1 ; RUN: opt < %s -gvn -S | FileCheck %s
3 ; 32-bit little endian target.
4 target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
7 define i32 @test0(i32 %V, i32* %P) {
17 ;;===----------------------------------------------------------------------===;;
19 ;;===----------------------------------------------------------------------===;;
22 define i8 @crash0({i32, i32} %A, {i32, i32}* %P) {
23 store {i32, i32} %A, {i32, i32}* %P
24 %X = bitcast {i32, i32}* %P to i8*
30 ;;===----------------------------------------------------------------------===;;
31 ;; Store -> Load and Load -> Load forwarding where src and dst are different
32 ;; types, but where the base pointer is a must alias.
33 ;;===----------------------------------------------------------------------===;;
35 ;; i32 -> f32 forwarding.
36 define float @coerce_mustalias1(i32 %V, i32* %P) {
39 %P2 = bitcast i32* %P to float*
43 ; CHECK: @coerce_mustalias1
48 ;; i32* -> float forwarding.
49 define float @coerce_mustalias2(i32* %V, i32** %P) {
50 store i32* %V, i32** %P
52 %P2 = bitcast i32** %P to float*
56 ; CHECK: @coerce_mustalias2
61 ;; float -> i32* forwarding.
62 define i32* @coerce_mustalias3(float %V, float* %P) {
63 store float %V, float* %P
65 %P2 = bitcast float* %P to i32**
69 ; CHECK: @coerce_mustalias3
74 ;; i32 -> f32 load forwarding.
75 define float @coerce_mustalias4(i32* %P, i1 %cond) {
78 %P2 = bitcast i32* %P to float*
80 br i1 %cond, label %T, label %F
85 %X = bitcast i32 %A to float
88 ; CHECK: @coerce_mustalias4
89 ; CHECK: %A = load i32* %P
95 ;; i32 -> i8 forwarding
96 define i8 @coerce_mustalias5(i32 %V, i32* %P) {
99 %P2 = bitcast i32* %P to i8*
103 ; CHECK: @coerce_mustalias5
108 ;; i64 -> float forwarding
109 define float @coerce_mustalias6(i64 %V, i64* %P) {
110 store i64 %V, i64* %P
112 %P2 = bitcast i64* %P to float*
116 ; CHECK: @coerce_mustalias6
121 ;; i64 -> i8* (32-bit) forwarding
122 define i8* @coerce_mustalias7(i64 %V, i64* %P) {
123 store i64 %V, i64* %P
125 %P2 = bitcast i64* %P to i8**
129 ; CHECK: @coerce_mustalias7
134 ;; non-local i32/float -> i8 load forwarding.
135 define i8 @coerce_mustalias_nonlocal0(i32* %P, i1 %cond) {
136 %P2 = bitcast i32* %P to float*
137 %P3 = bitcast i32* %P to i8*
138 br i1 %cond, label %T, label %F
140 store i32 42, i32* %P
144 store float 1.0, float* %P2
151 ; CHECK: @coerce_mustalias_nonlocal0
153 ; CHECK: %A = phi i8 [
158 ;; non-local i32/float -> i8 load forwarding. This also tests that the "P3"
159 ;; bitcast equivalence can be properly phi translated.
160 define i8 @coerce_mustalias_nonlocal1(i32* %P, i1 %cond) {
161 %P2 = bitcast i32* %P to float*
162 br i1 %cond, label %T, label %F
164 store i32 42, i32* %P
168 store float 1.0, float* %P2
172 %P3 = bitcast i32* %P to i8*
176 ;; FIXME: This is disabled because this caused a miscompile in the llvm-gcc
177 ;; bootstrap, see r82411
179 ; HECK: @coerce_mustalias_nonlocal1
181 ; HECK: %A = phi i8 [
187 ;; non-local i32 -> i8 partial redundancy load forwarding.
188 define i8 @coerce_mustalias_pre0(i32* %P, i1 %cond) {
189 %P3 = bitcast i32* %P to i8*
190 br i1 %cond, label %T, label %F
192 store i32 42, i32* %P
202 ; CHECK: @coerce_mustalias_pre0
204 ; CHECK: load i8* %P3
206 ; CHECK: %A = phi i8 [
211 ;;===----------------------------------------------------------------------===;;
212 ;; Store -> Load and Load -> Load forwarding where src and dst are different
213 ;; types, and the reload is an offset from the store pointer.
214 ;;===----------------------------------------------------------------------===;;
216 ;; i32 -> i8 forwarding.
218 define i8 @coerce_offset0(i32 %V, i32* %P) {
219 store i32 %V, i32* %P
221 %P2 = bitcast i32* %P to i8*
222 %P3 = getelementptr i8* %P2, i32 2
226 ; CHECK: @coerce_offset0
231 ;; non-local i32/float -> i8 load forwarding.
232 define i8 @coerce_offset_nonlocal0(i32* %P, i1 %cond) {
233 %P2 = bitcast i32* %P to float*
234 %P3 = bitcast i32* %P to i8*
235 %P4 = getelementptr i8* %P3, i32 2
236 br i1 %cond, label %T, label %F
238 store i32 42, i32* %P
242 store float 1.0, float* %P2
249 ; CHECK: @coerce_offset_nonlocal0
251 ; CHECK: %A = phi i8 [
257 ;; non-local i32 -> i8 partial redundancy load forwarding.
258 define i8 @coerce_offset_pre0(i32* %P, i1 %cond) {
259 %P3 = bitcast i32* %P to i8*
260 %P4 = getelementptr i8* %P3, i32 2
261 br i1 %cond, label %T, label %F
263 store i32 42, i32* %P
273 ; CHECK: @coerce_offset_pre0
275 ; CHECK: load i8* %P4
277 ; CHECK: %A = phi i8 [