This is an archive of the discontinued LLVM Phabricator instance.

[RS4GC] Rematerialize derived pointers before uses.
ClosedPublic

Authored by dantrushin on Nov 29 2022, 4:38 AM.

Details

Summary

Introduce an option to rematerialize derived pointers immediately
before their uses instead of after every statepoint. This can be
beneficial when pointer is live across many statepoints but has
few uses.
Initial implementation is simple and rematerializes derived pointer
before every use, even if there are several uses in the same block
or rematerialization instructions can be hoisted etc.
Transformation is considered profitable if we would insert less
instructions than we would insert after every live statepoint.

Depends on D138910, D138911

Diff Detail

Event Timeline

dantrushin created this revision.Nov 29 2022, 4:38 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 29 2022, 4:38 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
dantrushin requested review of this revision.Nov 29 2022, 4:38 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 29 2022, 4:38 AM

Rebase on tip after D138910 has been landed.

LGTM, please wait a bit for someone else to look at.

llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
2473

Move above as to exit earlier?

2504

looks profitable

2511

!empty()?

dantrushin marked an inline comment as done.Dec 13 2022, 2:27 AM
dantrushin added inline comments.
llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
2511

Nope.More than one - i.e., it has a sub-chain which could have changed.
If chain length is 1 we cannot spoil it.

skatkov added inline comments.Dec 13 2022, 2:29 AM
llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
2511

Right

dantrushin marked an inline comment as done.

Address review comments.
Also include changes for pre-committed tests

Still lgtm. Please wait one or two days for other possible reviews.

dantrushin marked 3 inline comments as done.Dec 15 2022, 9:21 AM
anna added inline comments.Dec 20 2022, 1:35 PM
llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
2442

Nit: beneficial

2517

So, these remats will be present till the end right? Seems suboptimal (in terms of compile time) especially if we have multiple uses within a single BB.

2518

Nit: or if

Address review comments (fix typos).

dantrushin marked 2 inline comments as done.Dec 21 2022, 3:42 AM
dantrushin added inline comments.
llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
2517

I left it as a follow up improvement because implementing it will complicate implementation.
There may be several statepoints intermixed with uses in the same block. Handling of this is not so trivial. I think we will need some refactoring
and this initial implementation would be motivating case for it :-)

Regarding compile time:

  1. Duplicating chains will be optimized away by LocalCSE (hopefully).
  2. Profitability heuristic accounts for every such copy and we guaranteed to have not more copies that we would have if we rematerialized after every statepoint.
  3. As a job security, this would be opportunity for possible compile time improvement project (just kidding)
anna added a comment.Dec 22 2022, 6:52 AM
This comment was removed by anna.
anna accepted this revision.Dec 22 2022, 6:52 AM

okay LGTM then.

This revision is now accepted and ready to land.Dec 22 2022, 6:52 AM
This revision was landed with ongoing or failed builds.Dec 27 2022, 6:09 AM
This revision was automatically updated to reflect the committed changes.