<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Aug 24, 2016, at 1:20 PM, Wei Mi <<a href="mailto:wmi@google.com" class="">wmi@google.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="">On Wed, Aug 24, 2016 at 12:01 PM, Sanjoy Das<br class=""><<a href="mailto:sanjoy@playingwithpointers.com" class="">sanjoy@playingwithpointers.com</a>> wrote:<br class=""><blockquote type="cite" class="">Hi Wei,<br class=""><br class="">Wei Mi wrote:<br class=""><blockquote type="cite" class="">Sanjoy and Andy, thanks a lot for your suggestions.<br class=""><br class="">On Wed, Aug 24, 2016 at 8:53 AM, Andrew Trick<<a href="mailto:atrick@apple.com" class="">atrick@apple.com</a>>  wrote:<br class=""><blockquote type="cite" class=""><br class=""><blockquote type="cite" class="">On Aug 23, 2016, at 11:30 PM, Sanjoy Das<<a href="mailto:sanjoy@playingwithpointers.com" class="">sanjoy@playingwithpointers.com</a>><br class="">wrote:<br class=""><br class="">Hi Wei,<br class=""><br class="">I've not seen GCC's SCEV so I cannot make a comparative comment here<br class="">(maybe Chris, Andy or Dan can chime in here), but I personally am in<br class="">the "make the cleanup passes smarter" camp.  We can also try to make<br class="">SCEV expansion smarter -- not by putting more things in SCEVExpander<br class="">(it is already complex enough!), but by splitting out a dedicated<br class="">SCEVSimplifier that you invoke on code generated from SCEVExpander to<br class="">strength reduce it.  SCEVSimplifier can then internally use routines<br class="">in SCEV, so that it is "as smart as" SCEV in most cases.<br class=""><br class="">— Sanjoy<br class=""></blockquote></blockquote><br class="">Combine the efforts of making the cleanup passes smarter and<br class="">simplifying the expanded code to make it more IR canonical looks like<br class="">a promising way. But I may not understand SCEVSimplifier you suggested<br class="">here correctly: The input of SCEVSimplifier is IR or SCEV? The code<br class="">generated by SCEVExpander is IR. If the input of SCEVSimplifier is IR,<br class="">how does it use SCEV routine internally?<br class=""></blockquote><br class="">It accepts a ScalarEvolution instance that it uses internally to check<br class="">for equivalences, so the interface is:<br class=""><br class="">class Simplifier {<br class="">public:<br class="">  Simplifier(ScalarEvolution &SE);<br class="">  Value *simplify(Value *);<br class="">};<br class=""><br class="">or something like that.  Once we have this separation between<br class="">expansion and strength reduction, we can be more aggressive (than we<br class="">can reasonably be within SCEVExpander) about teaching Simplifier SCEV<br class="">based CSE rules.<br class=""></blockquote><br class="">To rephrase it and see if I understand it correctly:<br class=""><br class="">Existing Value A;<br class=""><br class="">Expanded Value B (B is identical with A, but in a different form);<br class=""><br class="">So we can convert both A and B to SCEV again and compare their<br class="">equivalence and use the result to guide strength reduction. It is like<br class="">to enhance existing cleanup pass using the SCEV CSE rules.<br class=""><br class="">Or the idea of simplify is to transform B back to the form close to A<br class="">with SCEV knowledge?<br class=""><br class="">It sounds like an interesting idea.<br class=""></div></div></blockquote></div><div class=""><br class=""></div>I would need to see how this solves the bugs you posted earlier, like<div class=""><a href="https://llvm.org/bugs/show_bug.cgi?id=24920" class="">https://llvm.org/bugs/show_bug.cgi?id=24920</a></div><div class=""><br class=""></div><div class="">-Andy</div></body></html>