<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Mar 3, 2017 at 12:39 PM, Friedman, Eli <span dir="ltr"><<a href="mailto:efriedma@codeaurora.org" target="_blank">efriedma@codeaurora.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span class="gmail-">On 3/3/2017 11:51 AM, Daniel Berlin via llvm-dev wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
So i have a testcase (see PR31792, and cond_br2.llin GVN) that current GVN can simplify because it replaces instructions as it goes. It's an example of a larger issue that pops up quite a lot<br>
I would appreciate thoughts on what to do about it<br>
it amounts to something like this (but again, it happens a lot):<br>
<br>
live = gep thing, 0<br>
live2 = gep thing, 1<br>
branch i1 provablytrue,, mergeblock, otherbb<br>
otherbb:<br>
dead = something else<br>
br mergeblock<br>
merge block<br>
a = phi(live, dead)<br>
b = live2<br>
result = icmp sge a, b<br>
<br>
both GVN and NewGVN prove provablytrue to be true, and phi to be equivalent to live.<br>
<br>
GVN transforms this piece at time, and so by the time simplifycmpinst sees the icmp, it is<br>
<br>
result = icmp sge <live2, live><br>
<br>
It proves result true.<br>
<br>
NewGVN is an analysis, and so it doesn't transform the ir, and simplifycmpinst (rightfully) does not try to walk everything, everywhere, to prove something. It also couldn't know that dead is dead. So it doesn't see that result is true.<br>
</blockquote>
<br></span>
Why aren't we calling SimplifyCmpInst(pred, live, live2, ...)? </blockquote><div><br></div><div>We do.</div><div>The example is a bit contrived, the real example has a phi in the way of computing the ge offset, and SimplifyCmpInst does walking and matching, so this won't work anyway.</div><div><br></div><div>See computePointerICmp:<br></div><br><div><div> Constant *LHSOffset = stripAndComputeConstantOffsets(DL, LHS);</div><div> Constant *RHSOffset = stripAndComputeConstantOffsets(DL, RHS);</div></div><div><br></div><div>This in turn walks and collects the offsets. One of those is a phi we know to be equivalent to a constant ...</div><div> <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"> Or are you expecting SimplifyCmpInst(pred, live, dead, ...) to call back into GVN to find values equivalent to "dead"?<br></blockquote><div><br></div><div>The top level call we already get right.</div><div>But all of these simplifiers do not just do top level things. They go looking, so we need them to call back in in some cases.</div><div> <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span class="gmail-">
<br>
The upshot is that it takes two passes of newgvn to get the same result as gvn.<br>
<br>
I'm trying to decide what to about this case. As i said, it happens a lot.<br>
<br>
It would be pretty trivial to make a "VNImpl" interface that has a few functions (that can be fulfilled by any value numbering that is an analysis), have newgvn implement it, and use it in Simplify*.<br>
<br>
(It would take work to make GVN work here because of how many places it modifies the ir during value numbering. It also modifies as it goes, so the only advantage would be from unreachable blocks it discovers)<br>
<br>
But before i add another argument to functions taking a ton already[1], i wanted to ask whether anyone had any opinion on whether it's worth doing.<br>
<br>
VNImpl would probably look something like:<br>
class VNImpl{<br>
// return true if A and B are equivalent<br>
bool areEquivalent(Value *A, Value *B);<br>
// find a value that dominates A that is equivalent to it<br>
Value *findDominatingEquivalent(Valu<wbr>e *A);<br></span>
// obviousn<br>
bool isBlockReachable(BasicBock *BB);<br>
}<br>
</blockquote>
<br>
I'm not sure how you expect InstructionSimplify to use findDominatingEquivalent. </blockquote><div><br></div><div>Most places it uses strict equality and doesn't care, and we would use areEquivalent.</div><div>But it does expect the end result to dominate the original instruction, and this is guaranteed by the docs :P.</div><div>We could give up on these, or we could actually just use it at the end.<br></div><div>Any instruction that it returns we could just find the equivalent that dominates the original operand, or return null.</div><div>There is precisely one call it actually tests and uses domination (that i see, it's valuedominatesphi), the rest do not.</div><div>It is easy to assert there.</div><div><br></div><div><br></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Does it have to call findDominatingEquivalent every time it tries to match() on a Value (or otherwise examine it)? </blockquote><div><br></div><div>Only in places that go walking to other things. We also could make the call "findEquivalentOperand" if we don't care about dominance</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"> That seems extremely invasive in the sense that there would be a lot of places to change, </blockquote><div><br></div><div>Err, if the concern is match, we would just make a value equivalent matcher that used vn and just use that?<br> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">and no good way to make sure we actually caught all the places which need to be changed.</blockquote><div> </div><div>I'm not sure why you think this, we can, except for the single case of dominanting equivalents which are harder.</div><div><br></div><div>For things that just want a single unique equivalent operand, newgvn has a leader it can hand you. It usually, but does not always, dominate (and we could change that). For any equivalent operand it will hand you the same leader.</div><div><br></div><div><br></div><div><br></div></div></div></div>