1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -passes='loop(indvars,loop-deletion),verify<scalar-evolution>,print<scalar-evolution>' -S %s 2>&1| FileCheck %s
4 ; Make sure the SCEV for %invar is invalidated properly when the instruction is
5 ; moved by LoopDeletion.
8 define void @test_pr57837() {
9 ; CHECK-LABEL: @test_pr57837(
11 ; CHECK-NEXT: br label [[OUTER_HEADER:%.*]]
12 ; CHECK: outer.header:
13 ; CHECK-NEXT: br i1 true, label [[INNER_PH:%.*]], label [[OUTER_LATCH:%.*]]
15 ; CHECK-NEXT: [[INVAR:%.*]] = ashr i32 0, 3
16 ; CHECK-NEXT: br label [[INNER:%.*]]
18 ; CHECK-NEXT: [[P:%.*]] = phi i32 [ poison, [[INNER_PH]] ], [ [[INVAR]], [[INNER]] ]
19 ; CHECK-NEXT: [[INNER_IV:%.*]] = phi i32 [ 1, [[INNER_PH]] ], [ [[INNER_IV_NEXT:%.*]], [[INNER]] ]
20 ; CHECK-NEXT: [[ADD_1:%.*]] = add i32 [[P]], 30586
21 ; CHECK-NEXT: call void @use(i32 [[ADD_1]])
22 ; CHECK-NEXT: [[INNER_IV_NEXT]] = add nuw nsw i32 [[INNER_IV]], 1
23 ; CHECK-NEXT: [[INVAR_ADD:%.*]] = add i32 [[INVAR]], 407
24 ; CHECK-NEXT: [[INNER_CMP:%.*]] = icmp ult i32 [[INNER_IV_NEXT]], [[INVAR_ADD]]
25 ; CHECK-NEXT: br i1 [[INNER_CMP]], label [[INNER]], label [[INNER_EXIT:%.*]]
27 ; CHECK-NEXT: [[INVAR_LCSSA:%.*]] = phi i32 [ [[INVAR]], [[INNER]] ]
28 ; CHECK-NEXT: br label [[OUTER_LATCH]]
30 ; CHECK-NEXT: [[MERGE:%.*]] = phi i32 [ 0, [[OUTER_HEADER]] ], [ [[INVAR_LCSSA]], [[INNER_EXIT]] ]
31 ; CHECK-NEXT: call void @use(i32 [[MERGE]])
32 ; CHECK-NEXT: br label [[EXIT:%.*]]
34 ; CHECK-NEXT: ret void
37 br label %outer.header
39 outer.header: ; preds = %bb19, %bb
40 %outer.iv = phi i32 [ 0, %bb ], [ %tmp21, %outer.latch ]
41 %outer.cmp = icmp ult i32 %outer.iv, 400
42 br i1 %outer.cmp, label %inner.ph, label %outer.latch
48 %p = phi i32 [ poison, %inner.ph ], [ %invar, %inner ]
49 %inner.iv = phi i32 [ 1, %inner.ph ], [ %inner.iv.next , %inner ]
50 %add.1 = add i32 %p, 30586
51 call void @use(i32 %add.1)
52 %invar = ashr i32 0, 3
53 %inner.iv.next = add nuw nsw i32 %inner.iv, 1
54 %invar.add = add i32 %invar, 407
55 %inner.cmp = icmp slt i32 %inner.iv.next, %invar.add
56 br i1 %inner.cmp, label %inner, label %inner.exit
62 %merge = phi i32 [ 0, %outer.header ], [ %invar, %inner.exit ]
63 call void @use(i32 %merge)
64 %tmp21 = add i32 %outer.iv, 1
65 br i1 true, label %exit, label %outer.header
71 declare void @use(i32)
74 define i32 @scev_invalidation_after_deleting(ptr %src) {
75 ; CHECK-LABEL: @scev_invalidation_after_deleting(
77 ; CHECK-NEXT: br label [[OUTER_HEADER:%.*]]
78 ; CHECK: outer.header:
79 ; CHECK-NEXT: [[OUTER_IV:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[OUTER_IV_NEXT:%.*]], [[OUTER_LATCH:%.*]] ]
80 ; CHECK-NEXT: br label [[INNER_1:%.*]]
82 ; CHECK-NEXT: [[C_1:%.*]] = icmp eq i32 0, [[OUTER_IV]]
83 ; CHECK-NEXT: br i1 [[C_1]], label [[INNER_2_PREHEADER:%.*]], label [[INNER_1]]
84 ; CHECK: inner.2.preheader:
85 ; CHECK-NEXT: br label [[INNER_3_PH:%.*]]
87 ; CHECK-NEXT: br label [[INNER_3:%.*]]
89 ; CHECK-NEXT: [[L:%.*]] = load i32, ptr [[SRC:%.*]], align 4
90 ; CHECK-NEXT: br i1 false, label [[OUTER_LATCH]], label [[INNER_3]]
92 ; CHECK-NEXT: [[L_LCSSA:%.*]] = phi i32 [ [[L]], [[INNER_3]] ]
93 ; CHECK-NEXT: [[TRUNC:%.*]] = trunc i64 0 to i32
94 ; CHECK-NEXT: [[OUTER_IV_NEXT]] = add nsw i32 [[L_LCSSA]], [[TRUNC]]
95 ; CHECK-NEXT: br label [[OUTER_HEADER]]
98 br label %outer.header
101 %outer.iv = phi i32 [ 0, %entry ], [ %outer.iv.next, %outer.latch ]
105 %c.1 = icmp eq i32 0, %outer.iv
106 br i1 %c.1, label %inner.2, label %inner.1
109 %iv.2 = phi i64 [ 0, %inner.1 ], [ %iv.2.next, %inner.2 ]
110 %iv.2.next = add nuw i64 %iv.2, 1
111 br i1 true, label %inner.3.ph, label %inner.2
114 %trunc = trunc i64 %iv.2 to i32
118 %l = load i32, ptr %src, align 4
119 br i1 false, label %outer.latch, label %inner.3
122 %outer.iv.next = add nsw i32 %l, %trunc
123 br label %outer.header
126 define void @test_pr58314() {
127 ; CHECK-LABEL: @test_pr58314(
129 ; CHECK-NEXT: br label [[OUTER_HEADER:%.*]]
130 ; CHECK: outer.header:
131 ; CHECK-NEXT: [[C:%.*]] = icmp ne i16 0, 0
132 ; CHECK-NEXT: [[SEL:%.*]] = select i1 [[C]], i1 false, i1 true
133 ; CHECK-NEXT: br label [[INNER:%.*]]
135 ; CHECK-NEXT: br i1 true, label [[INNER]], label [[OUTER_LATCH:%.*]]
136 ; CHECK: outer.latch:
137 ; CHECK-NEXT: [[SEL_LCSSA:%.*]] = phi i1 [ [[SEL]], [[INNER]] ]
138 ; CHECK-NEXT: br i1 [[SEL_LCSSA]], label [[OUTER_HEADER]], label [[EXIT:%.*]]
140 ; CHECK-NEXT: ret void
143 br label %outer.header
149 %c = icmp ne i16 0, 0
150 %sel = select i1 %c, i1 false, i1 true
151 br i1 true, label %inner, label %outer.latch
154 br i1 %sel, label %outer.header, label %exit