Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions llvm/docs/ReleaseNotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ Changes to the RISC-V Backend
* Adds assembler support for the 'Zclsd` (Compressed Load/Store Pair Instructions)
extension.
* Adds experimental assembler support for Zvqdotq.
* When the experimental extension `Xqcili` is enabled, `qc.e.li` and `qc.li` may
now be used to materialize immediates.

Changes to the WebAssembly Backend
----------------------------------
Expand Down
24 changes: 24 additions & 0 deletions llvm/lib/Target/RISCV/MCTargetDesc/RISCVMatInt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ static int getInstSeqCost(RISCVMatInt::InstSeq &Res, bool HasRVC) {
// Assume instructions that aren't listed aren't compressible.
bool Compressed = false;
switch (Instr.getOpcode()) {
case RISCV::QC_E_LI:
// One 48-bit instruction takes the space of 1.5 regular instructions.
Cost += 150;
continue;
case RISCV::SLLI:
case RISCV::SRLI:
Compressed = true;
Expand Down Expand Up @@ -57,6 +61,24 @@ static void generateInstSeqImpl(int64_t Val, const MCSubtargetInfo &STI,
return;
}

if (!IsRV64 && STI.hasFeature(RISCV::FeatureVendorXqcili)) {
bool FitsOneStandardInst = ((Val & 0xFFF) == 0) || isInt<12>(Val);

// 20-bit signed immediates that don't fit into `ADDI` or `LUI` should use
// `QC.LI` (a single 32-bit instruction).
if (!FitsOneStandardInst && isInt<20>(Val)) {
Res.emplace_back(RISCV::QC_LI, Val);
return;
}

// 32-bit signed immediates that don't fit into `ADDI`, `LUI` or `QC.LI`
// should use `QC.E.LI` (a single 48-bit instruction).
if (!FitsOneStandardInst && isInt<32>(Val)) {
Res.emplace_back(RISCV::QC_E_LI, Val);
return;
}
}

if (isInt<32>(Val)) {
// Depending on the active bits in the immediate Value v, the following
// instruction sequences are emitted:
Expand Down Expand Up @@ -523,6 +545,8 @@ OpndKind Inst::getOpndKind() const {
default:
llvm_unreachable("Unexpected opcode!");
case RISCV::LUI:
case RISCV::QC_LI:
case RISCV::QC_E_LI:
return RISCVMatInt::Imm;
case RISCV::ADD_UW:
return RISCVMatInt::RegX0;
Expand Down
3 changes: 3 additions & 0 deletions llvm/lib/Target/RISCV/RISCVInstrInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2603,8 +2603,11 @@ bool RISCVInstrInfo::verifyInstruction(const MachineInstr &MI,
// clang-format off
CASE_OPERAND_SIMM(5)
CASE_OPERAND_SIMM(6)
CASE_OPERAND_SIMM(11)
CASE_OPERAND_SIMM(12)
CASE_OPERAND_SIMM(20)
CASE_OPERAND_SIMM(26)
CASE_OPERAND_SIMM(32)
// clang-format on
case RISCVOp::OPERAND_SIMM5_PLUS1:
Ok = (isInt<5>(Imm) && Imm != -16) || Imm == 16;
Expand Down
Loading
Loading