Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
25 changes: 25 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,25 @@ static void generateInstSeqImpl(int64_t Val, const MCSubtargetInfo &STI,
return;
}

if (!IsRV64 && STI.hasFeature(RISCV::FeatureVendorXqcili)) {
bool FitsOneStandardInst =
((Val & 0xFFF) == 0) || (((Val + 0x800) & 0xFFFFF000) == 0);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we do

return ((Val & 0xFFF) == 0) || isInt<12>(Val);

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, done.


// 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 +546,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