Skip to content

Commit 51c085b

Browse files
authored
[RISCV] Support Xqcilo loads/stores in RISCVMakeCompressible (#172971)
This patch adds support for converting Xqcilo loads/stores with either large offsets or uncompressible registers into loads/stores that can be compressed. We do this transformation only when the Xqcilia extension is enabled in addition to the Xqcilo extension so that we can use the QC_E_ADDI instruction to form the new base. There might be a few cases where compressing from the 48-bit Xqcilo load/store to a 32-bit load/store might be beneficial which this patch does not address.
1 parent 7d0773b commit 51c085b

File tree

2 files changed

+584
-4
lines changed

2 files changed

+584
-4
lines changed

llvm/lib/Target/RISCV/RISCVMakeCompressible.cpp

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,19 +101,26 @@ static unsigned log2LdstWidth(unsigned Opcode) {
101101
llvm_unreachable("Unexpected opcode");
102102
case RISCV::LBU:
103103
case RISCV::SB:
104+
case RISCV::QC_E_LBU:
105+
case RISCV::QC_E_SB:
104106
return 0;
105107
case RISCV::LH:
106108
case RISCV::LH_INX:
107109
case RISCV::LHU:
108110
case RISCV::SH:
109111
case RISCV::SH_INX:
112+
case RISCV::QC_E_LH:
113+
case RISCV::QC_E_LHU:
114+
case RISCV::QC_E_SH:
110115
return 1;
111116
case RISCV::LW:
112117
case RISCV::LW_INX:
113118
case RISCV::SW:
114119
case RISCV::SW_INX:
115120
case RISCV::FLW:
116121
case RISCV::FSW:
122+
case RISCV::QC_E_LW:
123+
case RISCV::QC_E_SW:
117124
return 2;
118125
case RISCV::LD:
119126
case RISCV::LD_RV32:
@@ -132,12 +139,17 @@ static unsigned offsetMask(unsigned Opcode) {
132139
llvm_unreachable("Unexpected opcode");
133140
case RISCV::LBU:
134141
case RISCV::SB:
142+
case RISCV::QC_E_LBU:
143+
case RISCV::QC_E_SB:
135144
return maskTrailingOnes<unsigned>(2U);
136145
case RISCV::LH:
137146
case RISCV::LH_INX:
138147
case RISCV::LHU:
139148
case RISCV::SH:
140149
case RISCV::SH_INX:
150+
case RISCV::QC_E_LH:
151+
case RISCV::QC_E_LHU:
152+
case RISCV::QC_E_SH:
141153
return maskTrailingOnes<unsigned>(1U);
142154
case RISCV::LW:
143155
case RISCV::LW_INX:
@@ -151,6 +163,8 @@ static unsigned offsetMask(unsigned Opcode) {
151163
case RISCV::SD_RV32:
152164
case RISCV::FLD:
153165
case RISCV::FSD:
166+
case RISCV::QC_E_LW:
167+
case RISCV::QC_E_SW:
154168
return maskTrailingOnes<unsigned>(5U);
155169
}
156170
}
@@ -214,6 +228,15 @@ static bool isCompressibleLoad(const MachineInstr &MI) {
214228
return !STI.is64Bit() && STI.hasStdExtCOrZcfOrZce();
215229
case RISCV::FLD:
216230
return STI.hasStdExtCOrZcd();
231+
// For the Xqcilo loads we mark it as compressible only if Xqcilia is also
232+
// enabled so that QC_E_ADDI can be used to create the new base.
233+
case RISCV::QC_E_LBU:
234+
case RISCV::QC_E_LH:
235+
case RISCV::QC_E_LHU:
236+
return !STI.is64Bit() && STI.hasVendorXqcilo() && STI.hasVendorXqcilia() &&
237+
STI.hasStdExtZcb();
238+
case RISCV::QC_E_LW:
239+
return !STI.is64Bit() && STI.hasVendorXqcilo() && STI.hasVendorXqcilia();
217240
}
218241
}
219242

@@ -238,6 +261,14 @@ static bool isCompressibleStore(const MachineInstr &MI) {
238261
return !STI.is64Bit() && STI.hasStdExtCOrZcfOrZce();
239262
case RISCV::FSD:
240263
return STI.hasStdExtCOrZcd();
264+
// For the Xqcilo stores we mark it as compressible only if Xqcilia is also
265+
// enabled so that QC_E_ADDI can be used to create the new base.
266+
case RISCV::QC_E_SB:
267+
case RISCV::QC_E_SH:
268+
return !STI.is64Bit() && STI.hasVendorXqcilo() && STI.hasVendorXqcilia() &&
269+
STI.hasStdExtZcb();
270+
case RISCV::QC_E_SW:
271+
return !STI.is64Bit() && STI.hasVendorXqcilo() && STI.hasVendorXqcilia();
241272
}
242273
}
243274

@@ -437,10 +468,16 @@ bool RISCVMakeCompressibleOpt::runOnMachineFunction(MachineFunction &Fn) {
437468

438469
// Create the appropriate copy and/or offset.
439470
if (RISCV::GPRRegClass.contains(RegImm.Reg)) {
440-
assert(isInt<12>(RegImm.Imm));
441-
BuildMI(MBB, MI, MI.getDebugLoc(), TII.get(RISCV::ADDI), NewReg)
442-
.addReg(RegImm.Reg)
443-
.addImm(RegImm.Imm);
471+
if (isInt<12>(RegImm.Imm)) {
472+
BuildMI(MBB, MI, MI.getDebugLoc(), TII.get(RISCV::ADDI), NewReg)
473+
.addReg(RegImm.Reg)
474+
.addImm(RegImm.Imm);
475+
} else {
476+
assert(STI.hasVendorXqcilia() && isInt<26>(RegImm.Imm));
477+
BuildMI(MBB, MI, MI.getDebugLoc(), TII.get(RISCV::QC_E_ADDI), NewReg)
478+
.addReg(RegImm.Reg)
479+
.addImm(RegImm.Imm);
480+
}
444481
} else {
445482
assert(RegImm.Imm == 0);
446483
TII.copyPhysReg(MBB, MI, MI.getDebugLoc(), NewReg, RegImm.Reg,

0 commit comments

Comments
 (0)