<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Sep 24, 2014 at 12:12 AM, Jiangning Liu <span dir="ltr"><<a href="mailto:liujiangning1@gmail.com" target="_blank">liujiangning1@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi Dan,<div><br></div><div>I consider your question again, and now I think the lattice lowering order in this algorithm should be "overdefined -> constant/constant_range".</div><div><br></div><div>At first look, following the text book it seems the lattice value TOP should be "undefined", and BOTTOM should be "overdefined". But this is not true for the specific implementation in this LLVM algorithm.</div></div></blockquote><div><br></div><div>Why?<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><br></div><div>In this algorithm, the lowering order is</div><div><br></div><div>Overdefined(TOP) -> constant/constant_range -> Undefined(BOTTOM).</div><div><br></div></div></blockquote><div><br></div><div>What does overdefined and undefiend mean then?</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div></div><div>In order to easily implement the algorithm, originally the BBLV is initialized to be BOTTOM, and this doesn't mean the lowering start point is "Undefined", and it should still be "Overdefined" instead. </div></div></blockquote><div><br></div><div>If it's initiatlized to bottom, then that is the TOP of the lattice ;)</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>If we never touch it in the algorithm, it will be kept as it is. </div></div></blockquote><div><br></div><div>Right.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>This is why once we visit a value at a specific BB, the algorithm will change Undefined to be Overdefined immediately at the very beginning of each lowering procedure.</div></div></blockquote><div><br></div><div>It should either be lowered to constant or overdefined.</div><div>if lowered to constant, it may be lowered again later to overdefined.</div><div>It should not be lowered to overdefined and then raised back to constant.</div><div><br></div><div><br></div><div>If it is lowering to overdefined too quickly, you should make it *not lower* to overdefined*. When I read the patch, and saw the implementation, it looks like you take *overdefined* values and raise them to *constant* sometimes.</div><div>Did i misread it?<br><br></div><div><br></div><div> </div><div> <br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div></div><div>If you look into the implementation details of this algorithm, you may find originally the lower ordering is like that. Originally the algorithm will return "overdefined"(TOP) forever for a specific (Val, BB) pair.</div></div></blockquote><div><br></div><div>This sounds like either a buggy or conservative implementationt hen, and i would fix *this* issue not by raising overdefined occasionally, but by stopping it from getting to overdefined in the first place.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div> This could miss some optimization opportunities as I described in the comment. My patch is trying to increase the number of lowering this "overdefined"(TOP) value.</div></div></blockquote><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><br></div><div>This is my current understanding, but maybe I'm wrong.</div><div><br></div><div>Thanks,<br></div><div>-Jiangning</div><div><div class="h5"><div><br></div><div class="gmail_extra"><br><div class="gmail_quote">2014-09-23 11:08 GMT+08:00 Jiangning Liu <span dir="ltr"><<a href="mailto:liujiangning1@gmail.com" target="_blank">liujiangning1@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi Dan,<div class="gmail_extra"><div class="gmail_quote"><span><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span><br></span><div>So can you explain how you aren't doing this?<br><br></div><div>It looksl ike you think the lattice goes</div><div>undefined</div><div>overdefined</div><div>constant</div><div><br></div><div>That should 100% not be the case</div><div>the lattice order should be</div><div>undefined</div><div>constant</div><div>overdefined</div><div><br></div><div>undefined means you don't know</div><div>constant means it has one value.</div><div>overdefined means it has too many values<br></div><div><br></div><div>This is a traditional value range lattice (though sometimes there are more things in the middle).</div><div>There is no way you should go from overdefined back to constant.</div><span><div><br></div></span></div></div></div></blockquote></span><div>Ah, I see. Thanks for your explanation! I think you are absolutely correct, and I misunderstood lattice value 'overdefined'. The original code is like this,</div><div><br></div><div>  if ((!BBLV.isUndefined() {<br></div><div>     ...</div><div>     return;</div><span><div>  }</div><div><br></div><div><div>  // Otherwise, this is the first time we're seeing this block.  Reset the</div><div>  // lattice value to overdefined, so that cycles will terminate and be</div><div>  // conservatively correct.</div><div>  BBLV.markOverdefined();</div></div><div><br></div></span><div>So this algorithm is really conservative. I think the solution might be removing this lowering or adding threshold control for this lowering. Do you have any suggestions?</div><div><br></div><div>Thanks,</div><div>-Jiangning </div></div></div></div>
</blockquote></div><br></div></div></div></div>
</blockquote></div><br></div></div>