<div dir="ltr"><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><br><div class="gmail_quote"><div dir="ltr">On Wed, May 9, 2018 at 8:24 PM Daniel Berlin <<a href="mailto:dberlin@dberlin.org">dberlin@dberlin.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Wed, May 9, 2018 at 10:39 AM, Hiroshi Yamauchi <span dir="ltr"><<a href="mailto:yamauchi@google.com" target="_blank">yamauchi@google.com</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"><div dir="ltr"><div style="font-family:arial,helvetica,sans-serif"><br></div><br><div class="gmail_quote"><span class="gmail-m_8307257963026143428gmail-"><div dir="ltr">On Tue, May 8, 2018 at 11:15 AM Daniel Berlin <<a href="mailto:dberlin@dberlin.org" target="_blank">dberlin@dberlin.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, May 8, 2018 at 10:38 AM, Hiroshi Yamauchi via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.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"><div dir="ltr">(<div style="color:rgb(34,34,34);font-size:13px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration-style:initial;text-decoration-color:initial;font-family:arial,helvetica,sans-serif;display:inline">​I came across this issue in the context of</div><span style="color:rgb(34,34,34);font-family:sans-serif;font-size:13px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"> </span><a href="https://reviews.llvm.org/D46336" style="color:rgb(17,85,204);font-family:sans-serif;font-size:13px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" target="_blank">D46336</a><span style="color:rgb(34,34,34);font-family:sans-serif;font-size:13px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">.</span><div style="font-family:arial,helvetica,sans-serif;display:inline">​ ​</div>Thanks, Sanjay, for starting this discussion.)<br><div><br></div><div>If <div style="font-family:arial,helvetica,sans-serif;display:inline">​we will</div> move <span style="color:rgb(34,34,34);font-family:sans-serif;font-size:13px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><div style="font-family:arial,helvetica,sans-serif;display:inline">​reassociation, </div></span>or keep additional ones<div style="font-family:arial,helvetica,sans-serif;display:inline">​,​</div> out of instcombine, <div style="font-family:arial,helvetica,sans-serif;display:inline">​open questions for me would be</div><div style="font-family:arial,helvetica,sans-serif;display:inline">​​:</div><br><br>1. Since -reassociate isn't a fixed point pass,</div></div></blockquote><div><br></div><div>This is fixable, fwiw, without fixpointing it.</div></div></div></div></blockquote><div><br></div></span><div><div style="font-family:arial,helvetica,sans-serif">How?</div></div></div></div></blockquote><div><br></div><div>Depends on specifically which part you would like to know about ;)</div></div></div></div></blockquote><div><br></div><div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">​Maybe I misunderstood what you meant by "This is fixable". Did you mean that we won't somehow need to fixpoint between instcombine and reassociate, or that <span style="color:rgb(34,34,34);font-family:arial,helvetica,sans-serif;font-size:13px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">the specific motivating examples from the above differentials are foldable without fixpointing?</span></div></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><span style="color:rgb(34,34,34);font-family:arial,helvetica,sans-serif;font-size:13px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">If the latter, that may be the case. The concern was that we may encounter examples that may need many more iterations, if not fixpointing. As long as it's feasible to fixpoint between <span style="color:rgb(34,34,34);font-family:arial,helvetica,sans-serif;font-size:13px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">instcombine and reassociate, it seems to work, but I guess that would <span style="color:rgb(34,34,34);font-family:arial,helvetica,sans-serif;font-size:13px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">probably </span>need some pass management change.</span></span></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"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><span class="gmail-m_8307257963026143428gmail-"><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"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div> we might need to repeat "-instcombine -reassociate" multiple times to <div style="font-family:arial,helvetica,sans-serif;display:inline">​fold</div> down to what we want (relating to <a href="https://reviews.llvm.org/D46336#1087082" target="_blank">my comment here</a>). I assumed this isn't not what we want to do<div style="font-family:arial,helvetica,sans-serif;display:inline">​? My impression is we don't do a fixed-point with passes?</div></div></div></blockquote><div><br></div><div>Well, i mean there is no practical difference between passes that we fixpoint externally and fixpoint internally.</div></div></div></div></blockquote></span><div><div style="font-family:arial,helvetica,sans-serif">​​</div><div style="font-family:arial,helvetica,sans-serif"><span style="color:rgb(34,34,34);font-family:arial,helvetica,sans-serif;font-size:13px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">I had the following in mind: Does the pass manager support fixpointing externally? Is there any performance difference? Are people okay with that in general?</span></div><div style="font-family:arial,helvetica,sans-serif"><br></div><div style="font-family:arial,helvetica,sans-serif">But if <span style="font-family:sans-serif">there is no practical difference</span>, I don't see any problem with that :)</div></div><span class="gmail-m_8307257963026143428gmail-"><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"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><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"><div dir="ltr"><div> <br></div></div></blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>2. <div style="font-family:arial,helvetica,sans-serif;display:inline">​Since -<span style="color:rgb(34,34,34);font-family:sans-serif;font-size:13px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">reassociate needs to come up with one operand order (at least currently as the only <span style="color:rgb(34,34,34);font-family:sans-serif;font-size:13px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">reassociate </span>pass), would there exist a single, unique operand order that would enable all <span style="color:rgb(34,34,34);font-family:arial,helvetica,sans-serif;font-size:13px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><span style="color:rgb(34,34,34);font-family:sans-serif;font-size:13px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">reassociative/commutative</span> foldings that we want? </span></span></div></div></div></blockquote><div><br></div><div>In what way?</div><div>Are you asking whether there is a single reassociation order that makes all foldings occur in the same operation or something?<br>I don't feel like i understand what you are asking.<br></div></div></div></div></blockquote><div><br></div></span><div><div><span style="font-family:arial,helvetica,sans-serif">Does this rephrase help: with the motivating examples (like and-of-shifts or bit check patterns) from the above differentials in mind, can we come up with a single <span style="color:rgb(34,34,34);font-family:sans-serif;font-size:13px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">reassociation order that solves all those and all the others that may come up in the future? Would we need different <span style="color:rgb(34,34,34);font-family:sans-serif;font-size:13px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">reassociation orders to fold different patterns?</span></span></span></div></div><span class="gmail-m_8307257963026143428gmail-"><div></div></span></div></div></blockquote><div><br></div><div>It doesn't quite help.</div><div>When stated that generally, there can be no such ordering at all, that's easy to prove.  It is a statically undecidable problem.</div><div><br></div><div>There is however, a different question and answer to a few related problems that maybe you are really asking?<br>1. Is there a way to determine and apply the a maximal or nearly-maximal set of folds/graph transforms that could be applied to a given set of code in a sane and principled way -> yes</div><div><br></div><div>(see, e.g., <a href="http://www.cs.cornell.edu/~ross/publications/eqsat/" target="_blank">http://www.cs.cornell.edu/~ross/publications/eqsat/</a>)</div><div><br></div><div>2. Is there a way to determine all expressions in the program as it exists that are equivalent or equivalent under constant time constant folding/reassociation, in a reasonable time bound -> yes</div><div><br></div><div>(not a single easy link, happy to talk about it)</div><div><br></div><div>Your original question is basically equivalent to</div><div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial">Is there a way to determine all expressions in the program as it exists that are equivalent or could be made equivalent through any type of folding that one can think up?</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial">The answer to that is "no", it's provable that this is not statically decidable, so the time bound doesn't matter :)</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial"><br></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial">You have to limit the possible folding/evaluation you apply in various ways to make this decidable, and then further limit it to make the time bound reasonable.</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial"><br></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial">This all quickly devolves into herbrand equivalence and it's variations.</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial"><br></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial"><br></div></div></div></div></div></blockquote><div><span style="font-family:arial,helvetica,sans-serif">​</span></div><div><div class="gmail_default"><font face="arial, helvetica, sans-serif">Let me try one more time :) </font><span style="font-family:arial,helvetica,sans-serif">May we need multiple reassociate passes to fold different </span><span style="font-family:arial,helvetica,sans-serif">reassociative patterns?</span></div><div class="gmail_default"><font face="arial, helvetica, sans-serif"><br></font></div><div class="gmail_default"><font face="arial, helvetica, sans-serif">A longer version: If Sanjay wants a particular reassociative pattern to be folded (D45842), Omer wants another particular </font><span style="font-family:arial,helvetica,sans-serif">reassociative <span style="color:rgb(34,34,34);font-family:arial,helvetica,sans-serif;font-size:13px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">pattern</span> to be folded (</span><font face="arial, helvetica, sans-serif">D41574)</font><span style="font-family:arial,helvetica,sans-serif">, and I want yet another </span><font face="arial, helvetica, sans-serif">​</font><span style="font-family:arial,helvetica,sans-serif">particular </span><span style="font-family:arial,helvetica,sans-serif">reassociative <span style="color:rgb(34,34,34);font-family:arial,helvetica,sans-serif;font-size:13px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">pattern</span> to be folded (</span><font face="arial, helvetica, sans-serif">D46336)</font><span style="font-family:arial,helvetica,sans-serif">, would we potentially need three different reassociate passes with each combined with instcombine, rather than just one that may be able to <span style="color:rgb(34,34,34);font-family:arial,helvetica,sans-serif;font-size:13px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">somehow </span>handle those cases in one shot, (assuming we don't want to put those in instcombine)?</span></div><div class="gmail_default"><span style="font-family:arial,helvetica,sans-serif"><br></span></div><div class="gmail_default"><span style="font-family:arial,helvetica,sans-serif">And it sounds like the answer is yes?</span></div></div><div><br></div><div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><br></div><div> </div></div></div>