206 lines · plain
1; RUN: opt -ppc-bool-ret-to-int -S -o - < %s | FileCheck %s2 3target datalayout = "e-m:e-i64:64-n32:64"4target triple = "powerpc64le-unknown-linux-gnu"5 6; CHECK-LABEL: notBoolRet7define signext i32 @notBoolRet() {8entry:9; CHECK: ret i32 110 ret i32 111}12 13; CHECK-LABEL: find14define zeroext i1 @find(ptr readonly %begin, ptr readnone %end, ptr nocapture %hasProp) {15entry:16 %cmp.4 = icmp eq ptr %begin, %end17 br i1 %cmp.4, label %cleanup, label %for.body.preheader18 19for.body.preheader: ; preds = %entry20 br label %for.body21 22for.cond: ; preds = %for.body23 %cmp = icmp eq ptr %incdec.ptr, %end24 br i1 %cmp, label %cleanup.loopexit, label %for.body25 26for.body: ; preds = %for.body.preheader, %for.cond27 %curr.05 = phi ptr [ %incdec.ptr, %for.cond ], [ %begin, %for.body.preheader ]28 %0 = load ptr, ptr %curr.05, align 829 %call = tail call zeroext i1 %hasProp(ptr %0)30 %incdec.ptr = getelementptr inbounds ptr, ptr %curr.05, i64 131 br i1 %call, label %cleanup.loopexit, label %for.cond32 33cleanup.loopexit: ; preds = %for.body, %for.cond34; 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 %cleanup37 38cleanup: ; preds = %cleanup.loopexit, %entry39; 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 i142; CHECK: ret i1 [[REG]]43 ret i1 %cleanup.dest.slot.044}45 46; CHECK-LABEL: retFalse47define zeroext i1 @retFalse() {48entry:49; CHECK: ret i1 false50 ret i1 false51}52 53; CHECK-LABEL: retCvtFalse54define zeroext i1 @retCvtFalse() {55entry:56; CHECK: ret i1 false57 ret i1 trunc(i32 0 to i1)58}59 60; CHECK-LABEL: find_cont61define void @find_cont(ptr readonly %begin, ptr readnone %end, ptr nocapture %hasProp, ptr nocapture %cont) {62entry:63 %cmp.4 = icmp eq ptr %begin, %end64 br i1 %cmp.4, label %cleanup, label %for.body.preheader65 66for.body.preheader: ; preds = %entry67 br label %for.body68 69for.cond: ; preds = %for.body70 %cmp = icmp eq ptr %incdec.ptr, %end71 br i1 %cmp, label %cleanup.loopexit, label %for.body72 73for.body: ; preds = %for.body.preheader, %for.cond74 %curr.05 = phi ptr [ %incdec.ptr, %for.cond ], [ %begin, %for.body.preheader ]75 %0 = load ptr, ptr %curr.05, align 876 %call = tail call zeroext i1 %hasProp(ptr %0)77 %incdec.ptr = getelementptr inbounds ptr, ptr %curr.05, i64 178 br i1 %call, label %cleanup.loopexit, label %for.cond79 80cleanup.loopexit: ; preds = %for.body, %for.cond81; 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 %cleanup84 85cleanup: ; preds = %cleanup.loopexit, %entry86; 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 i189; CHECK: call void %cont(i1 [[REG]]90 tail call void %cont(i1 %cleanup.dest.slot.0)91 ret void92}93 94; CHECK-LABEL: find_cont_ret95define zeroext i1 @find_cont_ret(ptr readonly %begin, ptr readnone %end, ptr nocapture %hasProp, ptr nocapture %cont) {96entry:97 %cmp.4 = icmp eq ptr %begin, %end98 br i1 %cmp.4, label %cleanup, label %for.body.preheader99 100for.body.preheader: ; preds = %entry101 br label %for.body102 103for.cond: ; preds = %for.body104 %cmp = icmp eq ptr %incdec.ptr, %end105 br i1 %cmp, label %cleanup.loopexit, label %for.body106 107for.body: ; preds = %for.body.preheader, %for.cond108 %curr.05 = phi ptr [ %incdec.ptr, %for.cond ], [ %begin, %for.body.preheader ]109 %0 = load ptr, ptr %curr.05, align 8110 %call = tail call zeroext i1 %hasProp(ptr %0)111 %incdec.ptr = getelementptr inbounds ptr, ptr %curr.05, i64 1112 br i1 %call, label %cleanup.loopexit, label %for.cond113 114cleanup.loopexit: ; preds = %for.body, %for.cond115; 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 %cleanup118 119cleanup: ; preds = %cleanup.loopexit, %entry120; 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 i1123; CHECK: call void %cont(i1 [[REG]]124 tail call void %cont(i1 %cleanup.dest.slot.0)125; CHECK: [[REG:%.+]] = trunc i64 {{%.+}} to i1126; CHECK: ret i1 [[REG]]127 ret i1 %cleanup.dest.slot.0128}129 130; CHECK-LABEL: arg_operand131define zeroext i1 @arg_operand(i1 %operand) {132entry:133 br i1 %operand, label %foo, label %cleanup134 135foo:136 br label %cleanup137 138cleanup:139; CHECK: [[REG:%.+]] = trunc i64 {{%.+}} to i1140; CHECK: ret i1 [[REG]]141 %result = phi i1 [ false, %foo ], [ %operand, %entry ]142 ret i1 %result143}144 145; CHECK-LABEL: bad_use146define zeroext i1 @bad_use(i1 %operand) {147entry:148 br i1 %operand, label %foo, label %cleanup149 150foo:151 br label %cleanup152 153cleanup:154; CHECK: [[REG:%.+]] = phi i1155; CHECK: ret i1 [[REG]]156 %result = phi i1 [ false, %foo], [ true, %entry ]157 %0 = icmp eq i1 %result, %operand158 ret i1 %result159}160 161; CHECK-LABEL: bad_use_closure162define zeroext i1 @bad_use_closure(i1 %operand) {163entry:164 br i1 %operand, label %foo, label %cleanup165 166foo:167 %bar = phi i1 [ false, %entry ]168 %0 = icmp eq i1 %bar, %operand169 br label %cleanup170 171cleanup:172; CHECK: [[REG:%.+]] = phi i1 [ true173; CHECK: ret i1 [[REG]]174 %result = phi i1 [ true, %entry ], [ %bar, %foo]175 ret i1 %result176}177 178; CHECK-LABEL: arg_test179define zeroext i1 @arg_test(i1 %operand) {180entry:181 br i1 %operand, label %foo, label %cleanup182 183foo:184 %bar = phi i1 [ false, %entry ]185 br label %cleanup186 187; CHECK-LABEL: cleanup188cleanup:189; CHECK: [[REG:%.+]] = trunc i64 {{%.+}} to i1190; CHECK: ret i1 [[REG]]191 %result = phi i1 [ %bar, %foo], [ %operand, %entry ]192 ret i1 %result193}194 195declare zeroext i1 @return_i1()196 197; CHECK-LABEL: call_test198define zeroext i1 @call_test() {199; CHECK: [[REG:%.+]] = call i1200 %result = call i1 @return_i1()201; CHECK: [[REG:%.+]] = zext i1 {{%.+}} to i64202; CHECK: [[REG:%.+]] = trunc i64 {{%.+}} to i1203; CHECK: ret i1 [[REG]]204 ret i1 %result205}206