1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -basicaa -newgvn -S | FileCheck %s
3 target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
5 ;; Function Attrs: nounwind ssp uwtable
6 ;; We should eliminate the sub, and one of the phi nodes
7 define void @vnum_test1(i32* %data) #0 {
8 ; CHECK-LABEL: @vnum_test1(
10 ; CHECK-NEXT: [[TMP:%.*]] = getelementptr inbounds i32, i32* [[DATA:%.*]], i64 3
11 ; CHECK-NEXT: [[TMP1:%.*]] = load i32, i32* [[TMP]], align 4
12 ; CHECK-NEXT: [[TMP2:%.*]] = getelementptr inbounds i32, i32* [[DATA]], i64 4
13 ; CHECK-NEXT: [[TMP3:%.*]] = load i32, i32* [[TMP2]], align 4
14 ; CHECK-NEXT: br label [[BB4:%.*]]
16 ; CHECK-NEXT: [[M_0:%.*]] = phi i32 [ [[TMP3]], [[BB:%.*]] ], [ [[TMP15:%.*]], [[BB17:%.*]] ]
17 ; CHECK-NEXT: [[I_0:%.*]] = phi i32 [ 0, [[BB]] ], [ [[TMP18:%.*]], [[BB17]] ]
18 ; CHECK-NEXT: [[TMP5:%.*]] = icmp slt i32 [[I_0]], [[TMP1]]
19 ; CHECK-NEXT: br i1 [[TMP5]], label [[BB6:%.*]], label [[BB19:%.*]]
21 ; CHECK-NEXT: [[TMP7:%.*]] = getelementptr inbounds i32, i32* [[DATA]], i64 2
22 ; CHECK-NEXT: [[TMP8:%.*]] = load i32, i32* [[TMP7]], align 4
23 ; CHECK-NEXT: [[TMP9:%.*]] = sext i32 [[TMP8]] to i64
24 ; CHECK-NEXT: [[TMP10:%.*]] = getelementptr inbounds i32, i32* [[DATA]], i64 [[TMP9]]
25 ; CHECK-NEXT: store i32 2, i32* [[TMP10]], align 4
26 ; CHECK-NEXT: store i32 0, i32* [[DATA]], align 4
27 ; CHECK-NEXT: [[TMP13:%.*]] = getelementptr inbounds i32, i32* [[DATA]], i64 1
28 ; CHECK-NEXT: [[TMP14:%.*]] = load i32, i32* [[TMP13]], align 4
29 ; CHECK-NEXT: [[TMP15]] = add nsw i32 [[M_0]], [[TMP14]]
30 ; CHECK-NEXT: br label [[BB17]]
32 ; CHECK-NEXT: [[TMP18]] = add nsw i32 [[I_0]], 1
33 ; CHECK-NEXT: br label [[BB4]]
35 ; CHECK-NEXT: ret void
38 %tmp = getelementptr inbounds i32, i32* %data, i64 3
39 %tmp1 = load i32, i32* %tmp, align 4
40 %tmp2 = getelementptr inbounds i32, i32* %data, i64 4
41 %tmp3 = load i32, i32* %tmp2, align 4
44 bb4: ; preds = %bb17, %bb
45 %m.0 = phi i32 [ %tmp3, %bb ], [ %tmp15, %bb17 ]
46 %i.0 = phi i32 [ 0, %bb ], [ %tmp18, %bb17 ]
47 %n.0 = phi i32 [ %tmp3, %bb ], [ %tmp16, %bb17 ]
48 %tmp5 = icmp slt i32 %i.0, %tmp1
49 br i1 %tmp5, label %bb6, label %bb19
52 %tmp7 = getelementptr inbounds i32, i32* %data, i64 2
53 %tmp8 = load i32, i32* %tmp7, align 4
54 %tmp9 = sext i32 %tmp8 to i64
55 %tmp10 = getelementptr inbounds i32, i32* %data, i64 %tmp9
56 store i32 2, i32* %tmp10, align 4
57 %tmp11 = sub nsw i32 %m.0, %n.0
58 %tmp12 = getelementptr inbounds i32, i32* %data, i64 0
59 store i32 %tmp11, i32* %tmp12, align 4
60 %tmp13 = getelementptr inbounds i32, i32* %data, i64 1
61 %tmp14 = load i32, i32* %tmp13, align 4
62 %tmp15 = add nsw i32 %m.0, %tmp14
63 %tmp16 = add nsw i32 %n.0, %tmp14
67 %tmp18 = add nsw i32 %i.0, 1
74 ;; Function Attrs: nounwind ssp uwtable
75 ;; We should eliminate the sub, one of the phi nodes, prove the store of the sub
76 ;; and the load of data are equivalent, that the load always produces constant 0, and
77 ;; delete the load replacing it with constant 0.
78 define i32 @vnum_test2(i32* %data) #0 {
79 ; CHECK-LABEL: @vnum_test2(
81 ; CHECK-NEXT: [[TMP:%.*]] = getelementptr inbounds i32, i32* [[DATA:%.*]], i64 3
82 ; CHECK-NEXT: [[TMP1:%.*]] = load i32, i32* [[TMP]], align 4
83 ; CHECK-NEXT: [[TMP2:%.*]] = getelementptr inbounds i32, i32* [[DATA]], i64 4
84 ; CHECK-NEXT: [[TMP3:%.*]] = load i32, i32* [[TMP2]], align 4
85 ; CHECK-NEXT: br label [[BB4:%.*]]
87 ; CHECK-NEXT: [[M_0:%.*]] = phi i32 [ [[TMP3]], [[BB:%.*]] ], [ [[TMP15:%.*]], [[BB19:%.*]] ]
88 ; CHECK-NEXT: [[I_0:%.*]] = phi i32 [ 0, [[BB]] ], [ [[TMP20:%.*]], [[BB19]] ]
89 ; CHECK-NEXT: [[TMP5:%.*]] = icmp slt i32 [[I_0]], [[TMP1]]
90 ; CHECK-NEXT: br i1 [[TMP5]], label [[BB6:%.*]], label [[BB21:%.*]]
92 ; CHECK-NEXT: [[TMP7:%.*]] = getelementptr inbounds i32, i32* [[DATA]], i64 2
93 ; CHECK-NEXT: [[TMP8:%.*]] = load i32, i32* [[TMP7]], align 4
94 ; CHECK-NEXT: [[TMP9:%.*]] = sext i32 [[TMP8]] to i64
95 ; CHECK-NEXT: [[TMP10:%.*]] = getelementptr inbounds i32, i32* [[DATA]], i64 [[TMP9]]
96 ; CHECK-NEXT: store i32 2, i32* [[TMP10]], align 4
97 ; CHECK-NEXT: store i32 0, i32* [[DATA]], align 4
98 ; CHECK-NEXT: [[TMP13:%.*]] = getelementptr inbounds i32, i32* [[DATA]], i64 1
99 ; CHECK-NEXT: [[TMP14:%.*]] = load i32, i32* [[TMP13]], align 4
100 ; CHECK-NEXT: [[TMP15]] = add nsw i32 [[M_0]], [[TMP14]]
101 ; CHECK-NEXT: br label [[BB19]]
103 ; CHECK-NEXT: [[TMP20]] = add nsw i32 [[I_0]], 1
104 ; CHECK-NEXT: br label [[BB4]]
106 ; CHECK-NEXT: ret i32 0
109 %tmp = getelementptr inbounds i32, i32* %data, i64 3
110 %tmp1 = load i32, i32* %tmp, align 4
111 %tmp2 = getelementptr inbounds i32, i32* %data, i64 4
112 %tmp3 = load i32, i32* %tmp2, align 4
115 bb4: ; preds = %bb19, %bb
116 %m.0 = phi i32 [ %tmp3, %bb ], [ %tmp15, %bb19 ]
117 %n.0 = phi i32 [ %tmp3, %bb ], [ %tmp16, %bb19 ]
118 %i.0 = phi i32 [ 0, %bb ], [ %tmp20, %bb19 ]
119 %p.0 = phi i32 [ undef, %bb ], [ %tmp18, %bb19 ]
120 %tmp5 = icmp slt i32 %i.0, %tmp1
121 br i1 %tmp5, label %bb6, label %bb21
124 %tmp7 = getelementptr inbounds i32, i32* %data, i64 2
125 %tmp8 = load i32, i32* %tmp7, align 4
126 %tmp9 = sext i32 %tmp8 to i64
127 %tmp10 = getelementptr inbounds i32, i32* %data, i64 %tmp9
128 store i32 2, i32* %tmp10, align 4
129 %tmp11 = sub nsw i32 %m.0, %n.0
130 %tmp12 = getelementptr inbounds i32, i32* %data, i64 0
131 store i32 %tmp11, i32* %tmp12, align 4
132 %tmp13 = getelementptr inbounds i32, i32* %data, i64 1
133 %tmp14 = load i32, i32* %tmp13, align 4
134 %tmp15 = add nsw i32 %m.0, %tmp14
135 %tmp16 = add nsw i32 %n.0, %tmp14
136 %tmp17 = getelementptr inbounds i32, i32* %data, i64 0
137 %tmp18 = load i32, i32* %tmp17, align 4
141 %tmp20 = add nsw i32 %i.0, 1
149 ; Function Attrs: nounwind ssp uwtable
150 ;; Same as test 2, with a conditional store of m-n, so it has to also discover
151 ;; that data ends up with the same value no matter what branch is taken.
152 define i32 @vnum_test3(i32* %data) #0 {
153 ; CHECK-LABEL: @vnum_test3(
155 ; CHECK-NEXT: [[TMP:%.*]] = getelementptr inbounds i32, i32* [[DATA:%.*]], i64 3
156 ; CHECK-NEXT: [[TMP1:%.*]] = load i32, i32* [[TMP]], align 4
157 ; CHECK-NEXT: [[TMP2:%.*]] = getelementptr inbounds i32, i32* [[DATA]], i64 4
158 ; CHECK-NEXT: [[TMP3:%.*]] = load i32, i32* [[TMP2]], align 4
159 ; CHECK-NEXT: br label [[BB4:%.*]]
161 ; CHECK-NEXT: [[N_0:%.*]] = phi i32 [ [[TMP3]], [[BB:%.*]] ], [ [[TMP19:%.*]], [[BB21:%.*]] ]
162 ; CHECK-NEXT: [[I_0:%.*]] = phi i32 [ 0, [[BB]] ], [ [[TMP22:%.*]], [[BB21]] ]
163 ; CHECK-NEXT: [[TMP5:%.*]] = icmp slt i32 [[I_0]], [[TMP1]]
164 ; CHECK-NEXT: br i1 [[TMP5]], label [[BB6:%.*]], label [[BB23:%.*]]
166 ; CHECK-NEXT: [[TMP7:%.*]] = getelementptr inbounds i32, i32* [[DATA]], i64 2
167 ; CHECK-NEXT: [[TMP9:%.*]] = getelementptr inbounds i32, i32* [[DATA]], i64 5
168 ; CHECK-NEXT: store i32 0, i32* [[TMP9]], align 4
169 ; CHECK-NEXT: [[TMP10:%.*]] = icmp slt i32 [[I_0]], 30
170 ; CHECK-NEXT: br i1 [[TMP10]], label [[BB11:%.*]], label [[BB14:%.*]]
172 ; CHECK-NEXT: br label [[BB14]]
174 ; CHECK-NEXT: [[TMP17:%.*]] = getelementptr inbounds i32, i32* [[DATA]], i64 1
175 ; CHECK-NEXT: [[TMP18:%.*]] = load i32, i32* [[TMP17]], align 4
176 ; CHECK-NEXT: [[TMP19]] = add nsw i32 [[N_0]], [[TMP18]]
177 ; CHECK-NEXT: br label [[BB21]]
179 ; CHECK-NEXT: [[TMP22]] = add nsw i32 [[I_0]], 1
180 ; CHECK-NEXT: br label [[BB4]]
182 ; CHECK-NEXT: ret i32 0
185 %tmp = getelementptr inbounds i32, i32* %data, i64 3
186 %tmp1 = load i32, i32* %tmp, align 4
187 %tmp2 = getelementptr inbounds i32, i32* %data, i64 4
188 %tmp3 = load i32, i32* %tmp2, align 4
191 bb4: ; preds = %bb21, %bb
192 %n.0 = phi i32 [ %tmp3, %bb ], [ %tmp20, %bb21 ]
193 %m.0 = phi i32 [ %tmp3, %bb ], [ %tmp19, %bb21 ]
194 %p.0 = phi i32 [ 0, %bb ], [ %tmp16, %bb21 ]
195 %i.0 = phi i32 [ 0, %bb ], [ %tmp22, %bb21 ]
196 %tmp5 = icmp slt i32 %i.0, %tmp1
197 br i1 %tmp5, label %bb6, label %bb23
200 %tmp7 = getelementptr inbounds i32, i32* %data, i64 2
201 %tmp8 = load i32, i32* %tmp7, align 4
202 %tmp9 = getelementptr inbounds i32, i32* %data, i64 5
203 store i32 0, i32* %tmp9, align 4
204 %tmp10 = icmp slt i32 %i.0, 30
205 br i1 %tmp10, label %bb11, label %bb14
208 %tmp12 = sub nsw i32 %m.0, %n.0
209 %tmp13 = getelementptr inbounds i32, i32* %data, i64 5
210 store i32 %tmp12, i32* %tmp13, align 4
213 bb14: ; preds = %bb11, %bb6
214 %tmp15 = getelementptr inbounds i32, i32* %data, i64 5
215 %tmp16 = load i32, i32* %tmp15, align 4
216 %tmp17 = getelementptr inbounds i32, i32* %data, i64 1
217 %tmp18 = load i32, i32* %tmp17, align 4
218 %tmp19 = add nsw i32 %m.0, %tmp18
219 %tmp20 = add nsw i32 %n.0, %tmp18
222 bb21: ; preds = %bb14
223 %tmp22 = add nsw i32 %i.0, 1
230 ;; This is an irreducible test case that will cause a memoryphi node loop
231 ;; in the two blocks.
232 ;; It's equivalent to something like
234 ;; if (<....>) goto loopmiddle
239 ;; if (<....>) goto loopstart otherwise goto loopend
242 ;; add the results of the loads
245 ;; Both loads should equal 0, but it requires being
246 ;; completely optimistic about MemoryPhis, otherwise
247 ;; we will not be able to see through the cycle.
248 define i8 @irreducible_memoryphi(i8* noalias %arg, i8* noalias %arg2) {
249 ; CHECK-LABEL: @irreducible_memoryphi(
251 ; CHECK-NEXT: store i8 0, i8* [[ARG:%.*]]
252 ; CHECK-NEXT: br i1 undef, label [[BB2:%.*]], label [[BB1:%.*]]
254 ; CHECK-NEXT: br label [[BB2]]
256 ; CHECK-NEXT: br i1 undef, label [[BB1]], label [[BB3:%.*]]
258 ; CHECK-NEXT: ret i8 0
262 br i1 undef, label %bb2, label %bb1
264 bb1: ; preds = %bb2, %bb
267 bb2: ; preds = %bb1, %bb
268 %tmp2 = load i8, i8* %arg
270 br i1 undef, label %bb1, label %bb3
273 %tmp = load i8, i8* %arg
274 %tmp3 = add i8 %tmp, %tmp2
277 ;; This is an irreducible test case that will cause a phi node loop
280 ;; It should return 0, but it requires being
281 ;; completely optimistic about phis, otherwise
282 ;; we will not be able to see through the cycle.
283 define i32 @irreducible_phi(i32 %arg) {
284 ; CHECK-LABEL: @irreducible_phi(
286 ; CHECK-NEXT: br i1 undef, label [[BB2:%.*]], label [[BB1:%.*]]
288 ; CHECK-NEXT: br label [[BB2]]
290 ; CHECK-NEXT: br i1 undef, label [[BB1]], label [[BB3:%.*]]
292 ; CHECK-NEXT: ret i32 0
295 %tmp = add i32 0, %arg
296 br i1 undef, label %bb2, label %bb1
298 bb1: ; preds = %bb2, %bb
299 %phi1 = phi i32 [%tmp, %bb], [%phi2, %bb2]
302 bb2: ; preds = %bb1, %bb
303 %phi2 = phi i32 [%tmp, %bb], [%phi1, %bb1]
304 br i1 undef, label %bb1, label %bb3
307 ; This should be zero
308 %tmp3 = sub i32 %tmp, %phi2
311 attributes #0 = { nounwind ssp uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
313 !llvm.ident = !{!0, !0, !0}
315 !0 = !{!"Apple LLVM version 6.0 (clang-600.0.56) (based on LLVM 3.5svn)"}