• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; RUN: opt < %s -indvars -S | FileCheck %s
2
3define i32 @test.signed.add.0(i32* %array, i32 %length, i32 %init) {
4; CHECK-LABEL: @test.signed.add.0
5 entry:
6  %upper = icmp slt i32 %init, %length
7  br i1 %upper, label %loop, label %exit
8
9 loop:
10; CHECK-LABEL: loop
11  %civ = phi i32 [ %init, %entry ], [ %civ.inc, %latch ]
12  %civ.inc = add i32 %civ, 1
13; CHECK: %civ.inc = add nsw i32 %civ, 1
14  %cmp = icmp slt i32 %civ.inc, %length
15  br i1 %cmp, label %latch, label %break
16
17 latch:
18  store i32 0, i32* %array
19  %check = icmp slt i32 %civ.inc, %length
20  br i1 %check, label %loop, label %break
21
22 break:
23  ret i32 %civ.inc
24
25 exit:
26  ret i32 42
27}
28
29define i32 @test.signed.add.1(i32* %array, i32 %length, i32 %init) {
30; CHECK-LABEL: @test.signed.add.1
31 entry:
32  %upper = icmp sle i32 %init, %length
33  br i1 %upper, label %loop, label %exit
34
35 loop:
36; CHECK-LABEL: loop
37  %civ = phi i32 [ %init, %entry ], [ %civ.inc, %latch ]
38  %civ.inc = add i32 %civ, 1
39; CHECK: %civ.inc = add i32 %civ, 1
40  %cmp = icmp slt i32 %civ.inc, %length
41  br i1 %cmp, label %latch, label %break
42
43 latch:
44  store i32 0, i32* %array
45  %check = icmp slt i32 %civ.inc, %length
46  br i1 %check, label %loop, label %break
47
48 break:
49  ret i32 %civ.inc
50
51 exit:
52  ret i32 42
53}
54
55define i32 @test.unsigned.add.0(i32* %array, i32 %length, i32 %init) {
56; CHECK-LABEL: @test.unsigned.add.0
57 entry:
58  %upper = icmp ult i32 %init, %length
59  br i1 %upper, label %loop, label %exit
60
61 loop:
62; CHECK-LABEL: loop
63  %civ = phi i32 [ %init, %entry ], [ %civ.inc, %latch ]
64  %civ.inc = add i32 %civ, 1
65; CHECK: %civ.inc = add nuw i32 %civ, 1
66  %cmp = icmp slt i32 %civ.inc, %length
67  br i1 %cmp, label %latch, label %break
68
69 latch:
70  store i32 0, i32* %array
71  %check = icmp ult i32 %civ.inc, %length
72  br i1 %check, label %loop, label %break
73
74 break:
75  ret i32 %civ.inc
76
77 exit:
78  ret i32 42
79}
80
81define i32 @test.unsigned.add.1(i32* %array, i32 %length, i32 %init) {
82; CHECK-LABEL: @test.unsigned.add.1
83 entry:
84  %upper = icmp ule i32 %init, %length
85  br i1 %upper, label %loop, label %exit
86
87 loop:
88; CHECK-LABEL: loop
89  %civ = phi i32 [ %init, %entry ], [ %civ.inc, %latch ]
90  %civ.inc = add i32 %civ, 1
91; CHECK: %civ.inc = add i32 %civ, 1
92  %cmp = icmp slt i32 %civ.inc, %length
93  br i1 %cmp, label %latch, label %break
94
95 latch:
96  store i32 0, i32* %array
97  %check = icmp ult i32 %civ.inc, %length
98  br i1 %check, label %loop, label %break
99
100 break:
101  ret i32 %civ.inc
102
103 exit:
104  ret i32 42
105}
106
107define hidden void @test.shl.exact.equal() {
108; CHECK-LABEL: @test.shl.exact.equal
109entry:
110  br label %for.body
111
112for.body:
113; CHECK-LABEL: for.body
114  %k.021 = phi i32 [ 1, %entry ], [ %inc, %for.body ]
115  %shl = shl i32 1, %k.021
116  %shr1 = ashr i32 %shl, 1
117; CHECK: %shr1 = ashr exact i32 %shl, 1
118  %shr2 = lshr i32 %shl, 1
119; CHECK: %shr2 = lshr exact i32 %shl, 1
120  %inc = add nuw nsw i32 %k.021, 1
121  %exitcond = icmp eq i32 %inc, 9
122  br i1 %exitcond, label %for.end, label %for.body
123
124for.end:
125  ret void
126}
127
128define hidden void @test.shl.exact.greater() {
129; CHECK-LABEL: @test.shl.exact.greater
130entry:
131  br label %for.body
132
133for.body:
134; CHECK-LABEL: for.body
135  %k.021 = phi i32 [ 3, %entry ], [ %inc, %for.body ]
136  %shl = shl i32 1, %k.021
137  %shr1 = ashr i32 %shl, 2
138; CHECK: %shr1 = ashr exact i32 %shl, 2
139  %shr2 = lshr i32 %shl, 2
140; CHECK: %shr2 = lshr exact i32 %shl, 2
141  %inc = add nuw nsw i32 %k.021, 1
142  %exitcond = icmp eq i32 %inc, 9
143  br i1 %exitcond, label %for.end, label %for.body
144
145for.end:
146  ret void
147}
148
149define hidden void @test.shl.exact.unbound(i32 %arg) {
150; CHECK-LABEL: @test.shl.exact.unbound
151entry:
152  br label %for.body
153
154for.body:
155; CHECK-LABEL: for.body
156  %k.021 = phi i32 [ 2, %entry ], [ %inc, %for.body ]
157  %shl = shl i32 1, %k.021
158  %shr1 = ashr i32 %shl, 2
159; CHECK: %shr1 = ashr exact i32 %shl, 2
160  %shr2 = lshr i32 %shl, 2
161; CHECK: %shr2 = lshr exact i32 %shl, 2
162  %inc = add nuw nsw i32 %k.021, 1
163  %exitcond = icmp eq i32 %inc, %arg
164  br i1 %exitcond, label %for.end, label %for.body
165
166for.end:
167  ret void
168}
169
170define hidden void @test.shl.nonexact() {
171; CHECK-LABEL: @test.shl.nonexact
172entry:
173  br label %for.body
174
175for.body:
176; CHECK-LABEL: for.body
177  %k.021 = phi i32 [ 2, %entry ], [ %inc, %for.body ]
178  %shl = shl i32 1, %k.021
179  %shr1 = ashr i32 %shl, 3
180; CHECK: %shr1 = ashr i32 %shl, 3
181  %shr2 = lshr i32 %shl, 3
182; CHECK: %shr2 = lshr i32 %shl, 3
183  %inc = add nuw nsw i32 %k.021, 1
184  %exitcond = icmp eq i32 %inc, 9
185  br i1 %exitcond, label %for.end, label %for.body
186
187for.end:
188  ret void
189}
190
191!0 = !{i32 0, i32 2}
192!1 = !{i32 0, i32 42}
193