1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -passes='loop(indvars,loop-deletion)' -verify-scev -S %s | FileCheck %s
4 ; Make sure indvarsimplify properly forgets the exit value %p.2.lcssa phi after
5 ; modifying it. Loop deletion is required to show the incorrect use of the cached
8 define void @test(i1 %c) {
11 ; CHECK-NEXT: br label [[HEADER_1:%.*]]
12 ; CHECK: header.1.loopexit:
13 ; CHECK-NEXT: br label [[HEADER_1_BACKEDGE:%.*]]
15 ; CHECK-NEXT: br label [[HEADER_2:%.*]]
17 ; CHECK-NEXT: br i1 [[C:%.*]], label [[LATCH_1:%.*]], label [[LATCH_2:%.*]]
19 ; CHECK-NEXT: br label [[HEADER_1_LOOPEXIT:%.*]]
21 ; CHECK-NEXT: br label [[HEADER_1_BACKEDGE]]
22 ; CHECK: header.1.backedge:
23 ; CHECK-NEXT: br label [[HEADER_1]]
29 %p.1 = phi i32 [ 0, %entry ], [ %p.2.lcssa, %latch.2 ], [ 0, %latch.1 ]
33 %p.2 = phi i32 [ %p.1, %header.1 ], [ %p.2.next, %latch.1 ]
34 br i1 %c, label %latch.1, label %latch.2
37 %p.2.next = add i32 %p.2, 1
38 br i1 false, label %header.2, label %header.1
41 %p.2.lcssa = phi i32 [ %p.2, %header.2 ]
45 define i8 @test_pr52023(i1 %c.1, i1 %c.2) {
46 ; CHECK-LABEL: @test_pr52023(
48 ; CHECK-NEXT: br label [[LOOP_1:%.*]]
50 ; CHECK-NEXT: [[INC79:%.*]] = phi i8 [ [[TMP0:%.*]], [[LOOP_1_LATCH:%.*]] ], [ 0, [[ENTRY:%.*]] ]
51 ; CHECK-NEXT: [[TMP1:%.*]] = add i8 [[INC79]], 1
52 ; CHECK-NEXT: br label [[LOOP_2:%.*]]
54 ; CHECK-NEXT: br i1 [[C_1:%.*]], label [[LOOP_2_LATCH:%.*]], label [[LOOP_1_LATCH]]
55 ; CHECK: loop.2.latch:
56 ; CHECK-NEXT: br label [[LOOP_1_LATCH]]
57 ; CHECK: loop.1.latch:
58 ; CHECK-NEXT: [[TMP0]] = phi i8 [ [[TMP1]], [[LOOP_2_LATCH]] ], [ undef, [[LOOP_2]] ]
59 ; CHECK-NEXT: br i1 [[C_2:%.*]], label [[EXIT:%.*]], label [[LOOP_1]]
61 ; CHECK-NEXT: [[INC_LCSSA_LCSSA:%.*]] = phi i8 [ [[TMP0]], [[LOOP_1_LATCH]] ]
62 ; CHECK-NEXT: ret i8 [[INC_LCSSA_LCSSA]]
68 %inc79 = phi i8 [ %inc.lcssa, %loop.1.latch ], [ 0, %entry ]
72 %inc6 = phi i8 [ %inc79, %loop.1 ], [ %inc, %loop.2.latch ]
73 %inc = add i8 %inc6, 1
74 br i1 %c.1, label %loop.2.latch , label %loop.1.latch
77 br i1 false, label %loop.2, label %loop.1.latch
80 %inc.lcssa = phi i8 [ %inc, %loop.2.latch ], [ undef, %loop.2 ]
81 br i1 %c.2, label %exit, label %loop.1
84 %inc.lcssa.lcssa = phi i8 [ %inc.lcssa, %loop.1.latch ]
85 ret i8 %inc.lcssa.lcssa
88 define i32 @test_pr58440(i1 %c.0) {
89 ; CHECK-LABEL: @test_pr58440(
91 ; CHECK-NEXT: [[TMP0:%.*]] = or i32 0, 1
92 ; CHECK-NEXT: br label [[LOOP_1_HEADER:%.*]]
93 ; CHECK: loop.1.header.loopexit:
94 ; CHECK-NEXT: br label [[LOOP_1_HEADER]]
95 ; CHECK: loop.1.header:
96 ; CHECK-NEXT: br label [[LOOP_2_HEADER:%.*]]
97 ; CHECK: loop.2.header:
98 ; CHECK-NEXT: br i1 [[C_0:%.*]], label [[LOOP_2_LATCH:%.*]], label [[LOOP_1_HEADER_LOOPEXIT:%.*]]
99 ; CHECK: loop.2.latch:
100 ; CHECK-NEXT: br i1 false, label [[EXIT:%.*]], label [[LOOP_2_HEADER]]
102 ; CHECK-NEXT: [[LCSSA:%.*]] = phi i32 [ [[TMP0]], [[LOOP_2_LATCH]] ]
103 ; CHECK-NEXT: ret i32 [[LCSSA]]
106 br label %loop.1.header
109 %p.1 = phi i32 [ 0, %entry ], [ %p.2, %loop.2.header ]
110 br label %loop.2.header
113 %p.2 = phi i32 [ %p.1, %loop.1.header ], [ %0, %loop.2.latch ]
114 br i1 %c.0, label %loop.2.latch, label %loop.1.header
118 br i1 false, label %exit, label %loop.2.header
121 %lcssa = phi i32 [ %0, %loop.2.latch ]
126 define i16 @test_pr58515_invalidate_loop_disposition(ptr %a) {
127 ; CHECK-LABEL: @test_pr58515_invalidate_loop_disposition(
129 ; CHECK-NEXT: [[SEL:%.*]] = select i1 true, i16 2, i16 0
130 ; CHECK-NEXT: br label [[LOOP:%.*]]
132 ; CHECK-NEXT: [[IV:%.*]] = phi i16 [ 1, [[ENTRY:%.*]] ], [ [[IV_NEXT:%.*]], [[LOOP]] ]
133 ; CHECK-NEXT: [[SUM:%.*]] = phi i16 [ 0, [[ENTRY]] ], [ [[SUM_NEXT:%.*]], [[LOOP]] ]
134 ; CHECK-NEXT: [[SUM_NEXT]] = add i16 [[SEL]], [[SUM]]
135 ; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i16 [[IV]], 1
136 ; CHECK-NEXT: [[C_2:%.*]] = icmp ult i16 [[IV]], 9
137 ; CHECK-NEXT: br i1 [[C_2]], label [[LOOP]], label [[EXIT:%.*]]
139 ; CHECK-NEXT: [[LCSSA:%.*]] = phi i16 [ [[SUM_NEXT]], [[LOOP]] ]
140 ; CHECK-NEXT: ret i16 0
146 %iv = phi i16 [ 1, %entry ], [ %iv.next, %loop ]
147 %sum = phi i16 [ 0, %entry ], [ %sum.next, %loop ]
148 %gep = getelementptr inbounds i16, ptr %a, i16 %iv
149 %c.1 = icmp ne ptr %a, %gep
150 %sel = select i1 %c.1, i16 2, i16 0
151 %sum.next = add i16 %sel, %sum
152 %iv.next = add nuw nsw i16 %iv, 1
153 %c.2 = icmp ult i16 %iv, 9
154 br i1 %c.2, label %loop, label %exit
157 %lcssa = phi i16 [ %sum.next, %loop ]
161 define i32 @pr58750(i16 %a, ptr %dst, i1 %c.0) {
162 ; CHECK-LABEL: @pr58750(
164 ; CHECK-NEXT: [[CMP186_NOT:%.*]] = icmp eq i16 [[A:%.*]], 0
165 ; CHECK-NEXT: call void @llvm.assume(i1 [[CMP186_NOT]])
166 ; CHECK-NEXT: br label [[OUTER_HEADER:%.*]]
167 ; CHECK: outer.header:
168 ; CHECK-NEXT: [[P_0:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[LCSSA:%.*]], [[OUTER_LATCH:%.*]] ]
169 ; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[P_0]], 0
170 ; CHECK-NEXT: br label [[INNER:%.*]]
172 ; CHECK-NEXT: store i16 0, ptr [[DST:%.*]], align 1
173 ; CHECK-NEXT: br i1 false, label [[INNER]], label [[OUTER_LATCH]]
174 ; CHECK: outer.latch:
175 ; CHECK-NEXT: [[LCSSA]] = phi i32 [ [[XOR]], [[INNER]] ]
176 ; CHECK-NEXT: br i1 [[C_0:%.*]], label [[OUTER_HEADER]], label [[EXIT:%.*]]
178 ; CHECK-NEXT: [[LCSSA_LCSSA:%.*]] = phi i32 [ [[LCSSA]], [[OUTER_LATCH]] ]
179 ; CHECK-NEXT: ret i32 [[LCSSA_LCSSA]]
182 %cmp186.not = icmp eq i16 %a, 0
183 call void @llvm.assume(i1 %cmp186.not)
184 br label %outer.header
187 %p.0 = phi i32 [ 0, %entry ], [ %lcssa, %outer.latch ]
191 %inner.iv = phi i16 [ 0, %outer.header ], [ %inner.iv.next, %inner ]
192 %p.1 = phi i32 [ %p.0, %outer.header ], [ %xor, %inner ]
193 store i16 %inner.iv, ptr %dst, align 1
194 %conv = sext i16 %inner.iv to i32
195 %xor = xor i32 %p.1, %conv
196 %inner.iv.next = add nuw i16 %inner.iv, 1
197 %c.1 = icmp ult i16 %inner.iv.next, %a
198 br i1 %c.1, label %inner, label %outer.latch
201 %lcssa = phi i32 [ %xor, %inner ]
202 br i1 %c.0, label %outer.header, label %exit
208 ; Function Attrs: inaccessiblememonly nocallback nofree nosync nounwind willreturn
209 declare void @llvm.assume(i1 noundef) #1