[PATCH] D18124: ConstantFoldInstruction: avoid wasted calls to ConstantFoldConstantExpression

escha via llvm-commits llvm-commits at lists.llvm.org
Sat Mar 12 16:36:34 PST 2016


escha updated this revision to Diff 50531.
escha added a comment.

Use llvm::all_of.


Repository:
  rL LLVM

http://reviews.llvm.org/D18124

Files:
  lib/Analysis/ConstantFolding.cpp

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<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 = dyn_cast<Constant>(*i);
-    if (!Op)
-      return nullptr;  // All operands not constant!
-
+    Constant *Op = cast<Constant>(*i);
     // Fold the Instruction's operands.
     if (ConstantExpr *NewCE = dyn_cast<ConstantExpr>(Op))
       Op = ConstantFoldConstantExpression(NewCE, DL, TLI);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D18124.50531.patch
Type: text/x-patch
Size: 860 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160313/33b41a30/attachment.bin>


More information about the llvm-commits mailing list