<html><body><p>Let me clarify this a little<br><br><i>1- As for (2) I don't think there will be a significant compile time cost. If we do not reduce the phi to its unique incoming value, we will end up in aliasPHI and we do this check there. It is just too late for some cases like the problem here, and we get conservative result. Do I miss something here?</i><br><br>Daniel, quoted chandler that there are plenty of program with large # of phis with identical incoming values. The compile time increase due to that code pattern should be small. There might be compile time increase for other reasons (but I don't know right now).<br><br><br><img width="16" height="16" src="cid:1__=8FBBF562DF834BE08f9e8a93df938690918c8FB@" border="0" alt="Inactive hide details for Ehsan A Amiri---07/14/2016 10:49:14 PM---I can measure compile time impact of (2) and (3) on power. A"><font color="#424282">Ehsan A Amiri---07/14/2016 10:49:14 PM---I can measure compile time impact of (2) and (3) on power. A couple of questions/remarks. 1- As for</font><br><br><font size="2" color="#5F5F5F">From:        </font><font size="2">Ehsan A Amiri/Toronto/IBM</font><br><font size="2" color="#5F5F5F">To:        </font><font size="2">Hal Finkel <hfinkel@anl.gov></font><br><font size="2" color="#5F5F5F">Cc:        </font><font size="2">Daniel Berlin <dberlin@dberlin.org>, llvm-commits <llvm-commits@lists.llvm.org>, reviews+D22305+public+92ca108e50bc4651@reviews.llvm.org</font><br><font size="2" color="#5F5F5F">Date:        </font><font size="2">07/14/2016 10:49 PM</font><br><font size="2" color="#5F5F5F">Subject:        </font><font size="2">Re: [PATCH] D22305: [BasicAA] Strip phi nodes, when all incoming values are the same.</font><br><hr width="100%" size="2" align="left" noshade style="color:#8091A5; "><br><br>I can measure compile time impact of (2) and (3) on power. A couple of questions/remarks.<br><br>1- As for (2) I don't think there will be a significant compile time cost. If we do not reduce the phi to its unique incoming value, we will end up in aliasPHI and we do this check there. It is just too late for some cases like the problem here, and we get conservative result. Do I miss something here?<br><br>2- I will use Daniel's patch for (3). Depending on how expensive it is, we can look at finer grain cache clean ups, as Hal suggests.<br><br>3- I will modify my patch for (2) and modify stripPointerCasts to include "seeing through phi". I wanted to separate that move as a next step, but Hal disagreed on the code review. <br><br>If you disagree with this way of doing the experiments, please let me know.<br><br>Thanks<br>Ehsan<br><br><br><img width="16" height="16" src="cid:1__=8FBBF562DF834BE08f9e8a93df938690918c8FB@" border="0" alt="Inactive hide details for Hal Finkel ---07/14/2016 09:35:07 PM-------- Original Message ----- > From: "Daniel Berlin" <dberlin@"><font color="#424282">Hal Finkel ---07/14/2016 09:35:07 PM-------- Original Message ----- > From: "Daniel Berlin" <dberlin@dberlin.org></font><br><br><font size="2" color="#5F5F5F">From:        </font><font size="2">Hal Finkel <hfinkel@anl.gov></font><br><font size="2" color="#5F5F5F">To:        </font><font size="2">Daniel Berlin <dberlin@dberlin.org></font><br><font size="2" color="#5F5F5F">Cc:        </font><font size="2">llvm-commits <llvm-commits@lists.llvm.org>, <reviews+D22305+public+92ca108e50bc4651@reviews.llvm.org>, Ehsan A Amiri/Toronto/IBM@IBMCA</font><br><font size="2" color="#5F5F5F">Date:        </font><font size="2">07/14/2016 09:35 PM</font><br><font size="2" color="#5F5F5F">Subject:        </font><font size="2">Re: [PATCH] D22305: [BasicAA] Strip phi nodes, when all incoming values are the same.</font><br><hr width="100%" size="2" align="left" noshade style="color:#8091A5; "><br><br><br><font face="Arial"><br></font><hr width="100%" size="2" align="left" id="zwchr"><br><b><font size="4" face="Arial">From: </font></b><font size="4" face="Arial">"Daniel Berlin" <dberlin@dberlin.org></font><b><font size="4" face="Arial"><br>To: </font></b><font size="4" face="Arial">"Hal Finkel" <hfinkel@anl.gov></font><b><font size="4" face="Arial"><br>Cc: </font></b><font size="4" face="Arial">"llvm-commits" <llvm-commits@lists.llvm.org>, reviews+D22305+public+92ca108e50bc4651@reviews.llvm.org, "Ehsan A Amiri" <amehsan@ca.ibm.com></font><b><font size="4" face="Arial"><br>Sent: </font></b><font size="4" face="Arial">Thursday, July 14, 2016 8:30:09 PM</font><b><font size="4" face="Arial"><br>Subject: </font></b><font size="4" face="Arial">Re: [PATCH] D22305: [BasicAA] Strip phi nodes, when all incoming values are the same.<br></font><ul><font face="Arial"><br>(2) is, in theory, the right thing to do. Even if we were to consider uniform PHIs to be anti-canonical, and thus something which should be simplified, we can't simplify often enough to prevent these from blocking useful analysis work. </font></ul><br><font size="4" face="Arial">FWIW, i'm fine with this approach if our approach is going to be as you say - that we will not simplify often enough.</font><br><br><font size="4" face="Arial">Right now, as i said, we simplify *everywhere*, and every one of those calls will eliminate this phi node.</font><br><br><font size="4" face="Arial">So it's only *this particular path* that misses all those calls.</font><br><br><font size="4" face="Arial">For example, if the alias check had gone through a gep of a phi anywhere, it would simplify the phi as part of getunderlyingobject, etc.</font><br><font size="4" face="Arial"> </font><ul><font face="Arial">Arbitrary uses of RAUW can create these PHIs, and we can't (and probably shouldn't) run InstCombine in between every other pass. This is a local pattern that stripPointerCasts, and similar functions, can look through.</font></ul><br><font size="4" face="Arial">Fine with this as long as we maybe stop trying to simplify instructions 8 or 9 times, and instead do it once (max) per instructions, and make this part of it.</font><br><br><font size="4" face="Arial">(IE This would mean we would have SimplifyAndGetUnderlyingObject and GetUnderlyingObject, and we simplify once and call the latter or something, or whatever. Not suggesting we decide this second, just suggesting that we agree if this is going to be our general approach).</font><br><font face="Arial">This is hard because we don't cache the simplifications in any way. It is not like we're updating the IR when we discover some simplification; we're only using the simplified version in place. I'm not sure how to fix this. Maybe we should run InstSimplify a lot more often. It is not as expensive was InstCombine by a large margin (IIRC).</font><br><font size="4" face="Arial"> </font><ul><font face="Arial"><br>(3) is also, in theory, the right thing to do. The memdep cache, by necessity, caches negative results. Each GVN iteration, however, performs "information revealing" operations which can make the cached results more conservative than a new query's results.</font></ul><br><font size="4" face="Arial">Yes.</font><br><font size="4" face="Arial">It's theoretically possible to make it less expensive than blowing away the whole cache, but so far, experience has told me that fully maintaining the cache becomes slower than redoing the queries :P</font><br><font face="Arial">I'm not sure how much this helps, but we could/should only clear out the MayAlias results.<br><br> -Hal</font><br><font size="4" face="Arial"> </font><ul><font face="Arial"><br>Now we actually need to measure the costs.<br><br> -Hal</font><br><br><br><font size="4" face="Arial">(Note: i've attached a patch for 3 in case anyone wants to see the compile time cost)</font><br><br><br><br><br><br><br><br><font size="4" face="Arial">On Thu, Jul 14, 2016 at 2:12 PM, Daniel Berlin <</font><a href="mailto:dberlin@dberlin.org" target="_blank"><u><font size="4" color="#0000FF" face="Arial">dberlin@dberlin.org</font></u></a><font size="4" face="Arial">> wrote:</font><br><font size="4" face="Arial">Note: This already had GVN run once on it, do you have the one before that?<br></font><br><br><font size="4" face="Arial">On Thu, Jul 14, 2016 at 1:53 PM, Ehsan A Amiri <</font><a href="mailto:amehsan@ca.ibm.com" target="_blank"><u><font size="4" color="#0000FF" face="Arial">amehsan@ca.ibm.com</font></u></a><font size="4" face="Arial">> wrote:</font><ul><font size="4" face="Arial">I can see the problem with the following command line and attached file <br><br>opt -gvn t.ll<br></font><i><font size="4" face="Arial"><br>(See attached file: t.ll)</font></i><font size="4" face="Arial"><br><br>My clang is almost a week old.<br><br></font><img src="cid:1__=8FBBF562DF834BE08f9e8a93df938690918c8FB@" width="16" height="16" alt="Inactive hide details for Daniel Berlin ---07/14/2016 04:27:43 PM---Actually, can you please attach a .ll file and an opt comma"><font size="4" color="#424282" face="Arial">Daniel Berlin ---07/14/2016 04:27:43 PM---Actually, can you please attach a .ll file and an opt command line that reproduces the problem?</font><font size="4" face="Arial"><br></font><font color="#5F5F5F" face="Arial"><br>From: </font><font face="Arial">Daniel Berlin <</font><a href="mailto:dberlin@dberlin.org" target="_blank"><u><font color="#0000FF" face="Arial">dberlin@dberlin.org</font></u></a><font face="Arial">></font><font color="#5F5F5F" face="Arial"><br>To: </font><font face="Arial">Ehsan A Amiri/Toronto/IBM@IBMCA</font><font color="#5F5F5F" face="Arial"><br>Cc: </font><font face="Arial">Hal Finkel <</font><a href="mailto:hfinkel@anl.gov" target="_blank"><u><font color="#0000FF" face="Arial">hfinkel@anl.gov</font></u></a><font face="Arial">>, llvm-commits <</font><a href="mailto:llvm-commits@lists.llvm.org" target="_blank"><u><font color="#0000FF" face="Arial">llvm-commits@lists.llvm.org</font></u></a><font face="Arial">>, </font><a href="mailto:reviews%2BD22305%2Bpublic%2B92ca108e50bc4651@reviews.llvm.org" target="_blank"><u><font color="#0000FF" face="Arial">reviews+D22305+public+92ca108e50bc4651@reviews.llvm.org</font></u></a><font color="#5F5F5F" face="Arial"><br>Date: </font><font face="Arial">07/14/2016 04:27 PM</font><font color="#5F5F5F" face="Arial"><br>Subject: </font><font face="Arial">Re: [PATCH] D22305: [BasicAA] Strip phi nodes, when all incoming values are the same.</font><br><hr width="100%" size="2" align="left" noshade style="color:#000000; "><font size="4" face="Arial"><br><br></font><br><font size="5" face="Arial">Actually, can you please attach a .ll file and an opt command line that reproduces the problem?<br>The clang command line you have is very sensitive to versions, etc.</font><font size="4" face="Arial"><br></font><font size="5" face="Arial"><br>I cannot get your issue to reproduce with the clang i have installed that can target powerpc-linux (and the issue does not reproduce with your testcase on x86) :)</font><font size="4" face="Arial"><br></font><font size="5" face="Arial"><br>While debugging a bit, note that there is at least one obvious bug in GVN that may affect this, by inspection:</font><font size="4" face="Arial"><br></font><font size="5" face="Arial"><br>When GVN splits a critical edge, it never adds the new block to the iteration order (at all), even though it inserts into it.<br>So they will not get processed until the next iteration of GVN on the function, even though they have code in them.  While this is okay from a correctness standpoint, it may block optimization of certain things (including the cases you've discovered).  In practice, there is no way to perfectly solve that without pre-splitting all critical edges, but you should get the same effect if we throw the critical edge block and then it's successors (including the current blcok) into bbvect after the current block again.</font><font size="4" face="Arial"><br></font><font size="5" face="Arial"><br>It is also missing a real phi simplification.<br>While simplifyinstruction will check if all arguments are trivially the same, that is not the real test that should be performed.</font><font size="4" face="Arial"><br></font><font size="5" face="Arial"><br>It should be doing VN.lookup on each argument and seeing if they come up with the the same value number.</font><font size="4" face="Arial"><br></font><font size="5" face="Arial"><br>Once you attach the .ll file, i'll fix these and see if it fixes your testcase, and if not, debug further.</font><font size="4" face="Arial"><br><br></font><font size="5" face="Arial"><br>On Thu, Jul 14, 2016 at 10:11 AM, Daniel Berlin <</font><a href="mailto:dberlin@dberlin.org" target="_blank"><u><font size="5" color="#0000FF" face="Arial">dberlin@dberlin.org</font></u></a><font size="5" face="Arial">> wrote:</font><ul><ul><font size="4" face="Arial"><br></font><font size="5" face="Arial"><br>On Thu, Jul 14, 2016 at 7:09 AM, Ehsan A Amiri <</font><a href="mailto:amehsan@ca.ibm.com" target="_blank"><u><font size="5" color="#0000FF" face="Arial">amehsan@ca.ibm.com</font></u></a><font size="5" face="Arial">> wrote:<br>This is order of events:</font><br><font size="5" face="Arial">This order cannot be correct if the solution I gave (or adding simplification to *some place in GVN*) does not work.  Or GVN is broken in other ways.<br> <br>1) GVN starts looking at the function. At this point the phi node has two different incoming values.<br>2) GVN performs an RAUW. The phi is converted to the one that has two identincal incoming values. </font><br><font size="5" face="Arial"><br>At this point, it should now process the phi instruction again before it processes the load, because it is doing a reverse postorder traversal.<br>When it did that, the phi should have been simplified<br>So why did that not happen?</font><font size="4" face="Arial"><br></font><font size="5" face="Arial"><br>Given the complexity of fixing the real problem,</font><br><font size="5" face="Arial"><br>Look, i understand why you want to just fix this in AA and be done with it.<br>Really, I do. </font><font size="4" face="Arial"><br></font><font size="5" face="Arial"><br>I understand you have spent a lot of time on this bug, and I greatly appreciate that.<br>But I really want to understand what is going on before we try to actually fix it.<br>I have a good understanding of what happens once the bad answer gets into memdep (and thank you for that!), but i still have trouble seeing why it lived long enough to get there.</font><font size="4" face="Arial"><br></font><font size="5" face="Arial"><br>To that end, so you don't have to spend more time running around for me,  i'll take over this bug, and either figure out why GVN lets this PHI live to the point it gets an AA query about it (and fix it/decide it can't be fixed), or commit the AA patch for you if we decide it can't be fixed.</font><font size="4" face="Arial"><br></font><font size="5" face="Arial"><br>My ETA is by friday.</font><font size="4" face="Arial"><br></font><font size="5" face="Arial"><br>I assume the testcase in the bug is the one we are still using, right?<br>(If not, if you can attach it, that would be helpful)</font><font size="4" face="Arial"><br></font></ul></ul><font size="4" face="Arial"><br></font></ul><br><br><br><font face="Arial"><br><br></font><br><font color="#888888" face="Arial">-- </font><br><font color="#888888" face="Arial">Hal Finkel<br>Assistant Computational Scientist<br>Leadership Computing Facility<br>Argonne National Laboratory</font></ul><br><font face="Arial"><br><br><br>-- </font><br><font face="Arial">Hal Finkel<br>Assistant Computational Scientist<br>Leadership Computing Facility<br>Argonne National Laboratory</font><br>[attachment "graycol.gif" deleted by Ehsan A Amiri/Toronto/IBM] <br><BR>
</body></html>