<div dir="ltr">No test case?</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Feb 21, 2014 at 10:15 AM, Sebastian Pop <span dir="ltr"><<a href="mailto:spop@codeaurora.org" target="_blank">spop@codeaurora.org</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: spop<br>
Date: Fri Feb 21 12:15:15 2014<br>
New Revision: 201868<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=201868&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=201868&view=rev</a><br>
Log:<br>
fix a corner case in delinearization<br>
<br>
handle special cases Step==1, Step==-1, GCD==1, and GCD==-1<br>
<br>
Modified:<br>
    llvm/trunk/lib/Analysis/ScalarEvolution.cpp<br>
<br>
Modified: llvm/trunk/lib/Analysis/ScalarEvolution.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ScalarEvolution.cpp?rev=201868&r1=201867&r2=201868&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ScalarEvolution.cpp?rev=201868&r1=201867&r2=201868&view=diff</a><br>

==============================================================================<br>
--- llvm/trunk/lib/Analysis/ScalarEvolution.cpp (original)<br>
+++ llvm/trunk/lib/Analysis/ScalarEvolution.cpp Fri Feb 21 12:15:15 2014<br>
@@ -7255,46 +7255,37 @@ SCEVAddRecExpr::delinearize(ScalarEvolut<br>
<br>
   DEBUG(dbgs() << "(delinearize: " << *this << "\n");<br>
<br>
-  // Currently we fail to delinearize when the stride of this SCEV is 1. We<br>
-  // could decide to not fail in this case: we could just return 1 for the size<br>
-  // of the subscript, and this same SCEV for the access function.<br>
-  if (Step == One) {<br>
-    DEBUG(dbgs() << "failed to delinearize " << *this << "\n)\n");<br>
-    return this;<br>
-  }<br>
+  // When the stride of this SCEV is 1, do not compute the GCD: the size of this<br>
+  // subscript is 1, and this same SCEV for the access function.<br>
+  const SCEV *Remainder = Zero;<br>
+  const SCEV *GCD = One;<br>
<br>
   // Find the GCD and Remainder of the Start and Step coefficients of this SCEV.<br>
-  const SCEV *Remainder = NULL;<br>
-  const SCEV *GCD = SCEVGCD::findGCD(SE, Start, Step, &Remainder);<br>
+  if (Step != One && !Step->isAllOnesValue())<br>
+    GCD = SCEVGCD::findGCD(SE, Start, Step, &Remainder);<br>
<br>
   DEBUG(dbgs() << "GCD: " << *GCD << "\n");<br>
   DEBUG(dbgs() << "Remainder: " << *Remainder << "\n");<br>
<br>
-  // Same remark as above: we currently fail the delinearization, although we<br>
-  // can very well handle this special case.<br>
-  if (GCD == One) {<br>
-    DEBUG(dbgs() << "failed to delinearize " << *this << "\n)\n");<br>
-    return this;<br>
-  }<br>
+  const SCEV *Quotient = Start;<br>
+  if (GCD != One && !GCD->isAllOnesValue())<br>
+    // As findGCD computed Remainder, GCD divides "Start - Remainder." The<br>
+    // Quotient is then this SCEV without Remainder, scaled down by the GCD.  The<br>
+    // Quotient is what will be used in the next subscript delinearization.<br>
+    Quotient = SCEVDivision::divide(SE, SE.getMinusSCEV(Start, Remainder), GCD);<br>
<br>
-  // As findGCD computed Remainder, GCD divides "Start - Remainder." The<br>
-  // Quotient is then this SCEV without Remainder, scaled down by the GCD.  The<br>
-  // Quotient is what will be used in the next subscript delinearization.<br>
-  const SCEV *Quotient =<br>
-      SCEVDivision::divide(SE, SE.getMinusSCEV(Start, Remainder), GCD);<br>
   DEBUG(dbgs() << "Quotient: " << *Quotient << "\n");<br>
<br>
-  const SCEV *Rem;<br>
+  const SCEV *Rem = Quotient;<br>
   if (const SCEVAddRecExpr *AR = dyn_cast<SCEVAddRecExpr>(Quotient))<br>
     // Recursively call delinearize on the Quotient until there are no more<br>
     // multiples that can be recognized.<br>
     Rem = AR->delinearize(SE, Subscripts, Sizes);<br>
-  else<br>
-    Rem = Quotient;<br>
<br>
   // Scale up the canonical induction variable IV by whatever remains from the<br>
   // Step after division by the GCD: the GCD is the size of all the sub-array.<br>
-  if (Step != GCD) {<br>
+  if (Step != One && !Step->isAllOnesValue() && GCD != One &&<br>
+      !GCD->isAllOnesValue() && Step != GCD) {<br>
     Step = SCEVDivision::divide(SE, Step, GCD);<br>
     IV = SE.getMulExpr(IV, Step);<br>
   }<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></div>