1; RUN: opt -bool-ret-to-int -S -o - < %s | FileCheck %s 2 3target datalayout = "e-m:e-i64:64-n32:64" 4target triple = "powerpc64le-unknown-linux-gnu" 5 6; CHECK-LABEL: notBoolRet 7define signext i32 @notBoolRet() { 8entry: 9; CHECK: ret i32 1 10 ret i32 1 11} 12 13; CHECK-LABEL: find 14define zeroext i1 @find(i8** readonly %begin, i8** readnone %end, i1 (i8*)* nocapture %hasProp) { 15entry: 16 %cmp.4 = icmp eq i8** %begin, %end 17 br i1 %cmp.4, label %cleanup, label %for.body.preheader 18 19for.body.preheader: ; preds = %entry 20 br label %for.body 21 22for.cond: ; preds = %for.body 23 %cmp = icmp eq i8** %incdec.ptr, %end 24 br i1 %cmp, label %cleanup.loopexit, label %for.body 25 26for.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 32 33cleanup.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 ] 36 br label %cleanup 37 38cleanup: ; 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 44} 45 46; CHECK-LABEL: retFalse 47define zeroext i1 @retFalse() { 48entry: 49; CHECK: ret i1 false 50 ret i1 false 51} 52 53; CHECK-LABEL: retCvtFalse 54define zeroext i1 @retCvtFalse() { 55entry: 56; CHECK: ret i1 false 57 ret i1 trunc(i32 0 to i1) 58} 59 60; CHECK-LABEL: find_cont 61define void @find_cont(i8** readonly %begin, i8** readnone %end, i1 (i8*)* nocapture %hasProp, void (i1)* nocapture %cont) { 62entry: 63 %cmp.4 = icmp eq i8** %begin, %end 64 br i1 %cmp.4, label %cleanup, label %for.body.preheader 65 66for.body.preheader: ; preds = %entry 67 br label %for.body 68 69for.cond: ; preds = %for.body 70 %cmp = icmp eq i8** %incdec.ptr, %end 71 br i1 %cmp, label %cleanup.loopexit, label %for.body 72 73for.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 79 80cleanup.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 ] 83 br label %cleanup 84 85cleanup: ; 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) 91 ret void 92} 93 94; CHECK-LABEL: find_cont_ret 95define zeroext i1 @find_cont_ret(i8** readonly %begin, i8** readnone %end, i1 (i8*)* nocapture %hasProp, void (i1)* nocapture %cont) { 96entry: 97 %cmp.4 = icmp eq i8** %begin, %end 98 br i1 %cmp.4, label %cleanup, label %for.body.preheader 99 100for.body.preheader: ; preds = %entry 101 br label %for.body 102 103for.cond: ; preds = %for.body 104 %cmp = icmp eq i8** %incdec.ptr, %end 105 br i1 %cmp, label %cleanup.loopexit, label %for.body 106 107for.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 113 114cleanup.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 ] 117 br label %cleanup 118 119cleanup: ; 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 128} 129 130; CHECK-LABEL: arg_operand 131define zeroext i1 @arg_operand(i1 %operand) { 132entry: 133 br i1 %operand, label %foo, label %cleanup 134 135foo: 136 br label %cleanup 137 138cleanup: 139; CHECK: [[REG:%.+]] = trunc i64 {{%.+}} to i1 140; CHECK: ret i1 [[REG]] 141 %result = phi i1 [ false, %foo ], [ %operand, %entry ] 142 ret i1 %result 143} 144 145; CHECK-LABEL: bad_use 146define zeroext i1 @bad_use(i1 %operand) { 147entry: 148 br i1 %operand, label %foo, label %cleanup 149 150foo: 151 br label %cleanup 152 153cleanup: 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 158 ret i1 %result 159} 160 161; CHECK-LABEL: bad_use_closure 162define zeroext i1 @bad_use_closure(i1 %operand) { 163entry: 164 br i1 %operand, label %foo, label %cleanup 165 166foo: 167 %bar = phi i1 [ false, %entry ] 168 %0 = icmp eq i1 %bar, %operand 169 br label %cleanup 170 171cleanup: 172; CHECK: [[REG:%.+]] = phi i1 [ true 173; CHECK: ret i1 [[REG]] 174 %result = phi i1 [ true, %entry ], [ %bar, %foo] 175 ret i1 %result 176} 177 178; CHECK-LABEL: arg_test 179define zeroext i1 @arg_test(i1 %operand) { 180entry: 181 br i1 %operand, label %foo, label %cleanup 182 183foo: 184 %bar = phi i1 [ false, %entry ] 185 br label %cleanup 186 187; CHECK-LABEL: cleanup 188cleanup: 189; CHECK: [[REG:%.+]] = trunc i64 {{%.+}} to i1 190; CHECK: ret i1 [[REG]] 191 %result = phi i1 [ %bar, %foo], [ %operand, %entry ] 192 ret i1 %result 193} 194 195declare zeroext i1 @return_i1() 196 197; CHECK-LABEL: call_test 198define 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]] 204 ret i1 %result 205} 206