Index: lib/Transforms/Utils/CallPromotionUtils.cpp =================================================================== --- lib/Transforms/Utils/CallPromotionUtils.cpp +++ lib/Transforms/Utils/CallPromotionUtils.cpp @@ -177,8 +177,8 @@ InsertBefore = &*std::next(CS.getInstruction()->getIterator()); // Bitcast the return value to the correct type. - auto *Cast = CastInst::Create(Instruction::BitCast, CS.getInstruction(), - RetTy, "", InsertBefore); + auto *Cast = CastInst::CreateBitOrPointerCast(CS.getInstruction(), RetTy, "", + InsertBefore); if (RetBitCast) *RetBitCast = Cast; @@ -321,12 +321,14 @@ const char **FailureReason) { assert(!CS.getCalledFunction() && "Only indirect call sites can be promoted"); + auto &DL = Callee->getParent()->getDataLayout(); + // Check the return type. The callee's return value type must be bitcast // compatible with the call site's type. Type *CallRetTy = CS.getInstruction()->getType(); Type *FuncRetTy = Callee->getReturnType(); if (CallRetTy != FuncRetTy) - if (!CastInst::isBitCastable(FuncRetTy, CallRetTy)) { + if (!CastInst::isBitOrNoopPointerCastable(FuncRetTy, CallRetTy, DL)) { if (FailureReason) *FailureReason = "Return type mismatch"; return false; @@ -351,7 +353,7 @@ Type *ActualTy = CS.getArgument(I)->getType(); if (FormalTy == ActualTy) continue; - if (!CastInst::isBitCastable(ActualTy, FormalTy)) { + if (!CastInst::isBitOrNoopPointerCastable(ActualTy, FormalTy, DL)) { if (FailureReason) *FailureReason = "Argument type mismatch"; return false; @@ -396,8 +398,8 @@ Type *FormalTy = CalleeType->getParamType(ArgNo); Type *ActualTy = Arg->getType(); if (FormalTy != ActualTy) { - auto *Cast = CastInst::Create(Instruction::BitCast, Arg, FormalTy, "", - CS.getInstruction()); + auto *Cast = CastInst::CreateBitOrPointerCast(Arg, FormalTy, "", + CS.getInstruction()); CS.setArgument(ArgNo, Cast); } }