Skip to content

Commit 4f7c9a8

Browse files
committed
[RISCV] Correctly account for the copy cost of GPR pairs in RISCVMakeCompressible.
1 parent adbbc57 commit 4f7c9a8

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

llvm/lib/Target/RISCV/RISCVMakeCompressible.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -332,9 +332,11 @@ static Register analyzeCompressibleUses(MachineInstr &FirstMI,
332332
// are required for a code size reduction. If no base adjustment is required,
333333
// then copying the register costs one new c.mv (or c.li Rd, 0 for "copying"
334334
// the zero register) and therefore two uses are required for a code size
335-
// reduction.
336-
if (MIs.size() < 2 || (RegImm.Imm != 0 && MIs.size() < 3))
337-
return RISCV::NoRegister;
335+
// reduction. For GPR pairs, we need 2 ADDIs to copy so we need three users.
336+
unsigned CopyCost = RISCV::GPRPairRegClass.contains(RegImm.Reg) ? 2 : 1;
337+
assert((RegImm.Imm == 0 || CopyCost == 1) && "GPRPair should have zero imm");
338+
if (MIs.size() <= CopyCost || (RegImm.Imm != 0 && MIs.size() <= 2))
339+
return Register();
338340

339341
// Find a compressible register which will be available from the first
340342
// instruction we care about to the last.

llvm/test/CodeGen/RISCV/make-compressible-zilsd.mir

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -234,10 +234,8 @@ body: |
234234
; RV32-LABEL: name: store_common_value_double_no_opt2
235235
; RV32: liveins: $x10, $x16, $x17
236236
; RV32-NEXT: {{ $}}
237-
; RV32-NEXT: $x12 = ADDI $x16, 0
238-
; RV32-NEXT: $x13 = ADDI $x17, 0
239-
; RV32-NEXT: SD_RV32 $x12_x13, renamable $x10, 0 :: (volatile store (s64) into %ir.a)
240-
; RV32-NEXT: SD_RV32 killed $x12_x13, killed renamable $x10, 0 :: (volatile store (s64) into %ir.a)
237+
; RV32-NEXT: SD_RV32 renamable $x16_x17, renamable $x10, 0 :: (volatile store (s64) into %ir.a)
238+
; RV32-NEXT: SD_RV32 killed renamable $x16_x17, killed renamable $x10, 0 :: (volatile store (s64) into %ir.a)
241239
; RV32-NEXT: PseudoRET
242240
SD_RV32 renamable $x16_x17, renamable $x10, 0 :: (volatile store (s64) into %ir.a)
243241
SD_RV32 killed renamable $x16_x17, killed renamable $x10, 0 :: (volatile store (s64) into %ir.a)

0 commit comments

Comments
 (0)