Skip to content

Commit 17117c1

Browse files
[RISCV] Correct the limit of RegPresureSet GPRAll
The generated limit is 33, which is the total number of scalar registers plus 1 (for `DUMMY_REG_PAIR_WITH_X0`). This is not right as not all scalar registers can be used. There are 4-6 reserved registers, so we need to adjust the limit by the reserved set. This change has impacts on instruction scheduling, MachineLICM, etc. Here are the statistics of spills/reloads on `llvm-test-suite` with `-O3 -march=rva23u64`: ``` Metric: regalloc.NumSpills,regalloc.NumReloads Program regalloc.NumSpills regalloc.NumReloads baseline after diff baseline after diff External/S...NT2017rate/502.gcc_r/502.gcc_r 11812.00 11338.00 -474.00 26813.00 25751.00 -1062.00 External/S...T2017speed/602.gcc_s/602.gcc_s 11812.00 11338.00 -474.00 26813.00 25751.00 -1062.00 External/S...te/526.blender_r/526.blender_r 13514.00 13228.00 -286.00 27456.00 27260.00 -196.00 External/S...00.perlbench_s/600.perlbench_s 4398.00 4274.00 -124.00 9745.00 9341.00 -404.00 External/S...00.perlbench_r/500.perlbench_r 4398.00 4274.00 -124.00 9745.00 9341.00 -404.00 SingleSour...nchmarks/Adobe-C++/loop_unroll 1533.00 1413.00 -120.00 2943.00 2633.00 -310.00 External/S...rate/510.parest_r/510.parest_r 43985.00 43879.00 -106.00 87409.00 87309.00 -100.00 External/S...te/538.imagick_r/538.imagick_r 4160.00 4060.00 -100.00 10338.00 10244.00 -94.00 External/S...ed/638.imagick_s/638.imagick_s 4160.00 4060.00 -100.00 10338.00 10244.00 -94.00 MultiSourc...e/Applications/ClamAV/clamscan 2120.00 2023.00 -97.00 5035.00 4901.00 -134.00 MultiSourc...sumer-typeset/consumer-typeset 1218.00 1129.00 -89.00 3041.00 2887.00 -154.00 MultiSourc.../Applications/JM/ldecod/ldecod 1341.00 1263.00 -78.00 2316.00 2238.00 -78.00 External/S...rate/511.povray_r/511.povray_r 1734.00 1659.00 -75.00 3413.00 3246.00 -167.00 MultiSource/Applications/SPASS/SPASS 1442.00 1376.00 -66.00 2954.00 2837.00 -117.00 MultiSourc.../DOE-ProxyApps-C++/CLAMR/CLAMR 1628.00 1568.00 -60.00 3026.00 2958.00 -68.00 regalloc.NumSpills regalloc.NumReloads run baseline after diff baseline after diff mean 86.725206 85.041122 -1.684083 1363.122137 1342.900383 -3.212869 ``` Co-authored-by: BoyaoWang430 <[email protected]>
1 parent 356df2d commit 17117c1

9 files changed

+3755
-3959
lines changed

llvm/lib/Target/RISCV/RISCVRegisterInfo.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -934,3 +934,17 @@ bool RISCVRegisterInfo::getRegAllocationHints(
934934

935935
return BaseImplRetVal;
936936
}
937+
938+
unsigned RISCVRegisterInfo::getRegPressureSetLimit(const MachineFunction &MF,
939+
unsigned Idx) const {
940+
if (Idx == RISCV::RegisterPressureSets::GPRAll) {
941+
unsigned Reserved = 0;
942+
BitVector ReservedRegs = getReservedRegs(MF);
943+
for (MCPhysReg Reg = RISCV::X0_H; Reg <= RISCV::X31_H; Reg++)
944+
if (ReservedRegs.test(Reg))
945+
Reserved++;
946+
947+
return 32 - Reserved;
948+
}
949+
return RISCVGenRegisterInfo::getRegPressureSetLimit(MF, Idx);
950+
}

llvm/lib/Target/RISCV/RISCVRegisterInfo.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ struct RISCVRegisterInfo : public RISCVGenRegisterInfo {
144144
static bool isRVVRegClass(const TargetRegisterClass *RC) {
145145
return RISCVRI::isVRegClass(RC->TSFlags);
146146
}
147+
unsigned getRegPressureSetLimit(const MachineFunction &MF,
148+
unsigned Idx) const override;
147149
};
148150
} // namespace llvm
149151

0 commit comments

Comments
 (0)