Skip to content

Commit 75d62ee

Browse files
authored
[RISCV] Correctly account for the copy cost of GPR pairs in RISCVMakeCompressible. (#141251)
GPR pairs require 2 ADDIs to copy, so we need to be updating more instructions to get a benefit.
1 parent a2d717d commit 75d62ee

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
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: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,13 @@
7070
ret void
7171
}
7272

73+
define void @store_common_value_double_no_opt2(ptr %a, i32 %b, double %c, double %d, double %e) #0 {
74+
entry:
75+
store volatile double %e, ptr %a, align 8
76+
store volatile double %e, ptr %a, align 8
77+
ret void
78+
}
79+
7380
define void @store_common_ptr_double_no_opt(double %a, i32 %b, i32 %c, i32 %d, i32 %e, ptr %p) #0 {
7481
entry:
7582
store volatile double %a, ptr %p, align 8
@@ -246,6 +253,24 @@ body: |
246253
SD_RV32 killed renamable $x16_x17, killed renamable $x10, 0 :: (store (s64) into %ir.a)
247254
PseudoRET
248255
256+
...
257+
---
258+
name: store_common_value_double_no_opt2
259+
tracksRegLiveness: true
260+
body: |
261+
bb.0.entry:
262+
liveins: $x10, $x16, $x17
263+
264+
; RV32-LABEL: name: store_common_value_double_no_opt2
265+
; RV32: liveins: $x10, $x16, $x17
266+
; RV32-NEXT: {{ $}}
267+
; RV32-NEXT: SD_RV32 renamable $x16_x17, renamable $x10, 0 :: (volatile store (s64) into %ir.a)
268+
; RV32-NEXT: SD_RV32 killed renamable $x16_x17, killed renamable $x10, 0 :: (volatile store (s64) into %ir.a)
269+
; RV32-NEXT: PseudoRET
270+
SD_RV32 renamable $x16_x17, renamable $x10, 0 :: (volatile store (s64) into %ir.a)
271+
SD_RV32 killed renamable $x16_x17, killed renamable $x10, 0 :: (volatile store (s64) into %ir.a)
272+
PseudoRET
273+
249274
...
250275
---
251276
name: store_common_ptr_double_no_opt

0 commit comments

Comments
 (0)