[llvm] [GlobalISel] Remove dead VRegs after instruction selection (PR #73892)

via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 12 01:14:56 PST 2023


qcolombet wrote:

> > I thought the problematic context was when registers are only referenced by debug instructions? Can we do something about those specifically instead?
> 
> The problematic context is instructions that were created and deleted during whole `GlobalISel` pipeline. Such instructions create virtual registers for themselves. Also such instructions are not selected (obviously they were replaced or deleted) and virtual registers used by these instructions don't have a `RegClass` because it is assigned during selecting MIR instruction.
> 
> Probably, the context, when registers are only referenced by debug instructions, is also actual. But I'm mostly concentrated on the context I've described above.
> 
> > If you have a register with an unset class, it was mis-selected. We shouldn't need to inspect the full set of registers, all used registers should be naturally encountered during the select process
> 
> We may have a register with an unset class and this register is not used anywhere. That's why the problem is hidden until we traverse all virtual registers and ask their `RegClass`. These registers are the problem. Should they have a `RegClass` or it is a problem of one who traverses such registers. In other words, can a dead register have an unset class immediately after instruction selection.

FWIW, the problem only arises if you try to access the regclass of an unused register. So arguably, the problem is in how these dead registers are used.
I agree that removing such footgun is good, but it shouldn't come with a high price. Most places traverse the MachineOperand so they are not exposed to this problem.

In other words, the benefit of doing this is not clear to me.

https://github.com/llvm/llvm-project/pull/73892


More information about the llvm-commits mailing list