[llvm] r263374 - ConstantFoldInstruction: avoid wasted calls to ConstantFoldConstantExpression

Fiona Glaser via llvm-commits llvm-commits at lists.llvm.org
Sat Mar 12 21:36:15 PST 2016


Author: escha
Date: Sat Mar 12 23:36:15 2016
New Revision: 263374

URL: http://llvm.org/viewvc/llvm-project?rev=263374&view=rev
Log:
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.

Modified:
    llvm/trunk/lib/Analysis/ConstantFolding.cpp

Modified: llvm/trunk/lib/Analysis/ConstantFolding.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ConstantFolding.cpp?rev=263374&r1=263373&r2=263374&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/ConstantFolding.cpp (original)
+++ llvm/trunk/lib/Analysis/ConstantFolding.cpp Sat Mar 12 23:36:15 2016
@@ -983,12 +983,12 @@ Constant *llvm::ConstantFoldInstruction(
 
   // 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);




More information about the llvm-commits mailing list