diff options
-rw-r--r-- | llvm/lib/Analysis/ConstantFolding.cpp | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp index 45988a002aa..9e21a7e3edf 100644 --- a/llvm/lib/Analysis/ConstantFolding.cpp +++ b/llvm/lib/Analysis/ConstantFolding.cpp @@ -983,12 +983,12 @@ Constant *llvm::ConstantFoldInstruction(Instruction *I, const DataLayout &DL, // Scan the operand list, checking to see if they are all constants, if so, // hand off to ConstantFoldInstOperandsImpl. - SmallVector<Constant*, 8> Ops; - for (User::op_iterator i = I->op_begin(), e = I->op_end(); i != e; ++i) { - Constant *Op = dyn_cast<Constant>(*i); - if (!Op) - return nullptr; // All operands not constant! + if (!all_of(I->operands(), [](Use &U) { return isa<Constant>(U); })) + return nullptr; + SmallVector<Constant *, 8> Ops; + for (User::op_iterator i = I->op_begin(), e = I->op_end(); i != e; ++i) { + Constant *Op = cast<Constant>(*i); // Fold the Instruction's operands. if (ConstantExpr *NewCE = dyn_cast<ConstantExpr>(Op)) Op = ConstantFoldConstantExpression(NewCE, DL, TLI); |