Skip to content

Commit 7e97ae3

Browse files
authored
[RISCV] Teach RISCVMakeCompressible handle Zca/Zcf/Zce/Zcd. (llvm#81844)
Make targets which don't have C but have Zca/Zcf/Zce/Zcd benefit from this pass.
1 parent bc1c86b commit 7e97ae3

File tree

3 files changed

+400
-134
lines changed

3 files changed

+400
-134
lines changed

llvm/lib/Target/RISCV/RISCVMakeCompressible.cpp

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -143,19 +143,35 @@ static bool isCompressedReg(Register Reg) {
143143
// Return true if MI is a load for which there exists a compressed version.
144144
static bool isCompressibleLoad(const MachineInstr &MI) {
145145
const RISCVSubtarget &STI = MI.getMF()->getSubtarget<RISCVSubtarget>();
146-
const unsigned Opcode = MI.getOpcode();
147146

148-
return Opcode == RISCV::LW || (!STI.is64Bit() && Opcode == RISCV::FLW) ||
149-
Opcode == RISCV::LD || Opcode == RISCV::FLD;
147+
switch (MI.getOpcode()) {
148+
default:
149+
return false;
150+
case RISCV::LW:
151+
case RISCV::LD:
152+
return STI.hasStdExtCOrZca();
153+
case RISCV::FLW:
154+
return !STI.is64Bit() && STI.hasStdExtCOrZcfOrZce();
155+
case RISCV::FLD:
156+
return STI.hasStdExtCOrZcd();
157+
}
150158
}
151159

152160
// Return true if MI is a store for which there exists a compressed version.
153161
static bool isCompressibleStore(const MachineInstr &MI) {
154162
const RISCVSubtarget &STI = MI.getMF()->getSubtarget<RISCVSubtarget>();
155-
const unsigned Opcode = MI.getOpcode();
156163

157-
return Opcode == RISCV::SW || (!STI.is64Bit() && Opcode == RISCV::FSW) ||
158-
Opcode == RISCV::SD || Opcode == RISCV::FSD;
164+
switch (MI.getOpcode()) {
165+
default:
166+
return false;
167+
case RISCV::SW:
168+
case RISCV::SD:
169+
return STI.hasStdExtCOrZca();
170+
case RISCV::FSW:
171+
return !STI.is64Bit() && STI.hasStdExtCOrZcfOrZce();
172+
case RISCV::FSD:
173+
return STI.hasStdExtCOrZcd();
174+
}
159175
}
160176

161177
// Find a single register and/or large offset which, if compressible, would
@@ -324,8 +340,7 @@ bool RISCVMakeCompressibleOpt::runOnMachineFunction(MachineFunction &Fn) {
324340
const RISCVInstrInfo &TII = *STI.getInstrInfo();
325341

326342
// This optimization only makes sense if compressed instructions are emitted.
327-
// FIXME: Support Zca, Zcf, Zcd granularity.
328-
if (!STI.hasStdExtC())
343+
if (!STI.hasStdExtCOrZca())
329344
return false;
330345

331346
for (MachineBasicBlock &MBB : Fn) {

llvm/lib/Target/RISCV/RISCVSubtarget.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,10 @@ class RISCVSubtarget : public RISCVGenSubtargetInfo {
143143
#include "RISCVGenSubtargetInfo.inc"
144144

145145
bool hasStdExtCOrZca() const { return HasStdExtC || HasStdExtZca; }
146+
bool hasStdExtCOrZcd() const { return HasStdExtC || HasStdExtZcd; }
147+
bool hasStdExtCOrZcfOrZce() const {
148+
return HasStdExtC || HasStdExtZcf || HasStdExtZce;
149+
}
146150
bool hasStdExtZvl() const { return ZvlLen != 0; }
147151
bool hasStdExtFOrZfinx() const { return HasStdExtF || HasStdExtZfinx; }
148152
bool hasStdExtDOrZdinx() const { return HasStdExtD || HasStdExtZdinx; }

0 commit comments

Comments
 (0)