[llvm] [RISCV] Fix QC.E.LI -> C.LI with Bare Symbol Compression (PR #146763)
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 9 22:01:03 PDT 2025
MaskRay wrote:
https://github.com/llvm/llvm-project/pull/139273 introduced a `CompressPat` to convert qe.e.li to c.li.
```
let isCompressOnly = true in
def : CompressPat<(QC_E_LI GPRNoX0:$rd, simm6:$imm),
(C_LI GPRNoX0:$rd, simm6:$imm)>;
```
There is a crash when assembling `qc.e.li a0, undef`.
Immediate thought: Is `simm6` appropriate in the `CompressPat`? Shall we allow immediates only?
But that would rule out compression for `qc.e.li x10, foo; foo = 8`, which you probably want.
(It assembles to `051f 0000 0008 qc.e.li a0, 0x80000` with this PR, which suggests a bug.)
Anyhow, let's continue.
* RISCVAsmParser::emitToStreamer calls RISCVRVC::compress, which calls RISCVValidateMCOperandForCompress to `simm6`.
* The verifier passes because `MCOp.isBareSymbolRef();` returns true.
```
case 3: {
// simm6
int64_t Imm;
if (MCOp.evaluateAsConstantImm(Imm))
return isInt<6>(Imm);
return MCOp.isBareSymbolRef();
}
```
* `RISCVMCCodeEmitter::encodeInstruction` calls `getBinaryCodeForInstr` for the compressed `c.li`, which failed because there wasn't a defined fixup.
This PR adds a fixup, which could be used to accept `c.li a0, foo; foo = 9` (currently rejected by GAS, but with a fixup this could be made working)
---
* Introducing a fixup for c.li seems like a solid choice.
* You might want to address the qc.e.li x10, foo; foo = 8 bug.
* I recommend that RISC-V avoids adding more hacks to the generic interface, such as `MCInst MCOp.isBareSymbolRef()`. #146184 actually eliminates some, which I like. Thanks!
https://github.com/llvm/llvm-project/pull/146763
More information about the llvm-commits
mailing list