This is an archive of the discontinued LLVM Phabricator instance.

[CGP] Fix the rematerialization of gc.relocates
ClosedPublic

Authored by skatkov on Aug 8 2017, 5:51 AM.

Details

Summary

If we want to substitute the relocation of derived pointer with gep of base then
we must ensure that relocation of base dominates the relocation of derived pointer.

Currently only check for basic block is present. However it is possible that both
relocation are in the same basic block but relocation of derived pointer is defined
earlier.

The patch moves the relocation of base pointer right before relocation of derived
pointer in this case.

Diff Detail

Repository
rL LLVM

Event Timeline

skatkov created this revision.Aug 8 2017, 5:51 AM
reames requested changes to this revision.Aug 14 2017, 11:12 AM
reames added inline comments.
lib/CodeGen/CodeGenPrepare.cpp
951 ↗(On Diff #110181)

Doing this linear scan of the basic block once per gc-relocate seems needless expensive compile time wise. I'd do one of the following:

  1. Canonicalize the location of the base pointer before the derived relocations, run that code once per statepoint, then visit the gc-relocates only once it has run.
  2. Reorganize the code to identify all remat candidates, then scan once for earliest required position, then materialize all including the moved base pointer.

Smaller comments:

  • Group the BB check with the scan code since they're all handling the same case.
  • Since we have to do the linear scan anyways, should we just handle the duplicate case at the same time?
956 ↗(On Diff #110181)

Rather than scanning all instructions in the block, you can start at the statepoint.

This revision now requires changes to proceed.Aug 14 2017, 11:12 AM
skatkov added inline comments.Aug 14 2017, 10:03 PM
lib/CodeGen/CodeGenPrepare.cpp
951 ↗(On Diff #110181)

It is not once per gc-relocate, it is once per RelocatedBase and all gc-relocate corresponding to RelocatedBase.

However I think I can do a bit smarter here. Specifically, I can check that the relocation I met before RelocatedBase is actually gc-relocate corresponding that base and move RelocatedBase right before this gc-relocate. So it should be faster and does not require utility map.

I will upload a new patch.

956 ↗(On Diff #110181)

I cannot start with statepoint because it might be located in a different basic block then RelocateBase.

skatkov updated this revision to Diff 111134.Aug 15 2017, 12:13 AM
skatkov edited edge metadata.
reames accepted this revision.Aug 16 2017, 10:14 AM

LGTM

This revision is now accepted and ready to land.Aug 16 2017, 10:14 AM
This revision was automatically updated to reflect the committed changes.