increasing-or-decreasing-iv.ll
8.24 KB
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
; RUN: opt -analyze -enable-new-pm=0 -scalar-evolution < %s | FileCheck %s
; RUN: opt -disable-output "-passes=print<scalar-evolution>" < %s 2>&1 | FileCheck %s
define void @f0(i1 %c) {
; CHECK-LABEL: Classifying expressions for: @f0
entry:
%start = select i1 %c, i32 127, i32 0
%step = select i1 %c, i32 -1, i32 1
br label %loop
loop:
%loop.iv = phi i32 [ 0, %entry ], [ %loop.iv.inc, %loop ]
%iv = phi i32 [ %start, %entry ], [ %iv.next, %loop ]
; CHECK: %iv = phi i32 [ %start, %entry ], [ %iv.next, %loop ]
; CHECK-NEXT: --> {%start,+,%step}<%loop> U: [0,128) S: [0,128)
%iv.next = add i32 %iv, %step
%loop.iv.inc = add i32 %loop.iv, 1
%be.cond = icmp ne i32 %loop.iv.inc, 128
br i1 %be.cond, label %loop, label %leave
leave:
ret void
}
define void @f1(i1 %c) {
; CHECK-LABEL: Classifying expressions for: @f1
entry:
%start = select i1 %c, i32 120, i32 0
%step = select i1 %c, i32 -8, i32 8
br label %loop
loop:
%loop.iv = phi i32 [ 0, %entry ], [ %loop.iv.inc, %loop ]
%iv = phi i32 [ %start, %entry ], [ %iv.next, %loop ]
; CHECK: %iv.1 = add i32 %iv, 1
; CHECK-NEXT: --> {(1 + %start)<nuw><nsw>,+,%step}<%loop> U: [1,122) S: [1,122)
; CHECK: %iv.2 = add i32 %iv, 2
; CHECK-NEXT: --> {(2 + %start)<nuw><nsw>,+,%step}<%loop> U: [2,123) S: [2,123)
; CHECK: %iv.3 = add i32 %iv, 3
; CHECK-NEXT: --> {(3 + %start)<nuw><nsw>,+,%step}<%loop> U: [3,124) S: [3,124)
; CHECK: %iv.4 = add i32 %iv, 4
; CHECK-NEXT: --> {(4 + %start)<nuw><nsw>,+,%step}<%loop> U: [4,125) S: [4,125)
; CHECK: %iv.5 = add i32 %iv, 5
; CHECK-NEXT: --> {(5 + %start)<nuw><nsw>,+,%step}<%loop> U: [5,126) S: [5,126)
; CHECK: %iv.6 = add i32 %iv, 6
; CHECK-NEXT: --> {(6 + %start)<nuw><nsw>,+,%step}<%loop> U: [6,127) S: [6,127)
; CHECK: %iv.7 = add i32 %iv, 7
; CHECK-NEXT: --> {(7 + %start)<nuw><nsw>,+,%step}<%loop> U: [7,128) S: [7,128)
%iv.1 = add i32 %iv, 1
%iv.2 = add i32 %iv, 2
%iv.3 = add i32 %iv, 3
%iv.4 = add i32 %iv, 4
%iv.5 = add i32 %iv, 5
%iv.6 = add i32 %iv, 6
%iv.7 = add i32 %iv, 7
; CHECK: %iv.m1 = sub i32 %iv, 1
; CHECK-NEXT: --> {(-1 + %start)<nsw>,+,%step}<%loop> U: [-1,120) S: [-1,120)
; CHECK: %iv.m2 = sub i32 %iv, 2
; CHECK-NEXT: --> {(-2 + %start)<nsw>,+,%step}<%loop> U: [0,-1) S: [-2,119)
; CHECK: %iv.m3 = sub i32 %iv, 3
; CHECK-NEXT: --> {(-3 + %start)<nsw>,+,%step}<%loop> U: [-3,118) S: [-3,118)
; CHECK: %iv.m4 = sub i32 %iv, 4
; CHECK-NEXT: --> {(-4 + %start)<nsw>,+,%step}<%loop> U: [0,-3) S: [-4,117)
; CHECK: %iv.m5 = sub i32 %iv, 5
; CHECK-NEXT: --> {(-5 + %start)<nsw>,+,%step}<%loop> U: [-5,116) S: [-5,116)
; CHECK: %iv.m6 = sub i32 %iv, 6
; CHECK-NEXT: --> {(-6 + %start)<nsw>,+,%step}<%loop> U: [0,-1) S: [-6,115)
; CHECK: %iv.m7 = sub i32 %iv, 7
; CHECK-NEXT: --> {(-7 + %start)<nsw>,+,%step}<%loop> U: [-7,114) S: [-7,114)
%iv.m1 = sub i32 %iv, 1
%iv.m2 = sub i32 %iv, 2
%iv.m3 = sub i32 %iv, 3
%iv.m4 = sub i32 %iv, 4
%iv.m5 = sub i32 %iv, 5
%iv.m6 = sub i32 %iv, 6
%iv.m7 = sub i32 %iv, 7
%iv.next = add i32 %iv, %step
%loop.iv.inc = add i32 %loop.iv, 1
%be.cond = icmp sgt i32 %loop.iv, 14
br i1 %be.cond, label %leave, label %loop
leave:
ret void
}
define void @f2(i1 %c) {
; CHECK-LABEL: Classifying expressions for: @f2
entry:
%start = select i1 %c, i32 127, i32 0
%step = select i1 %c, i32 -1, i32 1
br label %loop
loop:
%loop.iv = phi i32 [ 0, %entry ], [ %loop.iv.inc, %loop ]
%iv = phi i32 [ %start, %entry ], [ %iv.next, %loop ]
%iv.sext = sext i32 %iv to i64
%iv.next = add i32 %iv, %step
; CHECK: %iv.sext = sext i32 %iv to i64
; CHECK-NEXT: --> {(sext i32 %start to i64),+,(sext i32 %step to i64)}<nsw><%loop> U: [0,128) S: [0,128)
%loop.iv.inc = add i32 %loop.iv, 1
%be.cond = icmp ne i32 %loop.iv.inc, 128
br i1 %be.cond, label %loop, label %leave
leave:
ret void
}
define void @f3(i1 %c) {
; CHECK-LABEL: Classifying expressions for: @f3
entry:
; NB! the i16 type (as opposed to i32), the choice of the constant 509
; and the trip count are all related and not arbitrary. We want an
; add recurrence that will look like it can unsign-overflow *unless*
; SCEV is able to see the correlation between the two selects feeding
; into the initial value and the step increment.
%start = select i1 %c, i16 1000, i16 0
%step = select i1 %c, i16 1, i16 509
br label %loop
loop:
%loop.iv = phi i16 [ 0, %entry ], [ %loop.iv.inc, %loop ]
%iv = phi i16 [ %start, %entry ], [ %iv.next, %loop ]
%iv.zext = zext i16 %iv to i64
; CHECK: %iv.zext = zext i16 %iv to i64
; CHECK-NEXT: --> {(zext i16 %start to i64),+,(zext i16 %step to i64)}<nuw><%loop> U: [0,64644) S: [0,64644)
%iv.next = add i16 %iv, %step
%loop.iv.inc = add i16 %loop.iv, 1
%be.cond = icmp ne i16 %loop.iv.inc, 128
br i1 %be.cond, label %loop, label %leave
leave:
ret void
}
define void @f4(i1 %c) {
; CHECK-LABEL: Classifying expressions for: @f4
; @f4() demonstrates a case where SCEV is not able to compute a
; precise range for %iv.trunc, though it should be able to, in theory.
; This is because SCEV looks into affine add recurrences only when the
; backedge taken count of the loop has the same bitwidth as the
; induction variable.
entry:
%start = select i1 %c, i32 127, i32 0
%step = select i1 %c, i32 -1, i32 1
br label %loop
loop:
%loop.iv = phi i32 [ 0, %entry ], [ %loop.iv.inc, %loop ]
%iv = phi i32 [ %start, %entry ], [ %iv.next, %loop ]
%iv.trunc = trunc i32 %iv to i16
; CHECK: %iv.trunc = trunc i32 %iv to i16
; CHECK-NEXT: --> {(trunc i32 %start to i16),+,(trunc i32 %step to i16)}<%loop> U: full-set S: full-set
%iv.next = add i32 %iv, %step
%loop.iv.inc = add i32 %loop.iv, 1
%be.cond = icmp ne i32 %loop.iv.inc, 128
br i1 %be.cond, label %loop, label %leave
leave:
ret void
}
define void @f5(i1 %c) {
; CHECK-LABEL: Classifying expressions for: @f5
entry:
%start = select i1 %c, i32 127, i32 0
%step = select i1 %c, i32 -1, i32 1
br label %loop
loop:
%loop.iv = phi i16 [ 0, %entry ], [ %loop.iv.inc, %loop ]
%iv = phi i32 [ %start, %entry ], [ %iv.next, %loop ]
%iv.trunc = trunc i32 %iv to i16
; CHECK: %iv.trunc = trunc i32 %iv to i16
; CHECK-NEXT: --> {(trunc i32 %start to i16),+,(trunc i32 %step to i16)}<%loop> U: [0,128) S: [0,128)
%iv.next = add i32 %iv, %step
%loop.iv.inc = add i16 %loop.iv, 1
%be.cond = icmp ne i16 %loop.iv.inc, 128
br i1 %be.cond, label %loop, label %leave
leave:
ret void
}
define void @f6(i1 %c) {
; CHECK-LABEL: Classifying expressions for: @f6
entry:
%start = select i1 %c, i32 127, i32 0
%step = select i1 %c, i32 -2, i32 0
br label %loop
loop:
%loop.iv = phi i16 [ 0, %entry ], [ %loop.iv.inc, %loop ]
%iv = phi i32 [ %start, %entry ], [ %iv.next, %loop ]
; CHECK: %iv = phi i32 [ %start, %entry ], [ %iv.next, %loop ]
; CHECK-NEXT: --> {%start,+,(1 + %step)<nuw><nsw>}<%loop> U: [0,128) S: [0,128)
%step.plus.one = add i32 %step, 1
%iv.next = add i32 %iv, %step.plus.one
%iv.sext = sext i32 %iv to i64
; CHECK: %iv.sext = sext i32 %iv to i64
; CHECK-NEXT: --> {(sext i32 %start to i64),+,(1 + (sext i32 %step to i64))<nuw><nsw>}<nsw><%loop> U: [0,128) S: [0,128)
%loop.iv.inc = add i16 %loop.iv, 1
%be.cond = icmp ne i16 %loop.iv.inc, 128
br i1 %be.cond, label %loop, label %leave
leave:
ret void
}
define void @f7(i1 %c) {
; CHECK-LABEL: Classifying expressions for: @f7
entry:
%start = select i1 %c, i32 127, i32 0
%step = select i1 %c, i32 -1, i32 1
br label %loop
loop:
%loop.iv = phi i16 [ 0, %entry ], [ %loop.iv.inc, %loop ]
%iv = phi i32 [ %start, %entry ], [ %iv.next, %loop ]
%iv.trunc = trunc i32 %iv to i16
; CHECK: %iv.trunc = trunc i32 %iv to i16
; CHECK-NEXT: --> {(trunc i32 %start to i16),+,(trunc i32 %step to i16)}<%loop> U: [0,128) S: [0,128)
%iv.next = add i32 %iv, %step
%iv.trunc.plus.one = add i16 %iv.trunc, 1
; CHECK: %iv.trunc.plus.one = add i16 %iv.trunc, 1
; CHECK-NEXT: --> {(1 + (trunc i32 %start to i16))<nuw><nsw>,+,(trunc i32 %step to i16)}<%loop> U: [1,129) S: [1,129)
%iv.trunc.plus.two = add i16 %iv.trunc, 2
; CHECK: %iv.trunc.plus.two = add i16 %iv.trunc, 2
; CHECK-NEXT: --> {(2 + (trunc i32 %start to i16))<nuw><nsw>,+,(trunc i32 %step to i16)}<%loop> U: [2,130) S: [2,130)
%loop.iv.inc = add i16 %loop.iv, 1
%be.cond = icmp ne i16 %loop.iv.inc, 128
br i1 %be.cond, label %loop, label %leave
leave:
ret void
}