<div dir="ltr">The patch looks ok to me,<div>but it also looks more complex than simply fixing the comment.</div><div>Rather than negating the conditional each time we call findGCD,</div><div>let's leave the code alone and make the comment say something like:</div>
<div><br></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div><i>findGCD returns true if dependence has been disproven;</i></div><div><i>that is, if gcd does not divide Delta.</i></div></blockquote><div>
<br></div><div>Preston</div><div><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Jan 2, 2014 at 10:31 PM, Mingjie Xing <span dir="ltr"><<a href="mailto:mingjie.xing@gmail.com" target="_blank">mingjie.xing@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<br>
While reading source code again, I think it is not a simple comment<br>
typo. The function<br>
findGCD always finds the GCD. So the boolean return value depends on the meaning<br>
what we want it to be. We say the Diophantine equation has a solution<br>
iff GCD divides<br>
Delta. And the dependence is disproved if there is no solution.<br>
<br>
So if we want findGCD return true when GCD divides Delta, souce code<br>
should be fixed<br>
as the following patch,<br>
<br>
Index: lib/Analysis/DependenceAnalysis.cpp<br>
===================================================================<br>
--- lib/Analysis/DependenceAnalysis.cpp (revision 198188)<br>
+++ lib/Analysis/DependenceAnalysis.cpp (working copy)<br>
@@ -1275,7 +1275,7 @@<br>
 //<br>
 // Program 2.1, page 29.<br>
 // Computes the GCD of AM and BM.<br>
-// Also finds a solution to the equation ax - by = gdc(a, b).<br>
+// Also finds a solution to the equation ax - by = gcd(a, b).<br>
 // Returns true iff the gcd divides Delta.<br>
 static<br>
 bool findGCD(unsigned Bits, APInt AM, APInt BM, APInt Delta,<br>
@@ -1301,11 +1301,11 @@<br>
   // make sure gcd divides Delta<br>
   R = Delta.srem(G);<br>
   if (R != 0)<br>
-    return true; // gcd doesn't divide Delta, no dependence<br>
+    return false; // gcd doesn't divide Delta, no dependence<br>
   Q = Delta.sdiv(G);<br>
   X *= Q;<br>
   Y *= Q;<br>
-  return false;<br>
+  return true;<br>
 }<br>
<br>
<br>
@@ -1398,7 +1398,7 @@<br>
   APInt AM = ConstSrcCoeff->getValue()->getValue();<br>
   APInt BM = ConstDstCoeff->getValue()->getValue();<br>
   unsigned Bits = AM.getBitWidth();<br>
-  if (findGCD(Bits, AM, BM, ConstDelta->getValue()->getValue(), G, X, Y)) {<br>
+  if (!findGCD(Bits, AM, BM, ConstDelta->getValue()->getValue(), G, X, Y)) {<br>
     // gcd doesn't divide Delta, no dependence<br>
     ++ExactSIVindependence;<br>
     ++ExactSIVsuccesses;<br>
@@ -1802,7 +1802,7 @@<br>
   APInt AM = ConstSrcCoeff->getValue()->getValue();<br>
   APInt BM = ConstDstCoeff->getValue()->getValue();<br>
   unsigned Bits = AM.getBitWidth();<br>
-  if (findGCD(Bits, AM, BM, ConstDelta->getValue()->getValue(), G, X, Y)) {<br>
+  if (!findGCD(Bits, AM, BM, ConstDelta->getValue()->getValue(), G, X, Y)) {<br>
     // gcd doesn't divide Delta, no dependence<br>
     ++ExactRDIVindependence;<br>
     return true;<br>
<br>
Best Regards,<br>
Mingjie<br>
</blockquote></div><br></div>