1; RUN: opt -S -indvars < %s | FileCheck %s
2
3; Check that we replace signed comparisons between non-negative values with
4; unsigned comparisons if we can.
5
6target datalayout = "n8:16:32:64"
7
8define i32 @test_01(i32 %a, i32 %b, i32* %p) {
9
10; CHECK-LABEL: @test_01(
11; CHECK-NOT:   icmp slt
12; CHECK:       %cmp1 = icmp ult i32 %iv, 100
13; CHECK:       %cmp2 = icmp ult i32 %iv, 100
14; CHECK-NOT:   %cmp3
15; CHECK:       %exitcond = icmp ne i32 %iv.next, 1000
16
17entry:
18  br label %loop.entry
19
20loop.entry:
21  %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop.be ]
22  %cmp1 = icmp slt i32 %iv, 100
23  br i1 %cmp1, label %b1, label %b2
24
25b1:
26  store i32 %iv, i32* %p
27  br label %merge
28
29b2:
30  store i32 %a, i32* %p
31  br label %merge
32
33merge:
34  %cmp2 = icmp ult i32 %iv, 100
35  br i1 %cmp2, label %b3, label %b4
36
37b3:
38  store i32 %iv, i32* %p
39  br label %loop.be
40
41b4:
42  store i32 %b, i32* %p
43  br label %loop.be
44
45loop.be:
46  %iv.next = add i32 %iv, 1
47  %cmp3 = icmp slt i32 %iv.next, 1000
48  br i1 %cmp3, label %loop.entry, label %exit
49
50exit:
51  ret i32 %iv
52}
53
54define i32 @test_02(i32 %a, i32 %b, i32* %p) {
55
56; CHECK-LABEL: @test_02(
57; CHECK-NOT:   icmp sgt
58; CHECK:       %cmp1 = icmp ugt i32 100, %iv
59; CHECK:       %cmp2 = icmp ugt i32 100, %iv
60; CHECK-NOT:   %cmp3
61; CHECK:       %exitcond = icmp ne i32 %iv.next, 1000
62
63entry:
64  br label %loop.entry
65
66loop.entry:
67  %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop.be ]
68  %cmp1 = icmp sgt i32 100, %iv
69  br i1 %cmp1, label %b1, label %b2
70
71b1:
72  store i32 %iv, i32* %p
73  br label %merge
74
75b2:
76  store i32 %a, i32* %p
77  br label %merge
78
79merge:
80  %cmp2 = icmp ugt i32 100, %iv
81  br i1 %cmp2, label %b3, label %b4
82
83b3:
84  store i32 %iv, i32* %p
85  br label %loop.be
86
87b4:
88  store i32 %b, i32* %p
89  br label %loop.be
90
91loop.be:
92  %iv.next = add i32 %iv, 1
93  %cmp3 = icmp sgt i32 1000, %iv.next
94  br i1 %cmp3, label %loop.entry, label %exit
95
96exit:
97  ret i32 %iv
98}
99