This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] When custom iseling masked loads/stores, copy the mask into V0 instead of virtual register.
ClosedPublic

Authored by craig.topper on Mar 25 2021, 12:13 PM.

Details

Summary

This matches what we do in our isel patterns. In our internal
testing we've found this is needed to make the fast register
allocator happy at -O0. Otherwise it may assign V0 to an earlier
operand and find itself with no registers left when it reaches
the mask operand. By using V0 explicitly, the fast register allocator
will see it when it checks for phys register usages before it
starts allocating vregs. I'll try to update this with a test case.

Unfortunately, this does appear to prevent some instruction reordering
by the pre-RA scheduler which leads to the increased spills seen in
some tests. I suspect that problem could already occur for other
instructions that already used V0 directly.

There's a lot of repeated code here that could do with some
wrapper functions. Not sure if that should be at the level of the
new code that deals with V0. That would require multiple output
parameters to pass the glue, chain and register back. Maybe it
should be at a higher level over the entire set of push_backs.

Diff Detail

Event Timeline

craig.topper created this revision.Mar 25 2021, 12:13 PM
craig.topper requested review of this revision.Mar 25 2021, 12:13 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 25 2021, 12:13 PM
Herald added a subscriber: MaskRay. · View Herald Transcript

Add test that previously failed.

This revision is now accepted and ready to land.Mar 29 2021, 12:45 AM
frasercrmck accepted this revision.Mar 29 2021, 1:46 AM

LGTM too. I think helper functions would be interesting; I'd lean towards higher-level ones as you suggest. Otherwise it's a bit finicky with all the operands and returns going about the place.