Index: lib/Analysis/LazyValueInfo.cpp =================================================================== --- lib/Analysis/LazyValueInfo.cpp +++ lib/Analysis/LazyValueInfo.cpp @@ -1401,6 +1401,14 @@ return LVILatticeVal::getOverdefined(); } +// Return true if the instruction type of Val is supported by +// constantFoldUser(). Currently CastInst and BinaryOperator only. Call this +// before calling constantFoldUser() to find out if it's even worth attempting +// to call it. +static bool canConstantFoldUser(Value *Val) { + return isa(Val) || isa(Val); +} + /// \brief Compute the value of Val on the edge BBFrom -> BBTo. Returns false if /// Val is not constrained on the edge. Result is unspecified if return value /// is false. @@ -1434,7 +1442,9 @@ if (User *Usr = dyn_cast(Val)) { assert(Result.isOverdefined() && "Result isn't overdefined"); - if (isa(Val->getType())) { + // Check with canConstantFoldUser() first to avoid checking the operands + // which can be expensive for a large phi, etc. + if (isa(Val->getType()) && canConstantFoldUser(Val)) { const DataLayout &DL = BBTo->getModule()->getDataLayout(); if (usesOperand(Usr, Condition)) { // If Val has Condition as an operand and Val can be folded into a