Index: lib/Target/PowerPC/PPCBoolRetToInt.cpp =================================================================== --- lib/Target/PowerPC/PPCBoolRetToInt.cpp +++ lib/Target/PowerPC/PPCBoolRetToInt.cpp @@ -66,7 +66,10 @@ while (!WorkList.empty()) { Value *Curr = WorkList.back(); WorkList.pop_back(); - if (User *CurrUser = dyn_cast(Curr)) + User *CurrUser = dyn_cast(Curr); + // Operands of CallInst are skipped because they may not be Bool type, + // and their positions are defined by ABI. + if (CurrUser && !isa(Curr)) for (auto &Op : CurrUser->operands()) if (Defs.insert(Op).second) WorkList.push_back(Op); @@ -199,11 +202,12 @@ if (!std::any_of(Defs.begin(), Defs.end(), isa)) return false; - // Presently, we only know how to handle PHINode, Constant, and Arguments. - // Potentially, bitwise operations (AND, OR, XOR, NOT) and sign extension - // could also be handled in the future. + // Presently, we only know how to handle PHINode, Constant, Arguments and + // CallInst. Potentially, bitwise operations (AND, OR, XOR, NOT) and sign + // extension could also be handled in the future. for (Value *V : Defs) - if (!isa(V) && !isa(V) && !isa(V)) + if (!isa(V) && !isa(V) && + !isa(V) && !isa(V)) return false; for (Value *V : Defs) @@ -221,13 +225,15 @@ if (!BoolToIntMap.count(V)) BoolToIntMap[V] = translate(V); - // Replace the operands of the translated instructions. There were set to + // Replace the operands of the translated instructions. They were set to // zero in the translate function. for (auto &Pair : BoolToIntMap) { User *First = dyn_cast(Pair.first); User *Second = dyn_cast(Pair.second); assert((!First || Second) && "translated from user to non-user!?"); - if (First) + // Operands of CallInst are skipped because they may not be Bool type, + // and their positions are defined by ABI. + if (First && !isa(First)) for (unsigned i = 0; i < First->getNumOperands(); ++i) Second->setOperand(i, BoolToIntMap[First->getOperand(i)]); } Index: test/CodeGen/PowerPC/BoolRetToIntTest.ll =================================================================== --- test/CodeGen/PowerPC/BoolRetToIntTest.ll +++ test/CodeGen/PowerPC/BoolRetToIntTest.ll @@ -198,6 +198,8 @@ define zeroext i1 @call_test() { ; CHECK: [[REG:%.+]] = call i1 %result = call i1 @return_i1() +; CHECK: [[REG:%.+]] = zext i1 {{%.+}} to i32 +; CHECK: [[REG:%.+]] = trunc i32 {{%.+}} to i1 ; CHECK: ret i1 [[REG]] ret i1 %result -} \ No newline at end of file +}