<br><br>On Saturday, March 12, 2016, escha via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">escha created this revision.<br>
escha added a reviewer: resistor.<br>
escha added a subscriber: llvm-commits.<br>
escha set the repository for this revision to rL LLVM.<br>
<br>
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.<br>
<br>
Repository:<br>
rL LLVM<br>
<br>
<a href="http://reviews.llvm.org/D18124" target="_blank">http://reviews.llvm.org/D18124</a><br>
<br>
Files:<br>
lib/Analysis/ConstantFolding.cpp<br>
<br>
Index: lib/Analysis/ConstantFolding.cpp<br>
===================================================================<br>
--- lib/Analysis/ConstantFolding.cpp<br>
+++ lib/Analysis/ConstantFolding.cpp<br>
@@ -983,12 +983,14 @@<br>
<br>
// Scan the operand list, checking to see if they are all constants, if so,<br>
// hand off to ConstantFoldInstOperandsImpl.<br>
+ if (!std::all_of(I->op_begin(), I->op_end(), [] (Use &U) {<br>
+ return isa<Constant>(U);<br>
+ }))<br>
+ return nullptr;</blockquote><div><br></div><div>C<span></span>an you use llvm::all_of here?</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+<br>
SmallVector<Constant*, 8> Ops;<br>
for (User::op_iterator i = I->op_begin(), e = I->op_end(); i != e; ++i) {<br>
- Constant *Op = dyn_cast<Constant>(*i);<br>
- if (!Op)<br>
- return nullptr; // All operands not constant!<br>
-<br>
+ Constant *Op = cast<Constant>(*i);<br>
// Fold the Instruction's operands.<br>
if (ConstantExpr *NewCE = dyn_cast<ConstantExpr>(Op))<br>
Op = ConstantFoldConstantExpression(NewCE, DL, TLI);<br>
<br>
<br>
</blockquote>