This is an archive of the discontinued LLVM Phabricator instance.

[StatepointLowering] Handle UNDEF gc values.
ClosedPublic

Authored by dantrushin on May 28 2020, 5:37 AM.

Details

Summary

Do not spill UNDEF GC values. Instead, replace corresponding
gc.relocate intrinsic with an (arbitrary, but recognizable) constant.

Diff Detail

Event Timeline

dantrushin created this revision.May 28 2020, 5:37 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 28 2020, 5:37 AM
dantrushin marked an inline comment as done.May 28 2020, 5:42 AM
dantrushin added inline comments.
llvm/include/llvm/CodeGen/GCStrategy.h
77 ↗(On Diff #266827)

Should this be spelled NeedsSafePoints (needs vs. needed) ?

reames added a comment.EditedMay 29 2020, 12:02 PM

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.

dantrushin updated this revision to Diff 267608.Jun 1 2020, 6:58 AM

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?

reames accepted this revision.Jun 1 2020, 10:13 AM

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:
Lowering relocate(undef) as arbitrary constant. Current constant value is chosen such that it's unlikely to be a valid pointer.

This revision is now accepted and ready to land.Jun 1 2020, 10:13 AM
dantrushin edited the summary of this revision. (Show Details)Jun 1 2020, 2:44 PM
dantrushin updated this revision to Diff 267742.Jun 1 2020, 2:45 PM
dantrushin marked 5 inline comments as done.
dantrushin edited the summary of this revision. (Show Details)

Update according to comments.

This revision was automatically updated to reflect the committed changes.