BoolRetToIntTest.ll
6.58 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
; RUN: opt -ppc-bool-ret-to-int -S -o - < %s | FileCheck %s
target datalayout = "e-m:e-i64:64-n32:64"
target triple = "powerpc64le-unknown-linux-gnu"
; CHECK-LABEL: notBoolRet
define signext i32 @notBoolRet() {
entry:
; CHECK: ret i32 1
ret i32 1
}
; CHECK-LABEL: find
define zeroext i1 @find(i8** readonly %begin, i8** readnone %end, i1 (i8*)* nocapture %hasProp) {
entry:
%cmp.4 = icmp eq i8** %begin, %end
br i1 %cmp.4, label %cleanup, label %for.body.preheader
for.body.preheader: ; preds = %entry
br label %for.body
for.cond: ; preds = %for.body
%cmp = icmp eq i8** %incdec.ptr, %end
br i1 %cmp, label %cleanup.loopexit, label %for.body
for.body: ; preds = %for.body.preheader, %for.cond
%curr.05 = phi i8** [ %incdec.ptr, %for.cond ], [ %begin, %for.body.preheader ]
%0 = load i8*, i8** %curr.05, align 8
%call = tail call zeroext i1 %hasProp(i8* %0)
%incdec.ptr = getelementptr inbounds i8*, i8** %curr.05, i64 1
br i1 %call, label %cleanup.loopexit, label %for.cond
cleanup.loopexit: ; preds = %for.body, %for.cond
; CHECK: [[PHI:%.+]] = phi i64 [ 1, %for.body ], [ 0, %for.cond ]
%cleanup.dest.slot.0.ph = phi i1 [ true, %for.body ], [ false, %for.cond ]
br label %cleanup
cleanup: ; preds = %cleanup.loopexit, %entry
; CHECK: = phi i64 [ 0, %entry ], [ [[PHI]], %cleanup.loopexit ]
%cleanup.dest.slot.0 = phi i1 [ false, %entry ], [ %cleanup.dest.slot.0.ph, %cleanup.loopexit ]
; CHECK: [[REG:%.+]] = trunc i64 {{%.+}} to i1
; CHECK: ret i1 [[REG]]
ret i1 %cleanup.dest.slot.0
}
; CHECK-LABEL: retFalse
define zeroext i1 @retFalse() {
entry:
; CHECK: ret i1 false
ret i1 false
}
; CHECK-LABEL: retCvtFalse
define zeroext i1 @retCvtFalse() {
entry:
; CHECK: ret i1 false
ret i1 trunc(i32 0 to i1)
}
; CHECK-LABEL: find_cont
define void @find_cont(i8** readonly %begin, i8** readnone %end, i1 (i8*)* nocapture %hasProp, void (i1)* nocapture %cont) {
entry:
%cmp.4 = icmp eq i8** %begin, %end
br i1 %cmp.4, label %cleanup, label %for.body.preheader
for.body.preheader: ; preds = %entry
br label %for.body
for.cond: ; preds = %for.body
%cmp = icmp eq i8** %incdec.ptr, %end
br i1 %cmp, label %cleanup.loopexit, label %for.body
for.body: ; preds = %for.body.preheader, %for.cond
%curr.05 = phi i8** [ %incdec.ptr, %for.cond ], [ %begin, %for.body.preheader ]
%0 = load i8*, i8** %curr.05, align 8
%call = tail call zeroext i1 %hasProp(i8* %0)
%incdec.ptr = getelementptr inbounds i8*, i8** %curr.05, i64 1
br i1 %call, label %cleanup.loopexit, label %for.cond
cleanup.loopexit: ; preds = %for.body, %for.cond
; CHECK: [[PHI:%.+]] = phi i64 [ 1, %for.body ], [ 0, %for.cond ]
%cleanup.dest.slot.0.ph = phi i1 [ true, %for.body ], [ false, %for.cond ]
br label %cleanup
cleanup: ; preds = %cleanup.loopexit, %entry
; CHECK: = phi i64 [ 0, %entry ], [ [[PHI]], %cleanup.loopexit ]
%cleanup.dest.slot.0 = phi i1 [ false, %entry ], [ %cleanup.dest.slot.0.ph, %cleanup.loopexit ]
; CHECK: [[REG:%.+]] = trunc i64 {{%.+}} to i1
; CHECK: call void %cont(i1 [[REG]]
tail call void %cont(i1 %cleanup.dest.slot.0)
ret void
}
; CHECK-LABEL: find_cont_ret
define zeroext i1 @find_cont_ret(i8** readonly %begin, i8** readnone %end, i1 (i8*)* nocapture %hasProp, void (i1)* nocapture %cont) {
entry:
%cmp.4 = icmp eq i8** %begin, %end
br i1 %cmp.4, label %cleanup, label %for.body.preheader
for.body.preheader: ; preds = %entry
br label %for.body
for.cond: ; preds = %for.body
%cmp = icmp eq i8** %incdec.ptr, %end
br i1 %cmp, label %cleanup.loopexit, label %for.body
for.body: ; preds = %for.body.preheader, %for.cond
%curr.05 = phi i8** [ %incdec.ptr, %for.cond ], [ %begin, %for.body.preheader ]
%0 = load i8*, i8** %curr.05, align 8
%call = tail call zeroext i1 %hasProp(i8* %0)
%incdec.ptr = getelementptr inbounds i8*, i8** %curr.05, i64 1
br i1 %call, label %cleanup.loopexit, label %for.cond
cleanup.loopexit: ; preds = %for.body, %for.cond
; CHECK: [[PHI:%.+]] = phi i64 [ 1, %for.body ], [ 0, %for.cond ]
%cleanup.dest.slot.0.ph = phi i1 [ true, %for.body ], [ false, %for.cond ]
br label %cleanup
cleanup: ; preds = %cleanup.loopexit, %entry
; CHECK: = phi i64 [ 0, %entry ], [ [[PHI]], %cleanup.loopexit ]
%cleanup.dest.slot.0 = phi i1 [ false, %entry ], [ %cleanup.dest.slot.0.ph, %cleanup.loopexit ]
; CHECK: [[REG:%.+]] = trunc i64 {{%.+}} to i1
; CHECK: call void %cont(i1 [[REG]]
tail call void %cont(i1 %cleanup.dest.slot.0)
; CHECK: [[REG:%.+]] = trunc i64 {{%.+}} to i1
; CHECK: ret i1 [[REG]]
ret i1 %cleanup.dest.slot.0
}
; CHECK-LABEL: arg_operand
define zeroext i1 @arg_operand(i1 %operand) {
entry:
br i1 %operand, label %foo, label %cleanup
foo:
br label %cleanup
cleanup:
; CHECK: [[REG:%.+]] = trunc i64 {{%.+}} to i1
; CHECK: ret i1 [[REG]]
%result = phi i1 [ false, %foo ], [ %operand, %entry ]
ret i1 %result
}
; CHECK-LABEL: bad_use
define zeroext i1 @bad_use(i1 %operand) {
entry:
br i1 %operand, label %foo, label %cleanup
foo:
br label %cleanup
cleanup:
; CHECK: [[REG:%.+]] = phi i1
; CHECK: ret i1 [[REG]]
%result = phi i1 [ false, %foo], [ true, %entry ]
%0 = icmp eq i1 %result, %operand
ret i1 %result
}
; CHECK-LABEL: bad_use_closure
define zeroext i1 @bad_use_closure(i1 %operand) {
entry:
br i1 %operand, label %foo, label %cleanup
foo:
%bar = phi i1 [ false, %entry ]
%0 = icmp eq i1 %bar, %operand
br label %cleanup
cleanup:
; CHECK: [[REG:%.+]] = phi i1 [ true
; CHECK: ret i1 [[REG]]
%result = phi i1 [ true, %entry ], [ %bar, %foo]
ret i1 %result
}
; CHECK-LABEL: arg_test
define zeroext i1 @arg_test(i1 %operand) {
entry:
br i1 %operand, label %foo, label %cleanup
foo:
%bar = phi i1 [ false, %entry ]
br label %cleanup
; CHECK-LABEL: cleanup
cleanup:
; CHECK: [[REG:%.+]] = trunc i64 {{%.+}} to i1
; CHECK: ret i1 [[REG]]
%result = phi i1 [ %bar, %foo], [ %operand, %entry ]
ret i1 %result
}
declare zeroext i1 @return_i1()
; CHECK-LABEL: call_test
define zeroext i1 @call_test() {
; CHECK: [[REG:%.+]] = call i1
%result = call i1 @return_i1()
; CHECK: [[REG:%.+]] = zext i1 {{%.+}} to i64
; CHECK: [[REG:%.+]] = trunc i64 {{%.+}} to i1
; CHECK: ret i1 [[REG]]
ret i1 %result
}