Skip to content

Commit 3ea5463

Browse files
committed
[RISCV] Lower the alignment requirement for a GPR pair spill for Zdinx on RV32.
I believe we can use XLen alignment as long as eliminateFrameIndex limits the maximum folded offset to 2043. This way when we split the load/store into two 2 instructions we'll be able to add 4 without overflowing simm12. The test is long to make sure we generate enough spills to have a large offset. I'm open to suggestions on ways to shorten it.
1 parent e2b4e48 commit 3ea5463

File tree

3 files changed

+2881
-1
lines changed

3 files changed

+2881
-1
lines changed

llvm/lib/Target/RISCV/RISCVRegisterInfo.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,13 @@ bool RISCVRegisterInfo::eliminateFrameIndex(MachineBasicBlock::iterator II,
446446
(Lo12 & 0b11111) != 0) {
447447
// Prefetch instructions require the offset to be 32 byte aligned.
448448
MI.getOperand(FIOperandNum + 1).ChangeToImmediate(0);
449+
} else if ((Opc == RISCV::PseudoRV32ZdinxLD ||
450+
Opc == RISCV::PseudoRV32ZdinxSD) &&
451+
Lo12 >= 2044) {
452+
// This instruction will be split into 2 instructions. The second
453+
// instruction will add 4 to the immediate. If that would overflow 12
454+
// bits, we can't fold the offset.
455+
MI.getOperand(FIOperandNum + 1).ChangeToImmediate(0);
449456
} else {
450457
// We can encode an add with 12 bit signed immediate in the immediate
451458
// operand of our user instruction. As a result, the remaining

llvm/lib/Target/RISCV/RISCVRegisterInfo.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ let RegAltNameIndices = [ABIRegAltName] in {
573573
}
574574

575575
let RegInfos = RegInfoByHwMode<[RV32, RV64],
576-
[RegInfo<64, 64, 64>, RegInfo<128, 128, 128>]>,
576+
[RegInfo<64, 64, 32>, RegInfo<128, 128, 64>]>,
577577
DecoderMethod = "DecodeGPRPairRegisterClass" in
578578
def GPRPair : RegisterClass<"RISCV", [XLenPairFVT], 64, (add
579579
X10_X11, X12_X13, X14_X15, X16_X17,

0 commit comments

Comments
 (0)