[llvm] [MachineCP] Correctly handle register masks and sub-registers (PR #122472)

Oliver Stannard via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 13 06:26:20 PST 2025


ostannard wrote:

> To avoid checking all regunits, is there anything we can do in findAvailCopy?

I'm not sure what could be done there, can you elaborate?

My current ideas are to reduce the number of register units we need to check by iterating over the keys of either `MaybeDeadCopies` or `CopyTracker::Copies`, and memoising the construction of the `SafeRegUnits` bitset.

> Can you also illustrate what happens leading to the miscompilation?

The first commit inside this PR adds an MIR test which shows the bug happening. What's happening is that there is a copy to a Q register, followed by a copy to the overlapping D register. Then there is a function call, which preserves the D register, but not the top half of the overlapping Q register. The D register is used after the call, but machine copy propagation was removing both of those copies from the CopyTracker, not just the Q register one, so it though that the D register copy was dead too.

I also have a C reproducer (fuzzer-generated, using lots of vector intrinsics), but it's hundreds of lines long and I haven't been able to reduce it any further.

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


More information about the llvm-commits mailing list