Index: lib/Analysis/ConstantFolding.cpp =================================================================== --- lib/Analysis/ConstantFolding.cpp +++ lib/Analysis/ConstantFolding.cpp @@ -983,12 +983,12 @@ // Scan the operand list, checking to see if they are all constants, if so, // hand off to ConstantFoldInstOperandsImpl. + if (!llvm::all_of(I->operands(), [] (Use &U) { return isa(U); })) + return nullptr; + SmallVector Ops; for (User::op_iterator i = I->op_begin(), e = I->op_end(); i != e; ++i) { - Constant *Op = dyn_cast(*i); - if (!Op) - return nullptr; // All operands not constant! - + Constant *Op = cast(*i); // Fold the Instruction's operands. if (ConstantExpr *NewCE = dyn_cast(Op)) Op = ConstantFoldConstantExpression(NewCE, DL, TLI);