1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=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(ptr %data) #0 {
8 ; CHECK-LABEL: @vnum_test1(
10 ; CHECK-NEXT: [[TMP:%.*]] = getelementptr inbounds i32, ptr [[DATA:%.*]], i64 3
11 ; CHECK-NEXT: [[TMP1:%.*]] = load i32, ptr [[TMP]], align 4
12 ; CHECK-NEXT: [[TMP2:%.*]] = getelementptr inbounds i32, ptr [[DATA]], i64 4
13 ; CHECK-NEXT: [[TMP3:%.*]] = load i32, ptr [[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, ptr [[DATA]], i64 2
22 ; CHECK-NEXT: [[TMP8:%.*]] = load i32, ptr [[TMP7]], align 4
23 ; CHECK-NEXT: [[TMP9:%.*]] = sext i32 [[TMP8]] to i64
24 ; CHECK-NEXT: [[TMP10:%.*]] = getelementptr inbounds i32, ptr [[DATA]], i64 [[TMP9]]
25 ; CHECK-NEXT: store i32 2, ptr [[TMP10]], align 4
26 ; CHECK-NEXT: store i32 0, ptr [[DATA]], align 4
27 ; CHECK-NEXT: [[TMP13:%.*]] = getelementptr inbounds i32, ptr [[DATA]], i64 1
28 ; CHECK-NEXT: [[TMP14:%.*]] = load i32, ptr [[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, ptr %data, i64 3
39 %tmp1 = load i32, ptr %tmp, align 4
40 %tmp2 = getelementptr inbounds i32, ptr %data, i64 4
41 %tmp3 = load i32, ptr %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, ptr %data, i64 2
53 %tmp8 = load i32, ptr %tmp7, align 4
54 %tmp9 = sext i32 %tmp8 to i64
55 %tmp10 = getelementptr inbounds i32, ptr %data, i64 %tmp9
56 store i32 2, ptr %tmp10, align 4
57 %tmp11 = sub nsw i32 %m.0, %n.0
58 store i32 %tmp11, ptr %data, align 4
59 %tmp13 = getelementptr inbounds i32, ptr %data, i64 1
60 %tmp14 = load i32, ptr %tmp13, align 4
61 %tmp15 = add nsw i32 %m.0, %tmp14
62 %tmp16 = add nsw i32 %n.0, %tmp14
66 %tmp18 = add nsw i32 %i.0, 1
73 ;; Function Attrs: nounwind ssp uwtable
74 ;; We should eliminate the sub, one of the phi nodes, prove the store of the sub
75 ;; and the load of data are equivalent, that the load always produces constant 0, and
76 ;; delete the load replacing it with constant 0.
77 define i32 @vnum_test2(ptr %data) #0 {
78 ; CHECK-LABEL: @vnum_test2(
80 ; CHECK-NEXT: [[TMP:%.*]] = getelementptr inbounds i32, ptr [[DATA:%.*]], i64 3
81 ; CHECK-NEXT: [[TMP1:%.*]] = load i32, ptr [[TMP]], align 4
82 ; CHECK-NEXT: [[TMP2:%.*]] = getelementptr inbounds i32, ptr [[DATA]], i64 4
83 ; CHECK-NEXT: [[TMP3:%.*]] = load i32, ptr [[TMP2]], align 4
84 ; CHECK-NEXT: br label [[BB4:%.*]]
86 ; CHECK-NEXT: [[M_0:%.*]] = phi i32 [ [[TMP3]], [[BB:%.*]] ], [ [[TMP15:%.*]], [[BB19:%.*]] ]
87 ; CHECK-NEXT: [[I_0:%.*]] = phi i32 [ 0, [[BB]] ], [ [[TMP20:%.*]], [[BB19]] ]
88 ; CHECK-NEXT: [[TMP5:%.*]] = icmp slt i32 [[I_0]], [[TMP1]]
89 ; CHECK-NEXT: br i1 [[TMP5]], label [[BB6:%.*]], label [[BB21:%.*]]
91 ; CHECK-NEXT: [[TMP7:%.*]] = getelementptr inbounds i32, ptr [[DATA]], i64 2
92 ; CHECK-NEXT: [[TMP8:%.*]] = load i32, ptr [[TMP7]], align 4
93 ; CHECK-NEXT: [[TMP9:%.*]] = sext i32 [[TMP8]] to i64
94 ; CHECK-NEXT: [[TMP10:%.*]] = getelementptr inbounds i32, ptr [[DATA]], i64 [[TMP9]]
95 ; CHECK-NEXT: store i32 2, ptr [[TMP10]], align 4
96 ; CHECK-NEXT: store i32 0, ptr [[DATA]], align 4
97 ; CHECK-NEXT: [[TMP13:%.*]] = getelementptr inbounds i32, ptr [[DATA]], i64 1
98 ; CHECK-NEXT: [[TMP14:%.*]] = load i32, ptr [[TMP13]], align 4
99 ; CHECK-NEXT: [[TMP15]] = add nsw i32 [[M_0]], [[TMP14]]
100 ; CHECK-NEXT: br label [[BB19]]
102 ; CHECK-NEXT: [[TMP20]] = add nsw i32 [[I_0]], 1
103 ; CHECK-NEXT: br label [[BB4]]
105 ; CHECK-NEXT: ret i32 0
108 %tmp = getelementptr inbounds i32, ptr %data, i64 3
109 %tmp1 = load i32, ptr %tmp, align 4
110 %tmp2 = getelementptr inbounds i32, ptr %data, i64 4
111 %tmp3 = load i32, ptr %tmp2, align 4
114 bb4: ; preds = %bb19, %bb
115 %m.0 = phi i32 [ %tmp3, %bb ], [ %tmp15, %bb19 ]
116 %n.0 = phi i32 [ %tmp3, %bb ], [ %tmp16, %bb19 ]
117 %i.0 = phi i32 [ 0, %bb ], [ %tmp20, %bb19 ]
118 %p.0 = phi i32 [ undef, %bb ], [ %tmp18, %bb19 ]
119 %tmp5 = icmp slt i32 %i.0, %tmp1
120 br i1 %tmp5, label %bb6, label %bb21
123 %tmp7 = getelementptr inbounds i32, ptr %data, i64 2
124 %tmp8 = load i32, ptr %tmp7, align 4
125 %tmp9 = sext i32 %tmp8 to i64
126 %tmp10 = getelementptr inbounds i32, ptr %data, i64 %tmp9
127 store i32 2, ptr %tmp10, align 4
128 %tmp11 = sub nsw i32 %m.0, %n.0
129 store i32 %tmp11, ptr %data, align 4
130 %tmp13 = getelementptr inbounds i32, ptr %data, i64 1
131 %tmp14 = load i32, ptr %tmp13, align 4
132 %tmp15 = add nsw i32 %m.0, %tmp14
133 %tmp16 = add nsw i32 %n.0, %tmp14
134 %tmp18 = load i32, ptr %data, align 4
138 %tmp20 = add nsw i32 %i.0, 1
146 ; Function Attrs: nounwind ssp uwtable
147 ;; Same as test 2, with a conditional store of m-n, so it has to also discover
148 ;; that data ends up with the same value no matter what branch is taken.
149 define i32 @vnum_test3(ptr %data) #0 {
150 ; CHECK-LABEL: @vnum_test3(
152 ; CHECK-NEXT: [[TMP:%.*]] = getelementptr inbounds i32, ptr [[DATA:%.*]], i64 3
153 ; CHECK-NEXT: [[TMP1:%.*]] = load i32, ptr [[TMP]], align 4
154 ; CHECK-NEXT: [[TMP2:%.*]] = getelementptr inbounds i32, ptr [[DATA]], i64 4
155 ; CHECK-NEXT: [[TMP3:%.*]] = load i32, ptr [[TMP2]], align 4
156 ; CHECK-NEXT: br label [[BB4:%.*]]
158 ; CHECK-NEXT: [[N_0:%.*]] = phi i32 [ [[TMP3]], [[BB:%.*]] ], [ [[TMP19:%.*]], [[BB21:%.*]] ]
159 ; CHECK-NEXT: [[I_0:%.*]] = phi i32 [ 0, [[BB]] ], [ [[TMP22:%.*]], [[BB21]] ]
160 ; CHECK-NEXT: [[TMP5:%.*]] = icmp slt i32 [[I_0]], [[TMP1]]
161 ; CHECK-NEXT: br i1 [[TMP5]], label [[BB6:%.*]], label [[BB23:%.*]]
163 ; CHECK-NEXT: [[TMP7:%.*]] = getelementptr inbounds i32, ptr [[DATA]], i64 2
164 ; CHECK-NEXT: [[TMP9:%.*]] = getelementptr inbounds i32, ptr [[DATA]], i64 5
165 ; CHECK-NEXT: store i32 0, ptr [[TMP9]], align 4
166 ; CHECK-NEXT: [[TMP10:%.*]] = icmp slt i32 [[I_0]], 30
167 ; CHECK-NEXT: br i1 [[TMP10]], label [[BB11:%.*]], label [[BB14:%.*]]
169 ; CHECK-NEXT: br label [[BB14]]
171 ; CHECK-NEXT: [[TMP17:%.*]] = getelementptr inbounds i32, ptr [[DATA]], i64 1
172 ; CHECK-NEXT: [[TMP18:%.*]] = load i32, ptr [[TMP17]], align 4
173 ; CHECK-NEXT: [[TMP19]] = add nsw i32 [[N_0]], [[TMP18]]
174 ; CHECK-NEXT: br label [[BB21]]
176 ; CHECK-NEXT: [[TMP22]] = add nsw i32 [[I_0]], 1
177 ; CHECK-NEXT: br label [[BB4]]
179 ; CHECK-NEXT: ret i32 0
182 %tmp = getelementptr inbounds i32, ptr %data, i64 3
183 %tmp1 = load i32, ptr %tmp, align 4
184 %tmp2 = getelementptr inbounds i32, ptr %data, i64 4
185 %tmp3 = load i32, ptr %tmp2, align 4
188 bb4: ; preds = %bb21, %bb
189 %n.0 = phi i32 [ %tmp3, %bb ], [ %tmp20, %bb21 ]
190 %m.0 = phi i32 [ %tmp3, %bb ], [ %tmp19, %bb21 ]
191 %p.0 = phi i32 [ 0, %bb ], [ %tmp16, %bb21 ]
192 %i.0 = phi i32 [ 0, %bb ], [ %tmp22, %bb21 ]
193 %tmp5 = icmp slt i32 %i.0, %tmp1
194 br i1 %tmp5, label %bb6, label %bb23
197 %tmp7 = getelementptr inbounds i32, ptr %data, i64 2
198 %tmp8 = load i32, ptr %tmp7, align 4
199 %tmp9 = getelementptr inbounds i32, ptr %data, i64 5
200 store i32 0, ptr %tmp9, align 4
201 %tmp10 = icmp slt i32 %i.0, 30
202 br i1 %tmp10, label %bb11, label %bb14
205 %tmp12 = sub nsw i32 %m.0, %n.0
206 %tmp13 = getelementptr inbounds i32, ptr %data, i64 5
207 store i32 %tmp12, ptr %tmp13, align 4
210 bb14: ; preds = %bb11, %bb6
211 %tmp15 = getelementptr inbounds i32, ptr %data, i64 5
212 %tmp16 = load i32, ptr %tmp15, align 4
213 %tmp17 = getelementptr inbounds i32, ptr %data, i64 1
214 %tmp18 = load i32, ptr %tmp17, align 4
215 %tmp19 = add nsw i32 %m.0, %tmp18
216 %tmp20 = add nsw i32 %n.0, %tmp18
219 bb21: ; preds = %bb14
220 %tmp22 = add nsw i32 %i.0, 1
227 ;; This is an irreducible test case that will cause a memoryphi node loop
228 ;; in the two blocks.
229 ;; It's equivalent to something like
231 ;; if (<....>) goto loopmiddle
236 ;; if (<....>) goto loopstart otherwise goto loopend
239 ;; add the results of the loads
242 ;; Both loads should equal 0, but it requires being
243 ;; completely optimistic about MemoryPhis, otherwise
244 ;; we will not be able to see through the cycle.
245 define i8 @irreducible_memoryphi(ptr noalias %arg, ptr noalias %arg2) {
246 ; CHECK-LABEL: @irreducible_memoryphi(
248 ; CHECK-NEXT: store i8 0, ptr [[ARG:%.*]]
249 ; CHECK-NEXT: br i1 undef, label [[BB2:%.*]], label [[BB1:%.*]]
251 ; CHECK-NEXT: br label [[BB2]]
253 ; CHECK-NEXT: br i1 undef, label [[BB1]], label [[BB3:%.*]]
255 ; CHECK-NEXT: ret i8 0
259 br i1 undef, label %bb2, label %bb1
261 bb1: ; preds = %bb2, %bb
264 bb2: ; preds = %bb1, %bb
265 %tmp2 = load i8, ptr %arg
267 br i1 undef, label %bb1, label %bb3
270 %tmp = load i8, ptr %arg
271 %tmp3 = add i8 %tmp, %tmp2
274 ;; This is an irreducible test case that will cause a phi node loop
277 ;; It should return 0, but it requires being
278 ;; completely optimistic about phis, otherwise
279 ;; we will not be able to see through the cycle.
280 define i32 @irreducible_phi(i32 %arg) {
281 ; CHECK-LABEL: @irreducible_phi(
283 ; CHECK-NEXT: br i1 undef, label [[BB2:%.*]], label [[BB1:%.*]]
285 ; CHECK-NEXT: br label [[BB2]]
287 ; CHECK-NEXT: br i1 undef, label [[BB1]], label [[BB3:%.*]]
289 ; CHECK-NEXT: ret i32 0
292 %tmp = add i32 0, %arg
293 br i1 undef, label %bb2, label %bb1
295 bb1: ; preds = %bb2, %bb
296 %phi1 = phi i32 [%tmp, %bb], [%phi2, %bb2]
299 bb2: ; preds = %bb1, %bb
300 %phi2 = phi i32 [%tmp, %bb], [%phi1, %bb1]
301 br i1 undef, label %bb1, label %bb3
304 ; This should be zero
305 %tmp3 = sub i32 %tmp, %phi2
308 attributes #0 = { nounwind ssp uwtable "less-precise-fpmad"="false" "frame-pointer"="all" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
310 !llvm.ident = !{!0, !0, !0}
312 !0 = !{!"Apple LLVM version 6.0 (clang-600.0.56) (based on LLVM 3.5svn)"}