Skip to content

Commit 5c45ae4

Browse files
committed
[RISCV] Fix wrong register rename for store value during make-compressible optimization
Current implementation will rename both register in store instructions if we store base address into memory with same base register, it's OK if the offset is 0, however that is wrong transform if offset isn't 0, give a smalle example here: sd a0, 808(a0) We should not transform into: addi a2, a0, 768 sd a2, 40(a2) That should just rename base address like this: addi a2, a0, 768 sd a0, 40(a2) Reviewed By: asb Differential Revision: https://reviews.llvm.org/D128876
1 parent de3b5d7 commit 5c45ae4

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

llvm/lib/Target/RISCV/RISCVMakeCompressible.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,8 +293,16 @@ static void updateOperands(MachineInstr &MI, RegImmPair OldRegImm,
293293
assert((isCompressibleLoad(MI) || isCompressibleStore(MI)) &&
294294
"Unsupported instruction for this optimization.");
295295

296+
int SkipN = 0;
297+
298+
// Skip the first (value) operand to a store instruction (except if the store
299+
// offset is zero) in order to avoid an incorrect transformation.
300+
// e.g. sd a0, 808(a0) to addi a2, a0, 768; sd a2, 40(a2)
301+
if (isCompressibleStore(MI) && OldRegImm.Imm != 0)
302+
SkipN = 1;
303+
296304
// Update registers
297-
for (MachineOperand &MO : MI.operands())
305+
for (MachineOperand &MO : drop_begin(MI.operands(), SkipN))
298306
if (MO.isReg() && MO.getReg() == OldRegImm.Reg) {
299307
// Do not update operands that define the old register.
300308
//

llvm/test/CodeGen/RISCV/make-compressible-for-store-address.mir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ body: |
3333
; CHECK-NEXT: renamable $x11 = ADDI $x0, 1
3434
; CHECK-NEXT: $x12 = ADDI $x10, 768
3535
; CHECK-NEXT: SD killed renamable $x11, $x12, 32 :: (store (s64) into %ir.1)
36-
; CHECK-NEXT: SD $x12, $x12, 40 :: (store (s64) into %ir.2)
36+
; CHECK-NEXT: SD renamable $x10, $x12, 40 :: (store (s64) into %ir.2)
3737
; CHECK-NEXT: renamable $x11 = ADDI $x0, 2
3838
; CHECK-NEXT: SD killed renamable $x11, killed $x12, 48 :: (store (s64) into %ir.3)
3939
; CHECK-NEXT: PseudoRET

0 commit comments

Comments
 (0)