@@ -22,6 +22,10 @@ static int getInstSeqCost(RISCVMatInt::InstSeq &Res, bool HasRVC) {
2222 // Assume instructions that aren't listed aren't compressible.
2323 bool Compressed = false ;
2424 switch (Instr.getOpcode ()) {
25+ case RISCV::QC_E_LI:
26+ // One 48-bit instruction takes the space of 1.5 regular instructions.
27+ Cost += 150 ;
28+ continue ;
2529 case RISCV::SLLI:
2630 case RISCV::SRLI:
2731 Compressed = true ;
@@ -57,6 +61,24 @@ static void generateInstSeqImpl(int64_t Val, const MCSubtargetInfo &STI,
5761 return ;
5862 }
5963
64+ if (!IsRV64 && STI.hasFeature (RISCV::FeatureVendorXqcili)) {
65+ bool FitsOneStandardInst = ((Val & 0xFFF ) == 0 ) || isInt<12 >(Val);
66+
67+ // 20-bit signed immediates that don't fit into `ADDI` or `LUI` should use
68+ // `QC.LI` (a single 32-bit instruction).
69+ if (!FitsOneStandardInst && isInt<20 >(Val)) {
70+ Res.emplace_back (RISCV::QC_LI, Val);
71+ return ;
72+ }
73+
74+ // 32-bit signed immediates that don't fit into `ADDI`, `LUI` or `QC.LI`
75+ // should use `QC.E.LI` (a single 48-bit instruction).
76+ if (!FitsOneStandardInst && isInt<32 >(Val)) {
77+ Res.emplace_back (RISCV::QC_E_LI, Val);
78+ return ;
79+ }
80+ }
81+
6082 if (isInt<32 >(Val)) {
6183 // Depending on the active bits in the immediate Value v, the following
6284 // instruction sequences are emitted:
@@ -523,6 +545,8 @@ OpndKind Inst::getOpndKind() const {
523545 default :
524546 llvm_unreachable (" Unexpected opcode!" );
525547 case RISCV::LUI:
548+ case RISCV::QC_LI:
549+ case RISCV::QC_E_LI:
526550 return RISCVMatInt::Imm;
527551 case RISCV::ADD_UW:
528552 return RISCVMatInt::RegX0;
0 commit comments