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