ConstantFoldInstruction: avoid wasted calls to ConstantFoldConstantExpression

Check to see if all operands are constant before calling simplify on them
so that we don't perform wasted simplifications.

llvm-svn: 263374
This commit is contained in:
Fiona Glaser
2016-03-13 05:36:15 +00:00
parent 614be59692
commit 2e5c0c2858

View File

@@ -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);