llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[GC] Effective rematerialization at non-entry polls

Open preames opened this issue 10 years ago • 1 comments

Bugzilla Link 26223
Resolution FIXED
Resolved on Dec 11, 2017 01:26
Version trunk
OS Linux
CC @serguei-katkov

Extended Description

(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.

preames avatar Jan 20 '16 19:01 preames

Finally implemented by: commit ef36801a148ed815d543ccf0e4ee9f75196b7d87 Author: Serguei Katkov [email protected] Date: Wed Nov 29 09:48:50 2017 +0000

[CGP] Enable complex addr mode

Enable complex addr modes after two critical fixes: rL319109 and rL319292

serguei-katkov avatar Dec 11 '17 09:12 serguei-katkov