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