<div dir="ltr">The other major one we see in NewGVN is SimplifyCmpInst with pointers.<div>We spend about 10-20% of NewGVN time in it ;)</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, May 26, 2017 at 5:38 PM, Craig Topper via Phabricator <span dir="ltr"><<a href="mailto:reviews@reviews.llvm.org" target="_blank">reviews@reviews.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">craig.topper created this revision.<br>
<br>
Load instructions go through the default case of SimplifyInstruction and use the heavy ConstantFoldInstruction which tries to recursively constant fold any constantexpr operands. I believe this is harder than we try for other instructions in InstSimplify. We usually use some entry point like ConstantFoldBinaryOpOperands or ConstantFoldCompareInstOperand<wbr>s which bypass this logic.<br>
<br>
This patch calls directly to ConstantFoldLoadFromConstPtr if the load has a constant pointer and isn't volatile.<br>
<br>
On one benchmark cpp file I ran through callgrind, this showed instructions executed in SimplifyInstruction reduce by almost half.<br>
<br>
<br>
<a href="https://reviews.llvm.org/D33619" rel="noreferrer" target="_blank">https://reviews.llvm.org/<wbr>D33619</a><br>
<br>
Files:<br>
  lib/Analysis/<wbr>InstructionSimplify.cpp<br>
<br>
<br>
Index: lib/Analysis/<wbr>InstructionSimplify.cpp<br>
==============================<wbr>==============================<wbr>=======<br>
--- lib/Analysis/<wbr>InstructionSimplify.cpp<br>
+++ lib/Analysis/<wbr>InstructionSimplify.cpp<br>
@@ -4542,7 +4542,7 @@<br>
 Value *llvm::SimplifyInstruction(<wbr>Instruction *I, const SimplifyQuery &SQ,<br>
                                  OptimizationRemarkEmitter *ORE) {<br>
   const SimplifyQuery Q = SQ.CxtI ? SQ : SQ.getWithInstruction(I);<br>
-  Value *Result;<br>
+  Value *Result = nullptr;<br>
<br>
   switch (I->getOpcode()) {<br>
   default:<br>
@@ -4673,9 +4673,15 @@<br>
     Result =<br>
         SimplifyCastInst(I->getOpcode(<wbr>), I->getOperand(0), I->getType(), Q);<br>
     break;<br>
+  case Instruction::Load: {<br>
+    auto *LI = cast<LoadInst>(I);<br>
+    if (!LI->isVolatile())<br>
+      if (auto *C = dyn_cast<Constant>(LI-><wbr>getOperand(0)))<br>
+        Result = ConstantFoldLoadFromConstPtr(<wbr>C, LI->getType(), Q.DL);<br>
+    break;<br>
+  }<br>
   case Instruction::Alloca:<br>
     // No simplifications for Alloca and it can't be constant folded.<br>
-    Result = nullptr;<br>
     break;<br>
   }<br>
<br>
<br>
<br>
</blockquote></div><br></div>