Index: llvm/lib/Transforms/Scalar/SCCP.cpp =================================================================== --- llvm/lib/Transforms/Scalar/SCCP.cpp +++ llvm/lib/Transforms/Scalar/SCCP.cpp @@ -97,6 +97,13 @@ return !LV.isUnknownOrUndef() && !isConstant(LV); } +static bool canSCCPRemoveInstruction(Instruction *I) { + if (wouldInstructionBeTriviallyDead(I)) + return true; + + return (!isa(I) || !I->mayHaveSideEffects()) && !I->isTerminator(); +} + static bool tryToReplaceWithConstant(SCCPSolver &Solver, Value *V) { Constant *Const = nullptr; if (V->getType()->isStructTy()) { @@ -127,7 +134,8 @@ // Calls with "clang.arc.attachedcall" implicitly use the return value and // those uses cannot be updated with a constant. CallBase *CB = dyn_cast(V); - if (CB && ((CB->isMustTailCall() && !CB->isSafeToRemove()) || + if (CB && ((CB->isMustTailCall() && + !canSCCPRemoveInstruction(CB)) || CB->getOperandBundle(LLVMContext::OB_clang_arc_attachedcall))) { Function *F = CB->getCalledFunction(); @@ -156,7 +164,7 @@ if (Inst.getType()->isVoidTy()) continue; if (tryToReplaceWithConstant(Solver, &Inst)) { - if (Inst.isSafeToRemove()) + if (canSCCPRemoveInstruction(&Inst)) Inst.eraseFromParent(); MadeChanges = true;