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: [[TMP0]] = 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: br i1 [[C_2:%.*]], label [[EXIT:%.*]], label [[LOOP_1]]
60 ; CHECK-NEXT: [[INC_LCSSA_LCSSA:%.*]] = phi i8 [ [[TMP0]], [[LOOP_1_LATCH]] ]
61 ; CHECK-NEXT: ret i8 [[INC_LCSSA_LCSSA]]
67 %inc79 = phi i8 [ %inc.lcssa, %loop.1.latch ], [ 0, %entry ]
71 %inc6 = phi i8 [ %inc79, %loop.1 ], [ %inc, %loop.2.latch ]
72 %inc = add i8 %inc6, 1
73 br i1 %c.1, label %loop.2.latch , label %loop.1.latch
76 br i1 false, label %loop.2, label %loop.1.latch
79 %inc.lcssa = phi i8 [ %inc, %loop.2.latch ], [ undef, %loop.2 ]
80 br i1 %c.2, label %exit, label %loop.1
83 %inc.lcssa.lcssa = phi i8 [ %inc.lcssa, %loop.1.latch ]
84 ret i8 %inc.lcssa.lcssa
87 define i32 @test_pr58440(i1 %c.0) {
88 ; CHECK-LABEL: @test_pr58440(
90 ; CHECK-NEXT: [[TMP0:%.*]] = or i32 0, 1
91 ; CHECK-NEXT: br label [[LOOP_1_HEADER:%.*]]
92 ; CHECK: loop.1.header.loopexit:
93 ; CHECK-NEXT: br label [[LOOP_1_HEADER]]
94 ; CHECK: loop.1.header:
95 ; CHECK-NEXT: br label [[LOOP_2_HEADER:%.*]]
96 ; CHECK: loop.2.header:
97 ; CHECK-NEXT: br i1 [[C_0:%.*]], label [[LOOP_2_LATCH:%.*]], label [[LOOP_1_HEADER_LOOPEXIT:%.*]]
98 ; CHECK: loop.2.latch:
99 ; CHECK-NEXT: br i1 false, label [[EXIT:%.*]], label [[LOOP_2_HEADER]]
101 ; CHECK-NEXT: [[LCSSA:%.*]] = phi i32 [ [[TMP0]], [[LOOP_2_LATCH]] ]
102 ; CHECK-NEXT: ret i32 [[LCSSA]]
105 br label %loop.1.header
108 %p.1 = phi i32 [ 0, %entry ], [ %p.2, %loop.2.header ]
109 br label %loop.2.header
112 %p.2 = phi i32 [ %p.1, %loop.1.header ], [ %0, %loop.2.latch ]
113 br i1 %c.0, label %loop.2.latch, label %loop.1.header
117 br i1 false, label %exit, label %loop.2.header
120 %lcssa = phi i32 [ %0, %loop.2.latch ]
125 define i16 @test_pr58515_invalidate_loop_disposition(ptr %a) {
126 ; CHECK-LABEL: @test_pr58515_invalidate_loop_disposition(
128 ; CHECK-NEXT: [[SEL:%.*]] = select i1 true, i16 2, i16 0
129 ; CHECK-NEXT: br label [[LOOP:%.*]]
131 ; CHECK-NEXT: [[IV:%.*]] = phi i16 [ 1, [[ENTRY:%.*]] ], [ [[IV_NEXT:%.*]], [[LOOP]] ]
132 ; CHECK-NEXT: [[SUM:%.*]] = phi i16 [ 0, [[ENTRY]] ], [ [[SUM_NEXT:%.*]], [[LOOP]] ]
133 ; CHECK-NEXT: [[SUM_NEXT]] = add i16 [[SEL]], [[SUM]]
134 ; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i16 [[IV]], 1
135 ; CHECK-NEXT: [[C_2:%.*]] = icmp ult i16 [[IV]], 9
136 ; CHECK-NEXT: br i1 [[C_2]], label [[LOOP]], label [[EXIT:%.*]]
138 ; CHECK-NEXT: [[LCSSA:%.*]] = phi i16 [ [[SUM_NEXT]], [[LOOP]] ]
139 ; CHECK-NEXT: ret i16 0
145 %iv = phi i16 [ 1, %entry ], [ %iv.next, %loop ]
146 %sum = phi i16 [ 0, %entry ], [ %sum.next, %loop ]
147 %gep = getelementptr inbounds i16, ptr %a, i16 %iv
148 %c.1 = icmp ne ptr %a, %gep
149 %sel = select i1 %c.1, i16 2, i16 0
150 %sum.next = add i16 %sel, %sum
151 %iv.next = add nuw nsw i16 %iv, 1
152 %c.2 = icmp ult i16 %iv, 9
153 br i1 %c.2, label %loop, label %exit
156 %lcssa = phi i16 [ %sum.next, %loop ]
160 define i32 @pr58750(i16 %a, ptr %dst, i1 %c.0) {
161 ; CHECK-LABEL: @pr58750(
163 ; CHECK-NEXT: [[CMP186_NOT:%.*]] = icmp eq i16 [[A:%.*]], 0
164 ; CHECK-NEXT: call void @llvm.assume(i1 [[CMP186_NOT]])
165 ; CHECK-NEXT: br label [[OUTER_HEADER:%.*]]
166 ; CHECK: outer.header:
167 ; CHECK-NEXT: [[P_0:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[LCSSA:%.*]], [[OUTER_LATCH:%.*]] ]
168 ; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[P_0]], 0
169 ; CHECK-NEXT: br label [[INNER:%.*]]
171 ; CHECK-NEXT: store i16 0, ptr [[DST:%.*]], align 1
172 ; CHECK-NEXT: br i1 false, label [[INNER]], label [[OUTER_LATCH]]
173 ; CHECK: outer.latch:
174 ; CHECK-NEXT: [[LCSSA]] = phi i32 [ [[XOR]], [[INNER]] ]
175 ; CHECK-NEXT: br i1 [[C_0:%.*]], label [[OUTER_HEADER]], label [[EXIT:%.*]]
177 ; CHECK-NEXT: [[LCSSA_LCSSA:%.*]] = phi i32 [ [[LCSSA]], [[OUTER_LATCH]] ]
178 ; CHECK-NEXT: ret i32 [[LCSSA_LCSSA]]
181 %cmp186.not = icmp eq i16 %a, 0
182 call void @llvm.assume(i1 %cmp186.not)
183 br label %outer.header
186 %p.0 = phi i32 [ 0, %entry ], [ %lcssa, %outer.latch ]
190 %inner.iv = phi i16 [ 0, %outer.header ], [ %inner.iv.next, %inner ]
191 %p.1 = phi i32 [ %p.0, %outer.header ], [ %xor, %inner ]
192 store i16 %inner.iv, ptr %dst, align 1
193 %conv = sext i16 %inner.iv to i32
194 %xor = xor i32 %p.1, %conv
195 %inner.iv.next = add nuw i16 %inner.iv, 1
196 %c.1 = icmp ult i16 %inner.iv.next, %a
197 br i1 %c.1, label %inner, label %outer.latch
200 %lcssa = phi i32 [ %xor, %inner ]
201 br i1 %c.0, label %outer.header, label %exit
207 ; Function Attrs: inaccessiblememonly nocallback nofree nosync nounwind willreturn
208 declare void @llvm.assume(i1 noundef) #1