This is an archive of the discontinued LLVM Phabricator instance.

[LICM] Fix a crash when sinking instructions w/token operands
ClosedPublic

Authored by reames on Mar 16 2021, 11:39 AM.

Details

Summary

It is not legal to form a phi node with token type. The generic LCSSA construction code handles this correctly - by not forming LCSSA for such cases - but the adhoc fixup implementation in LICM did not.

This was noticed in the context of PR49607, but can be demonstrated on ToT with the tweaked test case. This is not specific to gc.relocate btw, it also applies to usage of the preallocated family of intrinsics as well.

Diff Detail

Event Timeline

reames created this revision.Mar 16 2021, 11:39 AM
reames requested review of this revision.Mar 16 2021, 11:39 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 16 2021, 11:39 AM
reames retitled this revision from [LICM] Fix a bug involving sinking of instructions w/token operands to [LICM] Fix a crash when sinking instructions w/token operands.Mar 16 2021, 11:40 AM

It is not legal to form a phi node with token type.

Can PHINode::Create() assert that?

It is not legal to form a phi node with token type.

Can PHINode::Create() assert that?

The verifier already catches this pretty promptly. I don't really see the value in this, but also have no problem landing a separate change to add the assert if desired.

fhahn accepted this revision.Mar 16 2021, 2:52 PM

LGTM given that we already do not create LCSSA phis during regular LCSSA construction.

llvm/lib/Transforms/Scalar/LICM.cpp
1515

It might be helpful for future readers of the code if the token-type check would be separate & with a brief comment (perhaps an early continue). I'm fine either way, please feel free to disregard the comment.

This revision is now accepted and ready to land.Mar 16 2021, 2:52 PM
reames added inline comments.Mar 17 2021, 11:24 AM
llvm/lib/Transforms/Scalar/LICM.cpp
1515

I played with a couple variations, and everything I came up with was harder to read and lengthened the code a lot. I ended up slightly rewording the comments describing the actions being done and left it at that.

reames added inline comments.Mar 17 2021, 12:15 PM
llvm/lib/Transforms/Scalar/LICM.cpp
1515

Thought about this a bit further, and came up with 31764ea295. Landed it because it seemed straight forward, but let me know what you think. I can always revert if you dislike the direction.

fhahn added inline comments.Mar 17 2021, 2:00 PM
llvm/lib/Transforms/Scalar/LICM.cpp
1515

I think that's a great improvement, thanks!