<br><br><div class="gmail_quote">On Fri Sep 19 2014 at 11:54:41 AM Daniel Berlin <<a href="mailto:dberlin@dberlin.org">dberlin@dberlin.org</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hey Jiangning,<br><span style="line-height:20px">Note that this also changes it from being O(n) to O(n^2) in terms of number of iterations, since things can go back up the lattice now.  It also should never happen :)</span><div><span style="line-height:20px"><br></span><div style="line-height:20px"><br></div><div style="line-height:20px">In the comments, you say</div></div><div><div style="line-height:20px"><span style="line-height:19.7999992370605px">+  // Once this BB is encountered, Val's value for this BB will not be Undefined</span><br style="line-height:19.7999992370605px"><span style="line-height:19.7999992370605px">+  // any longer. When we encounter this BB again, if Val's value is Overdefined,</span><br style="line-height:19.7999992370605px"><span style="line-height:19.7999992370605px">+  // we need to compute its value again.</span><br style="line-height:19.7999992370605px"><span style="line-height:19.7999992370605px">+  //</span><br style="line-height:19.7999992370605px"><span style="line-height:19.7999992370605px">+  // For example, considering this control flow,</span><br style="line-height:19.7999992370605px"><span style="line-height:19.7999992370605px">+  //   BB1->BB2, BB1->BB3, BB2->BB3, BB2->BB4</span><br style="line-height:19.7999992370605px"><span style="line-height:19.7999992370605px">+  //</span><br style="line-height:19.7999992370605px"><span style="line-height:19.7999992370605px">+  // Suppose we have "icmp slt %v, 0" in BB1, and "icmp sgt %v, 0" in BB3. At</span><br style="line-height:19.7999992370605px"><span style="line-height:19.7999992370605px">+  // the very beginning, when analyzing edge BB2->BB3, we don't know %v's value</span><br style="line-height:19.7999992370605px"><span style="line-height:19.7999992370605px">+  // in BB2, and the data flow algorithm tries to compute BB2's predecessors, so</span><br style="line-height:19.7999992370605px"><span style="line-height:19.7999992370605px">+  // then we know %v has negative value on edge BB1->BB2. And then we return to</span><br style="line-height:19.7999992370605px"><span style="line-height:19.7999992370605px">+  // check BB2 again, and at this moment BB2 has Overdefined value for %v in</span><br style="line-height:19.7999992370605px"><span style="line-height:19.7999992370605px">+  // BB2. So we should have to follow data flow propagation algorithm to get the</span><br style="line-height:19.7999992370605px"><span style="line-height:19.7999992370605px">+  // value on edge BB1->BB2 propagated to BB2, and finally %v on BB2 has a</span><br style="line-height:19.7999992370605px"><span style="line-height:19.7999992370605px">+  // constant range describing a negative value.</span><br></div><div style="line-height:20px"><br></div></div><div><div style="line-height:20px">This does not explain why BB2's value of %v started out as overdefined.</div><div style="line-height:20px">Somewhere in here, either propagation order is wrong, or the CFG has some weirdness (is the CFG above the complete description of the testcase? Are there critical edges).</div><div style="line-height:20px"><br></div><div style="line-height:20px">IMHO, You should never have a case where things to go the wrong direction in the lattice.</div></div></blockquote><div><br></div><div>To be a little more forceful here:<br><br></div><div>The base invariant of all of these kinds of algorithms (value range analysis, constant propagation, etc) is that values only go in one direction on the lattice.</div><div>If you have found a case where this is not true, either</div><div>1. The implementation is buggy/broken</div><div>2. The algorithm isn't powerful enough to handle what you really want to happen, and you should change algorithms :)</div><div><br></div><div>One of these is the real problem.</div><div><br></div><div>There is no case where the right solution should involved reevaluating values and moving them in the wrong direction on the lattice.</div><div>Besides hiding whatever the real problem is, it also changes the time bounds of the algorithm.</div></div>