<div style="font-family: arial, helvetica, sans-serif"><font size="2"><div class="gmail_quote">On Fri, Jun 15, 2012 at 1:07 PM, Andrew Trick <span dir="ltr"><<a href="mailto:atrick@apple.com" target="_blank">atrick@apple.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: atrick<br>
Date: Fri Jun 15 15:07:29 2012<br>
New Revision: 158537<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=158537&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=158537&view=rev</a><br>
Log:<br>
LSR: fix expansion of scaled reg in non-address type formulae.<br>
<br>
For non-address users, Base and Scaled registers are not specially<br>
associated to fit an address mode, so SCEVExpander should apply normal<br>
expansion rules. Otherwise we may sink computation into inner loops<br>
that have already been optimized.<br></blockquote><div><br></div><div>Test case possible?</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Modified:<br>
    llvm/trunk/lib/Transforms/Scalar/LoopStrengthReduce.cpp<br>
<br>
Modified: llvm/trunk/lib/Transforms/Scalar/LoopStrengthReduce.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/LoopStrengthReduce.cpp?rev=158537&r1=158536&r2=158537&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/LoopStrengthReduce.cpp?rev=158537&r1=158536&r2=158537&view=diff</a><br>

==============================================================================<br>
--- llvm/trunk/lib/Transforms/Scalar/LoopStrengthReduce.cpp (original)<br>
+++ llvm/trunk/lib/Transforms/Scalar/LoopStrengthReduce.cpp Fri Jun 15 15:07:29 2012<br>
@@ -4268,13 +4268,6 @@<br>
     Ops.push_back(SE.getUnknown(Rewriter.expandCodeFor(Reg, 0, IP)));<br>
   }<br>
<br>
-  // Flush the operand list to suppress SCEVExpander hoisting.<br>
-  if (!Ops.empty()) {<br>
-    Value *FullV = Rewriter.expandCodeFor(SE.getAddExpr(Ops), Ty, IP);<br>
-    Ops.clear();<br>
-    Ops.push_back(SE.getUnknown(FullV));<br>
-  }<br>
-<br>
   // Expand the ScaledReg portion.<br>
   Value *ICmpScaledV = 0;<br>
   if (F.AM.Scale != 0) {<br>
@@ -4296,23 +4289,34 @@<br>
     } else {<br>
       // Otherwise just expand the scaled register and an explicit scale,<br>
       // which is expected to be matched as part of the address.<br>
+<br>
+      // Flush the operand list to suppress SCEVExpander hoisting address modes.<br>
+      if (!Ops.empty() && LU.Kind == LSRUse::Address) {<br>
+        Value *FullV = Rewriter.expandCodeFor(SE.getAddExpr(Ops), Ty, IP);<br>
+        Ops.clear();<br>
+        Ops.push_back(SE.getUnknown(FullV));<br>
+      }<br>
       ScaledS = SE.getUnknown(Rewriter.expandCodeFor(ScaledS, 0, IP));<br>
       ScaledS = SE.getMulExpr(ScaledS,<br>
                               SE.getConstant(ScaledS->getType(), F.AM.Scale));<br>
       Ops.push_back(ScaledS);<br>
-<br>
-      // Flush the operand list to suppress SCEVExpander hoisting.<br>
-      Value *FullV = Rewriter.expandCodeFor(SE.getAddExpr(Ops), Ty, IP);<br>
-      Ops.clear();<br>
-      Ops.push_back(SE.getUnknown(FullV));<br>
     }<br>
   }<br>
<br>
   // Expand the GV portion.<br>
   if (F.AM.BaseGV) {<br>
+    // Flush the operand list to suppress SCEVExpander hoisting.<br>
+    if (!Ops.empty()) {<br>
+      Value *FullV = Rewriter.expandCodeFor(SE.getAddExpr(Ops), Ty, IP);<br>
+      Ops.clear();<br>
+      Ops.push_back(SE.getUnknown(FullV));<br>
+    }<br>
     Ops.push_back(SE.getUnknown(F.AM.BaseGV));<br>
+  }<br>
<br>
-    // Flush the operand list to suppress SCEVExpander hoisting.<br>
+  // Flush the operand list to suppress SCEVExpander hoisting of both folded and<br>
+  // unfolded offsets. LSR assumes they both live next to their uses.<br>
+  if (!Ops.empty()) {<br>
     Value *FullV = Rewriter.expandCodeFor(SE.getAddExpr(Ops), Ty, IP);<br>
     Ops.clear();<br>
     Ops.push_back(SE.getUnknown(FullV));<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></font></div>