<div dir="ltr">This might work and existing test cases should be able to make sure the behavior is not regressed.<div><br></div><div>David</div></div><br><div class="gmail_quote"><div dir="ltr">On Fri, May 18, 2018 at 5:49 PM Michael Zolotukhin via Phabricator <<a href="mailto:reviews@reviews.llvm.org">reviews@reviews.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">mzolotukhin added a comment.<br>
<br>
I thought about this transformation more, and I no longer think that we even need to move it to aggressive-instcombine (or another FunctionPass). What we need is to just change it from top-down to bottom-up: i.e. to start looking not from phi-nodes, but rather from `inttoptr` instructions. That is, the algorithm would look like:<br>
<br>
  visitIntToPtr(Instruction &I) {<br>
    Value *Def = I.getOperand()<br>
    if (!Def.hasSingleUse())<br>
       return;<br>
    if (isa<PtrToInt>(Def)) {   // Simple case without phi - it's probably already handled somewhere else, but I'm putting it here for completeness<br>
       I.replaceAllUsesWith(Def.getOperand());<br>
    }<br>
    if (isa<PHINode>(Def)) {    // Interesting case where we have a phi-node<br>
       if (all operands are PtrToInt with a single use) {<br>
         NewPHI = RewritePHI();<br>
         I.replaceAllUsesWith(NewPHI);<br>
      }<br>
    }<br>
  }<br>
<br>
What do you think? Would it work?<br>
<br>
PS: Internally we worked around the slowdown, so it's not pressing on us anymore.<br>
<br>
Michael<br>
<br>
<br>
Repository:<br>
  rL LLVM<br>
<br>
<a href="https://reviews.llvm.org/D47023" rel="noreferrer" target="_blank">https://reviews.llvm.org/D47023</a><br>
<br>
<br>
<br>
</blockquote></div>