Do not spill UNDEF GC values. Instead, replace corresponding
gc.relocate intrinsic with an (arbitrary, but recognizable) constant.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
llvm/include/llvm/CodeGen/GCStrategy.h | ||
---|---|---|
77 ↗ | (On Diff #266827) | Should this be spelled NeedsSafePoints (needs vs. needed) ? |
The alternative here is not "do we relocate undef". It's do we let the backend chose arbitrary values for an undef operand. Said more strongly, the compiler is allowed to pick any value it wants for undef, and setting it to an arbitrary constant seems fine from a legality perspective.
There's a potential *performance* implication of choosing a particular poison pattern instead of letting it be whatever value happened to last be in a register, but given an undef appearing in the relocation list strongly indicates the value either isn't used or we're in dead code, I don't think this really matters. Particular since instcombine explicitly removes such gc.relocates.
(I tried to prototype the "better codegen" option here and promptly got crashes in the backend. These aren't worth investigating. Picking a constant is clearly better than spilling so let's just take the incremental step forward.)
Please update the patch to make this behaviour unconditional. We can be fancier if we ever see a perf impact here.
Updated patch to handle UNDEF unconditionally.
By the way, I was following this comment in InstCombineCalls.cpp:
// Undef is undef, even after relocation. // TODO: provide a hook for this in GCStrategy. This is clearly legal for // most practical collectors, but there was discussion in the review thread // about whether it was legal for all possible collectors.
Is it not relevant anymore?
LGTM w/required changes applied before commit. If you disagree on any point, further review needed and LGTM does not apply.
Also, make sure you update your commit message before landing. The current description is out of sync with the patch.
llvm/lib/CodeGen/SelectionDAG/StatepointLowering.cpp | ||
---|---|---|
232 | Use Incomng.isUndef(), add to list in following return since the comment applies as well. | |
394 | Please remove the assert by folding it into an additional clause in the condition. e.g. if (Incoming is undef and <= 64 bits) Do the same below. Vector undefs are legal and shouldn't crash. | |
398 | Add to comment. (This is legal since the compiler is always allowed to chose an arbitrary value for undef.) | |
1018 | Use SD.isUndef | |
1022 | After removing the assert, replace comment with: |
Use Incomng.isUndef(), add to list in following return since the comment applies as well.