[RISCV] Enhance RISCVMoveMerger for GPRPair Moves on RV32
Our calling convention handling splits 64-bit values into two 32-bit values, before assigning them to a pair of registers (potentially not a GPRPair). Register coalescing looks through COPYs and can end up splitting a COPY of GPRPairs into two COPYs of the GPR sub-regs.
This means there's quite a few places in our tests where we end up with:
mv a0, xN
mv a1, x(N+1)
With either Zdinx (fmv.d) or P (padd.dw), we could transform this to a single instruction that moves both registers at once. We already have a pass to do this for Zcmp (and Xqccmp) -- the RISC-V Move Merger -- but only for cm.mva01s and cm.mvsa01, which have other restrictions the two registers being moved.
(This approach means we don't change how registers are allocated/coalesced, which should mean we can still end up with two mvs when the register allocator tells us it's better the registers aren't allocated into an even-odd pair. We don't want to over-constrain allocation.)
@llvm/issue-subscribers-backend-risc-v
Author: Sam Elliott (lenary)
This means there's quite a few places in our tests where we end up with:
mv a0, xN
mv a1, x(N+1)
With either Zdinx (fmv.d) or P (addd), we could transform this to a single instruction that moves both registers at once. We already have a pass to do this for Zcmp (and Xqccmp) -- the RISC-V Move Merger -- but only for cm.mva01s and cm.mvsa01, which have other restrictions the two registers being moved.
(This approach means we don't change how registers are allocated/coalesced, which should mean we can still end up with two mvs when the register allocator tells us it's better the registers aren't allocated into an even-odd pair. We don't want to over-constrain allocation.)
There are some notes about this in https://github.com/llvm/llvm-project/pull/180671#issuecomment-3875188873
Hey, is it alright if I try taking a stab at this if you haven't started on it yet?
I haven't started on it at all 😄 I filed this in case anyone else wanted to work on it. When you have a PR, tag me in reviews. If you have questions before that I can answer them here.
Quick question, I noticed that the following code sets the kill to false if another instruction inbetween the original mv instruction's iterator I to Paired reads the register.
for (auto It = std::next(I); It != Paired && PairedSource.isKill(); ++It)
if (It->readsRegister(PairedSource.getReg(), TRI))
PairedSource.setIsKill(false);
Why is this only done for MoveFromSToA (and not when moving A to S)?
I'm assuming that fmv.d/add would need the kill analysis regardless of MoveFromSToA?
Quick question, I noticed that the following code sets the kill to false if another instruction inbetween the original mv instruction's iterator
ItoPairedreads the register.for (auto It = std::next(I); It != Paired && PairedSource.isKill(); ++It) if (It->readsRegister(PairedSource.getReg(), TRI)) PairedSource.setIsKill(false);Why is this only done for
MoveFromSToA(and not when moving A to S)?I'm assuming that fmv.d/add would need the kill analysis regardless of
MoveFromSToA?
I think it's because the A registers on MoveFromAToS are represented by implicit use operands and don't have a place to put the copied kill flag.
Ah, that makes sense. Thanks!
Reopening because I think there improvements that can be made. See the post-commit comments I left on #182416
I think this is now closed by https://github.com/llvm/llvm-project/pull/183657