[llvm-bugs] [Bug 26223] New: [GC] Effective rematerialization at non-entry polls

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Jan 20 09:51:12 PST 2016


https://llvm.org/bugs/show_bug.cgi?id=26223

            Bug ID: 26223
           Summary: [GC] Effective rematerialization at non-entry polls
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedbugs at nondot.org
          Reporter: listmail at philipreames.com
                CC: llvm-bugs at lists.llvm.org
    Classification: Unclassified

(This bug is specific to the implementation of rewrite-statepoints-for-gc.)

If we have a bit of code like this:
%addr = gep %o, 8
loop {
  if (poll) {
     safepoint();
  }
  load %addr
}

We currently end up rewriting this as:
%addr = gep %o, 8
loop {
  %addr1 = phi (%addr, %addr2)
  if (poll) {
     safepoint();
     %remat = gep %o.relocated, 8
  }
  %addr2 = phi (%addr1, %remat)
  load %addr2
}
This ends up forcing us to rematerialize the address explicitly and likely will
cause us to spill/fill the address if register constrained.  This creates a
bunch of dependent loads (fill from stack, load from result) which show up as
hot in a couple of benchmarks.  

A much better result would be:
%addr = gep %o, 8
loop {
  if (poll) {
     safepoint();   
  }
  %remat = gep %o.relocated, 8
  load %remat
}

This version allows the GEP to be folded directly into x86's native addressing
modes.  

(Note: For conciseness, I'm not writing the phis for relocating %o, assume
they're all there.)


I can see a couple of ways of approaching this:
- Rematerialize not at relocations, but at uses.  This would require either a
post rewriting CSE to clean up, or a bit of smarts to avoid naive placement. 
This might be overly x86 specific.
- Push rematerializations into unconditional successors.  This would have the
effect of eliminating PHIs (because we know the remat is also legal there).  
- Add a post processing pass which tries to pull remat values through their
only use.  This could be done as either a step in RS4GC, or possibly just an
instcombine rule.  Given a single use gep of a gc-relocate, look to see if the
single use is a phi of the original value.  If so, replace the PHI with a gep
of the PHI producing the fixed up base.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20160120/8c9955dc/attachment.html>


More information about the llvm-bugs mailing list