This is an archive of the discontinued LLVM Phabricator instance.

[SelectionDAG] Don't apply MinRCSize constraint in InstrEmitter::AddRegisterOperand for IMPLICIT_DEF sources.
ClosedPublic

Authored by craig.topper on Jun 16 2022, 1:42 PM.

Details

Summary

MinRCSize is 4 and prevents constrainRegClass from changing the
register class if the new class has size less than 4.

IMPLICIT_DEF gets a unique vreg for each use and will be removed
by the ProcessImplicitDef pass before register allocation. I don't
think there is any reason to prevent constraining the virtual register
to whatever register class the use needs.

The attached test case was previously creating a copy of IMPLICIT_DEF
because vrm8nov0 has 3 registers in it.

Diff Detail

Event Timeline

craig.topper created this revision.Jun 16 2022, 1:42 PM
craig.topper requested review of this revision.Jun 16 2022, 1:42 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 16 2022, 1:42 PM
arsenm accepted this revision.Jun 16 2022, 2:13 PM

I've never understood the point of this parameter

This revision is now accepted and ready to land.Jun 16 2022, 2:13 PM

I've never understood the point of this parameter

I went digging a bit, and as best I can tell this is a heuristic to avoid putting too much pressure on register allocation for virtual regs from small register classes. The idea appears to be that using values copied into a bigger register class is likely to lead to overall better results. As a guess, I think this is a workaround for the fact that we can't spill to other register classes.

For the implicit_def case, that heuristic makes no sense. So LGTM by me too.

As a guess, I think this is a workaround for the fact that we can't spill to other register classes.

But the allocator does look for shared common superclasses to copy to before spilling, so I don't understand this

This revision was landed with ongoing or failed builds.Jun 16 2022, 2:55 PM
This revision was automatically updated to reflect the committed changes.

As a guess, I think this is a workaround for the fact that we can't spill to other register classes.

But the allocator does look for shared common superclasses to copy to before spilling, so I don't understand this

I guess this doesn't happen for fast regalloc which breaks every normal assumption

As a guess, I think this is a workaround for the fact that we can't spill to other register classes.

But the allocator does look for shared common superclasses to copy to before spilling, so I don't understand this

Huh, didn't realize we did that actually. Cool.

I guess this doesn't happen for fast regalloc which breaks every normal assumption

Sounds entirely plausible.

Which raises the question: what would be the impact of only applying this heuristic in fast regalloc? Or teaching fast reglloc how to do sub-class moves so we can avoid this?