[PATCH] D18124: ConstantFoldInstruction: avoid wasted calls to ConstantFoldConstantExpression
escha via llvm-commits
llvm-commits at lists.llvm.org
Sat Mar 12 16:10:58 PST 2016
escha created this revision.
escha added a reviewer: resistor.
escha added a subscriber: llvm-commits.
escha set the repository for this revision to rL LLVM.
The loop here calls ConstantFoldConstantExpression before knowing if all the operands are constant, which can waste a lot of time. Cuts time spent in ConstantFoldInstruction (and callees) by ~20% in our tests. Should be NFC.
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,14 @@
// Scan the operand list, checking to see if they are all constants, if so,
// hand off to ConstantFoldInstOperandsImpl.
+ if (!std::all_of(I->op_begin(), I->op_end(), [] (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.50530.patch
Type: text/x-patch
Size: 888 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160313/41cb32da/attachment.bin>
More information about the llvm-commits
mailing list