overflow-intrinsics.ll
11.2 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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
; RUN: opt -analyze -scalar-evolution < %s | FileCheck %s
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
define void @f_sadd_0(i8* %a) {
; CHECK-LABEL: Classifying expressions for: @f_sadd_0
entry:
br label %for.body
for.cond.cleanup: ; preds = %cont
ret void
for.body: ; preds = %entry, %cont
; CHECK: %i.04 = phi i32 [ 0, %entry ], [ %tmp2, %cont ]
; CHECK-NEXT: --> {0,+,1}<nuw><nsw><%for.body> U: [0,16) S: [0,16)
%i.04 = phi i32 [ 0, %entry ], [ %tmp2, %cont ]
%idxprom = sext i32 %i.04 to i64
%arrayidx = getelementptr inbounds i8, i8* %a, i64 %idxprom
store i8 0, i8* %arrayidx, align 1
%tmp0 = tail call { i32, i1 } @llvm.sadd.with.overflow.i32(i32 %i.04, i32 1)
%tmp1 = extractvalue { i32, i1 } %tmp0, 1
br i1 %tmp1, label %trap, label %cont, !nosanitize !{}
trap: ; preds = %for.body
tail call void @llvm.trap() #2, !nosanitize !{}
unreachable, !nosanitize !{}
cont: ; preds = %for.body
%tmp2 = extractvalue { i32, i1 } %tmp0, 0
%cmp = icmp slt i32 %tmp2, 16
br i1 %cmp, label %for.body, label %for.cond.cleanup
; CHECK: Loop %for.body: max backedge-taken count is 15
}
define void @f_sadd_1(i8* %a) {
; CHECK-LABEL: Classifying expressions for: @f_sadd_1
entry:
br label %for.body
for.cond.cleanup: ; preds = %cont
ret void
for.body: ; preds = %entry, %cont
; CHECK: %i.04 = phi i32 [ 0, %entry ], [ %tmp2, %cont ]
; CHECK-NEXT: --> {0,+,1}<%for.body> U: [0,16) S: [0,16)
; SCEV can prove <nsw> for the above induction variable; but it does
; not bother so before it sees the sext below since it is not a 100%
; obvious.
%i.04 = phi i32 [ 0, %entry ], [ %tmp2, %cont ]
%idxprom = sext i32 %i.04 to i64
%arrayidx = getelementptr inbounds i8, i8* %a, i64 %idxprom
store i8 0, i8* %arrayidx, align 1
%tmp0 = tail call { i32, i1 } @llvm.sadd.with.overflow.i32(i32 %i.04, i32 1)
%tmp1 = extractvalue { i32, i1 } %tmp0, 1
br i1 %tmp1, label %trap, label %cont, !nosanitize !{}
trap: ; preds = %for.body
br label %cont
cont: ; preds = %for.body
%tmp2 = extractvalue { i32, i1 } %tmp0, 0
%cmp = icmp slt i32 %tmp2, 16
br i1 %cmp, label %for.body, label %for.cond.cleanup
; CHECK: Loop %for.body: max backedge-taken count is 15
}
define void @f_sadd_2(i8* %a, i1* %c) {
; CHECK-LABEL: Classifying expressions for: @f_sadd_2
entry:
br label %for.body
for.cond.cleanup: ; preds = %cont
ret void
for.body: ; preds = %entry, %cont
; CHECK: %i.04 = phi i32 [ 0, %entry ], [ %tmp2, %cont ]
; CHECK-NEXT: --> {0,+,1}<%for.body>
%i.04 = phi i32 [ 0, %entry ], [ %tmp2, %cont ]
%idxprom = sext i32 %i.04 to i64
%arrayidx = getelementptr inbounds i8, i8* %a, i64 %idxprom
store i8 0, i8* %arrayidx, align 1
%tmp0 = tail call { i32, i1 } @llvm.sadd.with.overflow.i32(i32 %i.04, i32 1)
%tmp1 = extractvalue { i32, i1 } %tmp0, 1
br i1 %tmp1, label %trap, label %cont, !nosanitize !{}
trap: ; preds = %for.body
br label %cont
cont: ; preds = %for.body
%tmp2 = extractvalue { i32, i1 } %tmp0, 0
%cond = load volatile i1, i1* %c
br i1 %cond, label %for.body, label %for.cond.cleanup
}
define void @f_sadd_3(i8* %a, i1* %c) {
; CHECK-LABEL: Classifying expressions for: @f_sadd_3
entry:
br label %for.body
for.cond.cleanup: ; preds = %cont
ret void
for.body: ; preds = %entry, %cont
; CHECK: %i.04 = phi i32 [ 0, %entry ], [ %tmp2, %for.body ]
; CHECK-NEXT: --> {0,+,1}<nuw><nsw><%for.body>
%i.04 = phi i32 [ 0, %entry ], [ %tmp2, %for.body ]
%idxprom = sext i32 %i.04 to i64
%arrayidx = getelementptr inbounds i8, i8* %a, i64 %idxprom
store i8 0, i8* %arrayidx, align 1
%tmp0 = tail call { i32, i1 } @llvm.sadd.with.overflow.i32(i32 %i.04, i32 1)
%tmp1 = extractvalue { i32, i1 } %tmp0, 1
%tmp2 = extractvalue { i32, i1 } %tmp0, 0
br i1 %tmp1, label %trap, label %for.body, !nosanitize !{}
trap: ; preds = %for.body
tail call void @llvm.trap() #2, !nosanitize !{}
unreachable, !nosanitize !{}
}
define void @f_sadd_4(i8* %a, i1* %c) {
; CHECK-LABEL: Classifying expressions for: @f_sadd_4
entry:
br label %for.body
for.cond.cleanup: ; preds = %cont
ret void
for.body: ; preds = %entry, %cont
; CHECK: %i.04 = phi i32 [ 0, %entry ], [ %tmp2, %merge ]
; CHECK-NEXT: --> {0,+,1}<nuw><nsw><%for.body>
%i.04 = phi i32 [ 0, %entry ], [ %tmp2, %merge ]
%idxprom = sext i32 %i.04 to i64
%arrayidx = getelementptr inbounds i8, i8* %a, i64 %idxprom
store i8 0, i8* %arrayidx, align 1
%tmp0 = tail call { i32, i1 } @llvm.sadd.with.overflow.i32(i32 %i.04, i32 1)
%tmp1 = extractvalue { i32, i1 } %tmp0, 1
%tmp2 = extractvalue { i32, i1 } %tmp0, 0
br i1 %tmp1, label %notrap, label %merge
notrap:
br label %merge
merge:
%tmp3 = extractvalue { i32, i1 } %tmp0, 1
br i1 %tmp3, label %trap, label %for.body, !nosanitize !{}
trap: ; preds = %for.body
tail call void @llvm.trap() #2, !nosanitize !{}
unreachable, !nosanitize !{}
}
define void @f_sadd_may_overflow(i8* %a, i1* %c) {
; CHECK-LABEL: Classifying expressions for: @f_sadd_may_overflow
entry:
br label %for.body
for.cond.cleanup: ; preds = %cont
ret void
for.body: ; preds = %entry, %cont
; CHECK: %i.04 = phi i32 [ 0, %entry ], [ %tmp1, %cont ]
; CHECK-NEXT: --> {0,+,1}<%for.body> U: full-set S: full-set
%i.04 = phi i32 [ 0, %entry ], [ %tmp1, %cont ]
%idxprom = sext i32 %i.04 to i64
%arrayidx = getelementptr inbounds i8, i8* %a, i64 %idxprom
store i8 0, i8* %arrayidx, align 1
%tmp0 = tail call { i32, i1 } @llvm.sadd.with.overflow.i32(i32 %i.04, i32 1)
%cond1 = load volatile i1, i1* %c
br i1 %cond1, label %trap, label %cont, !nosanitize !{}
trap: ; preds = %for.body
tail call void @llvm.trap() #2, !nosanitize !{}
unreachable, !nosanitize !{}
cont: ; preds = %for.body
%tmp1 = extractvalue { i32, i1 } %tmp0, 0
%cond = load volatile i1, i1* %c
br i1 %cond, label %for.body, label %for.cond.cleanup
}
define void @f_uadd(i8* %a) {
; CHECK-LABEL: Classifying expressions for: @f_uadd
entry:
br label %for.body
for.cond.cleanup: ; preds = %cont
ret void
for.body: ; preds = %entry, %cont
; CHECK: %i.04 = phi i32 [ 0, %entry ], [ %tmp2, %cont ]
; CHECK-NEXT: --> {0,+,1}<nuw><%for.body> U: [0,16) S: [0,16)
%i.04 = phi i32 [ 0, %entry ], [ %tmp2, %cont ]
%idxprom = sext i32 %i.04 to i64
%arrayidx = getelementptr inbounds i8, i8* %a, i64 %idxprom
store i8 0, i8* %arrayidx, align 1
%tmp0 = tail call { i32, i1 } @llvm.uadd.with.overflow.i32(i32 %i.04, i32 1)
%tmp1 = extractvalue { i32, i1 } %tmp0, 1
br i1 %tmp1, label %trap, label %cont, !nosanitize !{}
trap: ; preds = %for.body
tail call void @llvm.trap(), !nosanitize !{}
unreachable, !nosanitize !{}
cont: ; preds = %for.body
%tmp2 = extractvalue { i32, i1 } %tmp0, 0
%cmp = icmp slt i32 %tmp2, 16
br i1 %cmp, label %for.body, label %for.cond.cleanup
; CHECK: Loop %for.body: max backedge-taken count is 15
}
define void @f_ssub(i8* nocapture %a) {
; CHECK-LABEL: Classifying expressions for: @f_ssub
entry:
br label %for.body
for.cond.cleanup: ; preds = %cont
ret void
for.body: ; preds = %entry, %cont
; CHECK: %i.04 = phi i32 [ 15, %entry ], [ %tmp2, %cont ]
; CHECK-NEXT: --> {15,+,-1}<%for.body> U: [0,16) S: [0,16)
%i.04 = phi i32 [ 15, %entry ], [ %tmp2, %cont ]
%idxprom = sext i32 %i.04 to i64
%arrayidx = getelementptr inbounds i8, i8* %a, i64 %idxprom
store i8 0, i8* %arrayidx, align 1
%tmp0 = tail call { i32, i1 } @llvm.ssub.with.overflow.i32(i32 %i.04, i32 1)
%tmp1 = extractvalue { i32, i1 } %tmp0, 1
br i1 %tmp1, label %trap, label %cont, !nosanitize !{}
trap: ; preds = %for.body
tail call void @llvm.trap(), !nosanitize !{}
unreachable, !nosanitize !{}
cont: ; preds = %for.body
%tmp2 = extractvalue { i32, i1 } %tmp0, 0
%cmp = icmp sgt i32 %tmp2, -1
br i1 %cmp, label %for.body, label %for.cond.cleanup
; CHECK: Loop %for.body: max backedge-taken count is 15
}
define void @f_usub(i8* nocapture %a) {
; CHECK-LABEL: Classifying expressions for: @f_usub
entry:
br label %for.body
for.cond.cleanup: ; preds = %cont
ret void
for.body: ; preds = %entry, %cont
; CHECK: %i.04 = phi i32 [ 15, %entry ], [ %tmp2, %cont ]
; CHECK-NEXT: --> {15,+,-1}<%for.body> U: [0,16) S: [0,16)
%i.04 = phi i32 [ 15, %entry ], [ %tmp2, %cont ]
%idxprom = sext i32 %i.04 to i64
%arrayidx = getelementptr inbounds i8, i8* %a, i64 %idxprom
store i8 0, i8* %arrayidx, align 1
%tmp0 = tail call { i32, i1 } @llvm.usub.with.overflow.i32(i32 %i.04, i32 1)
%tmp1 = extractvalue { i32, i1 } %tmp0, 1
br i1 %tmp1, label %trap, label %cont, !nosanitize !{}
trap: ; preds = %for.body
tail call void @llvm.trap(), !nosanitize !{}
unreachable, !nosanitize !{}
cont: ; preds = %for.body
%tmp2 = extractvalue { i32, i1 } %tmp0, 0
%cmp = icmp sgt i32 %tmp2, -1
br i1 %cmp, label %for.body, label %for.cond.cleanup
; CHECK: Loop %for.body: max backedge-taken count is 15
}
define i32 @f_smul(i32 %val_a, i32 %val_b) {
; CHECK-LABEL: Classifying expressions for: @f_smul
%agg = tail call { i32, i1 } @llvm.smul.with.overflow.i32(i32 %val_a, i32 %val_b)
; CHECK: %mul = extractvalue { i32, i1 } %agg, 0
; CHECK-NEXT: --> (%val_a * %val_b) U: full-set S: full-set
%mul = extractvalue { i32, i1 } %agg, 0
ret i32 %mul
}
define i32 @f_umul(i32 %val_a, i32 %val_b) {
; CHECK-LABEL: Classifying expressions for: @f_umul
%agg = tail call { i32, i1 } @llvm.umul.with.overflow.i32(i32 %val_a, i32 %val_b)
; CHECK: %mul = extractvalue { i32, i1 } %agg, 0
; CHECK-NEXT: --> (%val_a * %val_b) U: full-set S: full-set
%mul = extractvalue { i32, i1 } %agg, 0
ret i32 %mul
}
declare { i32, i1 } @llvm.sadd.with.overflow.i32(i32, i32) nounwind readnone
declare { i32, i1 } @llvm.uadd.with.overflow.i32(i32, i32) nounwind readnone
declare { i32, i1 } @llvm.ssub.with.overflow.i32(i32, i32) nounwind readnone
declare { i32, i1 } @llvm.usub.with.overflow.i32(i32, i32) nounwind readnone
declare { i32, i1 } @llvm.smul.with.overflow.i32(i32, i32) nounwind readnone
declare { i32, i1 } @llvm.umul.with.overflow.i32(i32, i32) nounwind readnone
declare void @llvm.trap() #2