1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -S -passes=indvars < %s | FileCheck %s
4 ; We must NOT replace check against IV with check against invariant 0. It should fail.
5 define i32 @test_01() {
6 ; CHECK-LABEL: @test_01(
8 ; CHECK-NEXT: br label [[OUTER_LOOP:%.*]]
10 ; CHECK-NEXT: [[IV:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[IV_NEXT:%.*]], [[OUTER_LATCH:%.*]] ]
11 ; CHECK-NEXT: [[CHECK_1:%.*]] = icmp ult i32 [[IV]], 2
12 ; CHECK-NEXT: br label [[INNER_LOOP:%.*]]
14 ; CHECK-NEXT: [[STOREMERGE611_I:%.*]] = phi i64 [ 0, [[OUTER_LOOP]] ], [ [[ADD_I:%.*]], [[INNER_LATCH:%.*]] ]
15 ; CHECK-NEXT: br i1 [[CHECK_1]], label [[INNER_LATCH]], label [[EXIT:%.*]]
17 ; CHECK-NEXT: [[ADD_I]] = add nuw nsw i64 [[STOREMERGE611_I]], 1
18 ; CHECK-NEXT: [[CMP5_I:%.*]] = icmp ult i64 [[STOREMERGE611_I]], 11
19 ; CHECK-NEXT: br i1 [[CMP5_I]], label [[INNER_LOOP]], label [[OUTER_LATCH]]
21 ; CHECK-NEXT: [[IV_NEXT]] = add nsw i32 [[IV]], -1
22 ; CHECK-NEXT: br label [[OUTER_LOOP]]
24 ; CHECK-NEXT: [[IV_LCSSA:%.*]] = phi i32 [ [[IV]], [[INNER_LOOP]] ]
25 ; CHECK-NEXT: ret i32 [[IV_LCSSA]]
30 outer.loop: ; preds = %outer.latch, %entry
31 %iv = phi i32 [ 0, %entry ], [ %iv.next, %outer.latch ]
32 %check_1 = icmp ult i32 %iv, 2
35 inner.loop: ; preds = %inner.latch, %outer.loop
36 %storemerge611.i = phi i64 [ 0, %outer.loop ], [ %add.i, %inner.latch ]
37 br i1 %check_1, label %inner.latch, label %exit
39 inner.latch: ; preds = %inner.loop
40 %add.i = add i64 %storemerge611.i, 1
41 %cmp5.i = icmp ult i64 %storemerge611.i, 11
42 br i1 %cmp5.i, label %inner.loop, label %outer.latch
44 outer.latch: ; preds = %inner.latch
45 %iv.next = add i32 %iv, -1
48 exit: ; preds = %inner.loop
52 define i32 @test_02() {
53 ; CHECK-LABEL: @test_02(
55 ; CHECK-NEXT: br label [[OUTER_LOOP:%.*]]
57 ; CHECK-NEXT: [[IV:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[IV_NEXT:%.*]], [[OUTER_LATCH:%.*]] ]
58 ; CHECK-NEXT: [[CHECK_1:%.*]] = icmp ult i32 [[IV]], 2147483640
59 ; CHECK-NEXT: br label [[INNER_LOOP:%.*]]
61 ; CHECK-NEXT: [[STOREMERGE611_I:%.*]] = phi i64 [ 0, [[OUTER_LOOP]] ], [ [[ADD_I:%.*]], [[INNER_LATCH:%.*]] ]
62 ; CHECK-NEXT: br i1 [[CHECK_1]], label [[INNER_LATCH]], label [[EXIT:%.*]]
64 ; CHECK-NEXT: [[ADD_I]] = add nuw nsw i64 [[STOREMERGE611_I]], 1
65 ; CHECK-NEXT: [[CMP5_I:%.*]] = icmp ult i64 [[STOREMERGE611_I]], 11
66 ; CHECK-NEXT: br i1 [[CMP5_I]], label [[INNER_LOOP]], label [[OUTER_LATCH]]
68 ; CHECK-NEXT: [[IV_NEXT]] = add nuw i32 [[IV]], 10
69 ; CHECK-NEXT: br label [[OUTER_LOOP]]
71 ; CHECK-NEXT: [[IV_LCSSA:%.*]] = phi i32 [ [[IV]], [[INNER_LOOP]] ]
72 ; CHECK-NEXT: ret i32 [[IV_LCSSA]]
77 outer.loop: ; preds = %outer.latch, %entry
78 %iv = phi i32 [ 0, %entry ], [ %iv.next, %outer.latch ]
79 %check_1 = icmp ult i32 %iv, 2147483640
82 inner.loop: ; preds = %inner.latch, %outer.loop
83 %storemerge611.i = phi i64 [ 0, %outer.loop ], [ %add.i, %inner.latch ]
84 br i1 %check_1, label %inner.latch, label %exit
86 inner.latch: ; preds = %inner.loop
87 %add.i = add i64 %storemerge611.i, 1
88 %cmp5.i = icmp ult i64 %storemerge611.i, 11
89 br i1 %cmp5.i, label %inner.loop, label %outer.latch
91 outer.latch: ; preds = %inner.latch
92 %iv.next = add i32 %iv, 10
95 exit: ; preds = %inner.loop
99 define i32 @test_03() {
100 ; CHECK-LABEL: @test_03(
102 ; CHECK-NEXT: br label [[OUTER_LOOP:%.*]]
104 ; CHECK-NEXT: [[IV:%.*]] = phi i32 [ 2147483640, [[ENTRY:%.*]] ], [ [[IV_NEXT:%.*]], [[OUTER_LATCH:%.*]] ]
105 ; CHECK-NEXT: [[CHECK_1:%.*]] = icmp ult i32 [[IV]], 2147483647
106 ; CHECK-NEXT: br label [[INNER_LOOP:%.*]]
108 ; CHECK-NEXT: [[STOREMERGE611_I:%.*]] = phi i64 [ 0, [[OUTER_LOOP]] ], [ [[ADD_I:%.*]], [[INNER_LATCH:%.*]] ]
109 ; CHECK-NEXT: br i1 [[CHECK_1]], label [[INNER_LATCH]], label [[EXIT:%.*]]
110 ; CHECK: inner.latch:
111 ; CHECK-NEXT: [[ADD_I]] = add nuw nsw i64 [[STOREMERGE611_I]], 1
112 ; CHECK-NEXT: [[CMP5_I:%.*]] = icmp ult i64 [[STOREMERGE611_I]], 11
113 ; CHECK-NEXT: br i1 [[CMP5_I]], label [[INNER_LOOP]], label [[OUTER_LATCH]]
114 ; CHECK: outer.latch:
115 ; CHECK-NEXT: [[IV_NEXT]] = add nuw i32 [[IV]], 10
116 ; CHECK-NEXT: br label [[OUTER_LOOP]]
118 ; CHECK-NEXT: [[IV_LCSSA:%.*]] = phi i32 [ [[IV]], [[INNER_LOOP]] ]
119 ; CHECK-NEXT: ret i32 [[IV_LCSSA]]
124 outer.loop: ; preds = %outer.latch, %entry
125 %iv = phi i32 [ 2147483640, %entry ], [ %iv.next, %outer.latch ]
126 %check_1 = icmp ult i32 %iv, 2147483647
129 inner.loop: ; preds = %inner.latch, %outer.loop
130 %storemerge611.i = phi i64 [ 0, %outer.loop ], [ %add.i, %inner.latch ]
131 br i1 %check_1, label %inner.latch, label %exit
133 inner.latch: ; preds = %inner.loop
134 %add.i = add i64 %storemerge611.i, 1
135 %cmp5.i = icmp ult i64 %storemerge611.i, 11
136 br i1 %cmp5.i, label %inner.loop, label %outer.latch
138 outer.latch: ; preds = %inner.latch
139 %iv.next = add i32 %iv, 10
142 exit: ; preds = %inner.loop