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 @@ -181,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.