overflow-intrinsics.ll
4.9 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
; RUN: opt -S -indvars < %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(i8* %a) {
; CHECK-LABEL: @f_sadd(
entry:
br label %for.body
for.cond.cleanup: ; preds = %cont
ret void
for.body: ; preds = %entry, %cont
%i.04 = phi i32 [ 0, %entry ], [ %2, %cont ]
%idxprom = sext i32 %i.04 to i64
%arrayidx = getelementptr inbounds i8, i8* %a, i64 %idxprom
store i8 0, i8* %arrayidx, align 1
%0 = tail call { i32, i1 } @llvm.sadd.with.overflow.i32(i32 %i.04, i32 1)
%1 = extractvalue { i32, i1 } %0, 1
; CHECK: for.body:
; CHECK-NOT: @llvm.sadd.with.overflow
; CHECK: br i1 false, label %trap, label %cont, !nosanitize !0
br i1 %1, label %trap, label %cont, !nosanitize !{}
trap: ; preds = %for.body
tail call void @llvm.trap() #2, !nosanitize !{}
unreachable, !nosanitize !{}
cont: ; preds = %for.body
%2 = extractvalue { i32, i1 } %0, 0
%cmp = icmp slt i32 %2, 16
br i1 %cmp, label %for.body, label %for.cond.cleanup
}
define void @f_uadd(i8* %a) {
; CHECK-LABEL: @f_uadd(
entry:
br label %for.body
for.cond.cleanup: ; preds = %cont
ret void
for.body: ; preds = %entry, %cont
%i.04 = phi i32 [ 0, %entry ], [ %2, %cont ]
%idxprom = sext i32 %i.04 to i64
%arrayidx = getelementptr inbounds i8, i8* %a, i64 %idxprom
store i8 0, i8* %arrayidx, align 1
%0 = tail call { i32, i1 } @llvm.uadd.with.overflow.i32(i32 %i.04, i32 1)
%1 = extractvalue { i32, i1 } %0, 1
; CHECK: for.body:
; CHECK-NOT: @llvm.uadd.with.overflow
; CHECK: br i1 false, label %trap, label %cont, !nosanitize !0
br i1 %1, label %trap, label %cont, !nosanitize !{}
trap: ; preds = %for.body
tail call void @llvm.trap(), !nosanitize !{}
unreachable, !nosanitize !{}
cont: ; preds = %for.body
%2 = extractvalue { i32, i1 } %0, 0
%cmp = icmp slt i32 %2, 16
br i1 %cmp, label %for.body, label %for.cond.cleanup
}
define void @f_ssub(i8* nocapture %a) {
; CHECK-LABEL: @f_ssub(
entry:
br label %for.body
for.cond.cleanup: ; preds = %cont
ret void
for.body: ; preds = %entry, %cont
%i.04 = phi i32 [ 15, %entry ], [ %2, %cont ]
%idxprom = sext i32 %i.04 to i64
%arrayidx = getelementptr inbounds i8, i8* %a, i64 %idxprom
store i8 0, i8* %arrayidx, align 1
%0 = tail call { i32, i1 } @llvm.ssub.with.overflow.i32(i32 %i.04, i32 1)
%1 = extractvalue { i32, i1 } %0, 1
; CHECK: for.body:
; CHECK-NOT: @llvm.ssub.with.overflow.i32
; CHECK: br i1 false, label %trap, label %cont, !nosanitize !0
br i1 %1, label %trap, label %cont, !nosanitize !{}
trap: ; preds = %for.body
tail call void @llvm.trap(), !nosanitize !{}
unreachable, !nosanitize !{}
cont: ; preds = %for.body
%2 = extractvalue { i32, i1 } %0, 0
%cmp = icmp sgt i32 %2, -1
br i1 %cmp, label %for.body, label %for.cond.cleanup
}
define void @f_usub(i8* nocapture %a) {
; CHECK-LABEL: @f_usub(
entry:
br label %for.body
for.cond.cleanup: ; preds = %cont
ret void
for.body: ; preds = %entry, %cont
%i.04 = phi i32 [ 15, %entry ], [ %2, %cont ]
%idxprom = sext i32 %i.04 to i64
%arrayidx = getelementptr inbounds i8, i8* %a, i64 %idxprom
store i8 0, i8* %arrayidx, align 1
%0 = tail call { i32, i1 } @llvm.usub.with.overflow.i32(i32 %i.04, i32 1)
%1 = extractvalue { i32, i1 } %0, 1
; It is theoretically possible to prove this, but SCEV cannot
; represent non-unsigned-wrapping subtraction operations.
; CHECK: for.body:
; CHECK: [[COND:%[^ ]+]] = extractvalue { i32, i1 } %1, 1
; CHECK-NEXT: br i1 [[COND]], label %trap, label %cont, !nosanitize !0
br i1 %1, label %trap, label %cont, !nosanitize !{}
trap: ; preds = %for.body
tail call void @llvm.trap(), !nosanitize !{}
unreachable, !nosanitize !{}
cont: ; preds = %for.body
%2 = extractvalue { i32, i1 } %0, 0
%cmp = icmp sgt i32 %2, -1
br i1 %cmp, label %for.body, label %for.cond.cleanup
}
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