1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -S -indvars < %s | FileCheck %s
4 ; Check that we replace signed comparisons between non-negative values with
5 ; unsigned comparisons if we can.
7 target datalayout = "n8:16:32:64"
9 define i32 @test_01(i32 %a, i32 %b, i32* %p) {
10 ; CHECK-LABEL: @test_01(
12 ; CHECK-NEXT: br label [[LOOP_ENTRY:%.*]]
14 ; CHECK-NEXT: [[IV:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[IV_NEXT:%.*]], [[LOOP_BE:%.*]] ]
15 ; CHECK-NEXT: [[CMP1:%.*]] = icmp ult i32 [[IV]], 100
16 ; CHECK-NEXT: br i1 [[CMP1]], label [[B1:%.*]], label [[B2:%.*]]
18 ; CHECK-NEXT: store i32 [[IV]], i32* [[P:%.*]], align 4
19 ; CHECK-NEXT: br label [[MERGE:%.*]]
21 ; CHECK-NEXT: store i32 [[A:%.*]], i32* [[P]], align 4
22 ; CHECK-NEXT: br label [[MERGE]]
24 ; CHECK-NEXT: [[CMP2:%.*]] = icmp ult i32 [[IV]], 100
25 ; CHECK-NEXT: br i1 [[CMP2]], label [[B3:%.*]], label [[B4:%.*]]
27 ; CHECK-NEXT: store i32 [[IV]], i32* [[P]], align 4
28 ; CHECK-NEXT: br label [[LOOP_BE]]
30 ; CHECK-NEXT: store i32 [[B:%.*]], i32* [[P]], align 4
31 ; CHECK-NEXT: br label [[LOOP_BE]]
33 ; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i32 [[IV]], 1
34 ; CHECK-NEXT: [[EXITCOND:%.*]] = icmp ne i32 [[IV_NEXT]], 1000
35 ; CHECK-NEXT: br i1 [[EXITCOND]], label [[LOOP_ENTRY]], label [[EXIT:%.*]]
37 ; CHECK-NEXT: ret i32 999
44 %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop.be ]
45 %cmp1 = icmp slt i32 %iv, 100
46 br i1 %cmp1, label %b1, label %b2
49 store i32 %iv, i32* %p
57 %cmp2 = icmp ult i32 %iv, 100
58 br i1 %cmp2, label %b3, label %b4
61 store i32 %iv, i32* %p
69 %iv.next = add i32 %iv, 1
70 %cmp3 = icmp slt i32 %iv.next, 1000
71 br i1 %cmp3, label %loop.entry, label %exit
77 define i32 @test_02(i32 %a, i32 %b, i32* %p) {
78 ; CHECK-LABEL: @test_02(
80 ; CHECK-NEXT: br label [[LOOP_ENTRY:%.*]]
82 ; CHECK-NEXT: [[IV:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[IV_NEXT:%.*]], [[LOOP_BE:%.*]] ]
83 ; CHECK-NEXT: [[CMP1:%.*]] = icmp ugt i32 100, [[IV]]
84 ; CHECK-NEXT: br i1 [[CMP1]], label [[B1:%.*]], label [[B2:%.*]]
86 ; CHECK-NEXT: store i32 [[IV]], i32* [[P:%.*]], align 4
87 ; CHECK-NEXT: br label [[MERGE:%.*]]
89 ; CHECK-NEXT: store i32 [[A:%.*]], i32* [[P]], align 4
90 ; CHECK-NEXT: br label [[MERGE]]
92 ; CHECK-NEXT: [[CMP2:%.*]] = icmp ugt i32 100, [[IV]]
93 ; CHECK-NEXT: br i1 [[CMP2]], label [[B3:%.*]], label [[B4:%.*]]
95 ; CHECK-NEXT: store i32 [[IV]], i32* [[P]], align 4
96 ; CHECK-NEXT: br label [[LOOP_BE]]
98 ; CHECK-NEXT: store i32 [[B:%.*]], i32* [[P]], align 4
99 ; CHECK-NEXT: br label [[LOOP_BE]]
101 ; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i32 [[IV]], 1
102 ; CHECK-NEXT: [[EXITCOND:%.*]] = icmp ne i32 [[IV_NEXT]], 1000
103 ; CHECK-NEXT: br i1 [[EXITCOND]], label [[LOOP_ENTRY]], label [[EXIT:%.*]]
105 ; CHECK-NEXT: ret i32 999
112 %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop.be ]
113 %cmp1 = icmp sgt i32 100, %iv
114 br i1 %cmp1, label %b1, label %b2
117 store i32 %iv, i32* %p
121 store i32 %a, i32* %p
125 %cmp2 = icmp ugt i32 100, %iv
126 br i1 %cmp2, label %b3, label %b4
129 store i32 %iv, i32* %p
133 store i32 %b, i32* %p
137 %iv.next = add i32 %iv, 1
138 %cmp3 = icmp sgt i32 1000, %iv.next
139 br i1 %cmp3, label %loop.entry, label %exit