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 ; memset -> i16 forwarding.
135 define signext i16 @memset_to_i16_local(i16* %A) nounwind ssp {
137 %conv = bitcast i16* %A to i8*
138 tail call void @llvm.memset.i64(i8* %conv, i8 1, i64 200, i32 1)
139 %arrayidx = getelementptr inbounds i16* %A, i64 42
140 %tmp2 = load i16* %arrayidx
142 ; CHECK: @memset_to_i16_local
147 ; memset -> float forwarding.
148 define float @memset_to_float_local(float* %A, i8 %Val) nounwind ssp {
150 %conv = bitcast float* %A to i8* ; <i8*> [#uses=1]
151 tail call void @llvm.memset.i64(i8* %conv, i8 %Val, i64 400, i32 1)
152 %arrayidx = getelementptr inbounds float* %A, i64 42 ; <float*> [#uses=1]
153 %tmp2 = load float* %arrayidx ; <float> [#uses=1]
155 ; CHECK: @memset_to_float_local
162 ; CHECK-NEXT: bitcast
163 ; CHECK-NEXT: ret float
166 ;; non-local memset -> i16 load forwarding.
167 define i16 @memset_to_i16_nonlocal0(i16* %P, i1 %cond) {
168 %P3 = bitcast i16* %P to i8*
169 br i1 %cond, label %T, label %F
171 tail call void @llvm.memset.i64(i8* %P3, i8 1, i64 400, i32 1)
175 tail call void @llvm.memset.i64(i8* %P3, i8 2, i64 400, i32 1)
179 %P2 = getelementptr i16* %P, i32 4
183 ; CHECK: @memset_to_i16_nonlocal0
185 ; CHECK-NEXT: %A = phi i16 [ 514, %F ], [ 257, %T ]
191 declare void @llvm.memset.i64(i8* nocapture, i8, i64, i32) nounwind
196 ;; non-local i32/float -> i8 load forwarding.
197 define i8 @coerce_mustalias_nonlocal0(i32* %P, i1 %cond) {
198 %P2 = bitcast i32* %P to float*
199 %P3 = bitcast i32* %P to i8*
200 br i1 %cond, label %T, label %F
202 store i32 42, i32* %P
206 store float 1.0, float* %P2
213 ; CHECK: @coerce_mustalias_nonlocal0
215 ; CHECK: %A = phi i8 [
221 ;; non-local i32/float -> i8 load forwarding. This also tests that the "P3"
222 ;; bitcast equivalence can be properly phi translated.
223 define i8 @coerce_mustalias_nonlocal1(i32* %P, i1 %cond) {
224 %P2 = bitcast i32* %P to float*
225 br i1 %cond, label %T, label %F
227 store i32 42, i32* %P
231 store float 1.0, float* %P2
235 %P3 = bitcast i32* %P to i8*
239 ;; FIXME: This is disabled because this caused a miscompile in the llvm-gcc
240 ;; bootstrap, see r82411
242 ; HECK: @coerce_mustalias_nonlocal1
244 ; HECK: %A = phi i8 [
250 ;; non-local i32 -> i8 partial redundancy load forwarding.
251 define i8 @coerce_mustalias_pre0(i32* %P, i1 %cond) {
252 %P3 = bitcast i32* %P to i8*
253 br i1 %cond, label %T, label %F
255 store i32 42, i32* %P
265 ; CHECK: @coerce_mustalias_pre0
267 ; CHECK: load i8* %P3
269 ; CHECK: %A = phi i8 [
274 ;;===----------------------------------------------------------------------===;;
275 ;; Store -> Load and Load -> Load forwarding where src and dst are different
276 ;; types, and the reload is an offset from the store pointer.
277 ;;===----------------------------------------------------------------------===;;
279 ;; i32 -> i8 forwarding.
281 define i8 @coerce_offset0(i32 %V, i32* %P) {
282 store i32 %V, i32* %P
284 %P2 = bitcast i32* %P to i8*
285 %P3 = getelementptr i8* %P2, i32 2
289 ; CHECK: @coerce_offset0
294 ;; non-local i32/float -> i8 load forwarding.
295 define i8 @coerce_offset_nonlocal0(i32* %P, i1 %cond) {
296 %P2 = bitcast i32* %P to float*
297 %P3 = bitcast i32* %P to i8*
298 %P4 = getelementptr i8* %P3, i32 2
299 br i1 %cond, label %T, label %F
301 store i32 42, i32* %P
305 store float 1.0, float* %P2
312 ; CHECK: @coerce_offset_nonlocal0
314 ; CHECK: %A = phi i8 [
320 ;; non-local i32 -> i8 partial redundancy load forwarding.
321 define i8 @coerce_offset_pre0(i32* %P, i1 %cond) {
322 %P3 = bitcast i32* %P to i8*
323 %P4 = getelementptr i8* %P3, i32 2
324 br i1 %cond, label %T, label %F
326 store i32 42, i32* %P
336 ; CHECK: @coerce_offset_pre0
338 ; CHECK: load i8* %P4
340 ; CHECK: %A = phi i8 [
345 define i32 @chained_load(i32** %p) {
348 br i1 true, label %block2, label %block3
363 ; CHECK: @chained_load
364 ; CHECK: %z = load i32** %p
366 ; CHECK: %d = load i32* %z
367 ; CHECK-NEXT: ret i32 %d
371 declare i1 @cond() readonly
372 declare i1 @cond2() readonly
374 define i32 @phi_trans2() {
376 %P = alloca i32, i32 400
380 %A = phi i32 [1, %entry], [2, %F]
381 %cond2 = call i1 @cond()
382 br i1 %cond2, label %T1, label %TY
385 %P2 = getelementptr i32* %P, i32 %A
387 %cond = call i1 @cond2()
388 br i1 %cond, label %TX, label %F
391 %P3 = getelementptr i32* %P, i32 2
392 store i32 17, i32* %P3
394 store i32 42, i32* %P2 ; Provides "P[A]".
398 ret i32 %x ;; SHOULD NOT BE COMPILED TO 'ret i32 42'.