diff --git a/llvm/lib/Analysis/PHITransAddr.cpp b/llvm/lib/Analysis/PHITransAddr.cpp --- a/llvm/lib/Analysis/PHITransAddr.cpp +++ b/llvm/lib/Analysis/PHITransAddr.cpp @@ -26,12 +26,7 @@ cl::desc("Enable phi-translation of add instructions")); static bool canPHITrans(Instruction *Inst) { - if (isa(Inst) || - isa(Inst)) - return true; - - if (isa(Inst) && - isSafeToSpeculativelyExecute(Inst)) + if (isa(Inst) || isa(Inst) || isa(Inst)) return true; if (Inst->getOpcode() == Instruction::Add && @@ -179,7 +174,6 @@ // operands need to be phi translated, and if so, reconstruct it. if (CastInst *Cast = dyn_cast(Inst)) { - if (!isSafeToSpeculativelyExecute(Cast)) return nullptr; Value *PHIIn = translateSubExpr(Cast->getOperand(0), CurBB, PredBB, DT); if (!PHIIn) return nullptr; if (PHIIn == Cast->getOperand(0)) @@ -187,10 +181,12 @@ // Find an available version of this cast. - // Constants are trivial to find. - if (Constant *C = dyn_cast(PHIIn)) - return addAsInput( - ConstantExpr::getCast(Cast->getOpcode(), C, Cast->getType())); + // Try to simplify cast first. + if (Value *V = simplifyCastInst(Cast->getOpcode(), PHIIn, Cast->getType(), + {DL, TLI, DT, AC})) { + RemoveInstInputs(PHIIn, InstInputs); + return addAsInput(V); + } // Otherwise we have to see if a casted version of the incoming pointer // is available. If so, we can use it, otherwise we have to fail. @@ -371,7 +367,6 @@ // Handle cast of PHI translatable value. if (CastInst *Cast = dyn_cast(Inst)) { - if (!isSafeToSpeculativelyExecute(Cast)) return nullptr; Value *OpVal = insertTranslatedSubExpr(Cast->getOperand(0), CurBB, PredBB, DT, NewInsts); if (!OpVal) return nullptr;