1 ; RUN: opt -ppc-bool-ret-to-int -S -o - < %s | FileCheck %s
3 target datalayout = "e-m:e-i64:64-n32:64"
4 target triple = "powerpc64le-unknown-linux-gnu"
6 ; CHECK-LABEL: notBoolRet
7 define signext i32 @notBoolRet() {
14 define zeroext i1 @find(i8** readonly %begin, i8** readnone %end, i1 (i8*)* nocapture %hasProp) {
16 %cmp.4 = icmp eq i8** %begin, %end
17 br i1 %cmp.4, label %cleanup, label %for.body.preheader
19 for.body.preheader: ; preds = %entry
22 for.cond: ; preds = %for.body
23 %cmp = icmp eq i8** %incdec.ptr, %end
24 br i1 %cmp, label %cleanup.loopexit, label %for.body
26 for.body: ; preds = %for.body.preheader, %for.cond
27 %curr.05 = phi i8** [ %incdec.ptr, %for.cond ], [ %begin, %for.body.preheader ]
28 %0 = load i8*, i8** %curr.05, align 8
29 %call = tail call zeroext i1 %hasProp(i8* %0)
30 %incdec.ptr = getelementptr inbounds i8*, i8** %curr.05, i64 1
31 br i1 %call, label %cleanup.loopexit, label %for.cond
33 cleanup.loopexit: ; preds = %for.body, %for.cond
34 ; CHECK: [[PHI:%.+]] = phi i64 [ 1, %for.body ], [ 0, %for.cond ]
35 %cleanup.dest.slot.0.ph = phi i1 [ true, %for.body ], [ false, %for.cond ]
38 cleanup: ; preds = %cleanup.loopexit, %entry
39 ; CHECK: = phi i64 [ 0, %entry ], [ [[PHI]], %cleanup.loopexit ]
40 %cleanup.dest.slot.0 = phi i1 [ false, %entry ], [ %cleanup.dest.slot.0.ph, %cleanup.loopexit ]
41 ; CHECK: [[REG:%.+]] = trunc i64 {{%.+}} to i1
42 ; CHECK: ret i1 [[REG]]
43 ret i1 %cleanup.dest.slot.0
46 ; CHECK-LABEL: retFalse
47 define zeroext i1 @retFalse() {
53 ; CHECK-LABEL: retCvtFalse
54 define zeroext i1 @retCvtFalse() {
57 ret i1 trunc(i32 0 to i1)
60 ; CHECK-LABEL: find_cont
61 define void @find_cont(i8** readonly %begin, i8** readnone %end, i1 (i8*)* nocapture %hasProp, void (i1)* nocapture %cont) {
63 %cmp.4 = icmp eq i8** %begin, %end
64 br i1 %cmp.4, label %cleanup, label %for.body.preheader
66 for.body.preheader: ; preds = %entry
69 for.cond: ; preds = %for.body
70 %cmp = icmp eq i8** %incdec.ptr, %end
71 br i1 %cmp, label %cleanup.loopexit, label %for.body
73 for.body: ; preds = %for.body.preheader, %for.cond
74 %curr.05 = phi i8** [ %incdec.ptr, %for.cond ], [ %begin, %for.body.preheader ]
75 %0 = load i8*, i8** %curr.05, align 8
76 %call = tail call zeroext i1 %hasProp(i8* %0)
77 %incdec.ptr = getelementptr inbounds i8*, i8** %curr.05, i64 1
78 br i1 %call, label %cleanup.loopexit, label %for.cond
80 cleanup.loopexit: ; preds = %for.body, %for.cond
81 ; CHECK: [[PHI:%.+]] = phi i64 [ 1, %for.body ], [ 0, %for.cond ]
82 %cleanup.dest.slot.0.ph = phi i1 [ true, %for.body ], [ false, %for.cond ]
85 cleanup: ; preds = %cleanup.loopexit, %entry
86 ; CHECK: = phi i64 [ 0, %entry ], [ [[PHI]], %cleanup.loopexit ]
87 %cleanup.dest.slot.0 = phi i1 [ false, %entry ], [ %cleanup.dest.slot.0.ph, %cleanup.loopexit ]
88 ; CHECK: [[REG:%.+]] = trunc i64 {{%.+}} to i1
89 ; CHECK: call void %cont(i1 [[REG]]
90 tail call void %cont(i1 %cleanup.dest.slot.0)
94 ; CHECK-LABEL: find_cont_ret
95 define zeroext i1 @find_cont_ret(i8** readonly %begin, i8** readnone %end, i1 (i8*)* nocapture %hasProp, void (i1)* nocapture %cont) {
97 %cmp.4 = icmp eq i8** %begin, %end
98 br i1 %cmp.4, label %cleanup, label %for.body.preheader
100 for.body.preheader: ; preds = %entry
103 for.cond: ; preds = %for.body
104 %cmp = icmp eq i8** %incdec.ptr, %end
105 br i1 %cmp, label %cleanup.loopexit, label %for.body
107 for.body: ; preds = %for.body.preheader, %for.cond
108 %curr.05 = phi i8** [ %incdec.ptr, %for.cond ], [ %begin, %for.body.preheader ]
109 %0 = load i8*, i8** %curr.05, align 8
110 %call = tail call zeroext i1 %hasProp(i8* %0)
111 %incdec.ptr = getelementptr inbounds i8*, i8** %curr.05, i64 1
112 br i1 %call, label %cleanup.loopexit, label %for.cond
114 cleanup.loopexit: ; preds = %for.body, %for.cond
115 ; CHECK: [[PHI:%.+]] = phi i64 [ 1, %for.body ], [ 0, %for.cond ]
116 %cleanup.dest.slot.0.ph = phi i1 [ true, %for.body ], [ false, %for.cond ]
119 cleanup: ; preds = %cleanup.loopexit, %entry
120 ; CHECK: = phi i64 [ 0, %entry ], [ [[PHI]], %cleanup.loopexit ]
121 %cleanup.dest.slot.0 = phi i1 [ false, %entry ], [ %cleanup.dest.slot.0.ph, %cleanup.loopexit ]
122 ; CHECK: [[REG:%.+]] = trunc i64 {{%.+}} to i1
123 ; CHECK: call void %cont(i1 [[REG]]
124 tail call void %cont(i1 %cleanup.dest.slot.0)
125 ; CHECK: [[REG:%.+]] = trunc i64 {{%.+}} to i1
126 ; CHECK: ret i1 [[REG]]
127 ret i1 %cleanup.dest.slot.0
130 ; CHECK-LABEL: arg_operand
131 define zeroext i1 @arg_operand(i1 %operand) {
133 br i1 %operand, label %foo, label %cleanup
139 ; CHECK: [[REG:%.+]] = trunc i64 {{%.+}} to i1
140 ; CHECK: ret i1 [[REG]]
141 %result = phi i1 [ false, %foo ], [ %operand, %entry ]
145 ; CHECK-LABEL: bad_use
146 define zeroext i1 @bad_use(i1 %operand) {
148 br i1 %operand, label %foo, label %cleanup
154 ; CHECK: [[REG:%.+]] = phi i1
155 ; CHECK: ret i1 [[REG]]
156 %result = phi i1 [ false, %foo], [ true, %entry ]
157 %0 = icmp eq i1 %result, %operand
161 ; CHECK-LABEL: bad_use_closure
162 define zeroext i1 @bad_use_closure(i1 %operand) {
164 br i1 %operand, label %foo, label %cleanup
167 %bar = phi i1 [ false, %entry ]
168 %0 = icmp eq i1 %bar, %operand
172 ; CHECK: [[REG:%.+]] = phi i1 [ true
173 ; CHECK: ret i1 [[REG]]
174 %result = phi i1 [ true, %entry ], [ %bar, %foo]
178 ; CHECK-LABEL: arg_test
179 define zeroext i1 @arg_test(i1 %operand) {
181 br i1 %operand, label %foo, label %cleanup
184 %bar = phi i1 [ false, %entry ]
187 ; CHECK-LABEL: cleanup
189 ; CHECK: [[REG:%.+]] = trunc i64 {{%.+}} to i1
190 ; CHECK: ret i1 [[REG]]
191 %result = phi i1 [ %bar, %foo], [ %operand, %entry ]
195 declare zeroext i1 @return_i1()
197 ; CHECK-LABEL: call_test
198 define zeroext i1 @call_test() {
199 ; CHECK: [[REG:%.+]] = call i1
200 %result = call i1 @return_i1()
201 ; CHECK: [[REG:%.+]] = zext i1 {{%.+}} to i64
202 ; CHECK: [[REG:%.+]] = trunc i64 {{%.+}} to i1
203 ; CHECK: ret i1 [[REG]]