[llvm] [RISCV] Use Record from CompressPat in compress/uncompress functions. (PR #150664)

Sam Elliott via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 25 11:29:47 PDT 2025


lenary wrote:

> Now we're using what is in the CompressPat where before we were using whatever was in the instructions and ignoring the predicate in the CompressPat.

I wonder if we can use both? Maybe this is too much of a change.

so for

```
def : CompressPat<(ADDI GPRNoX0:$rs1, GPRNoX0:$rs1, simm6nonzero:$imm),
                  (C_ADDI GPRNoX0:$rs1, simm6nonzero:$imm)>;
```

When compressing, you would check that `$imm` is `simm6nonzero` and `simm6nonzero` (sure, inefficient, but both will give the same result). When uncompressing, you check `$imm` is both `simm6nonzero` and `simm12`.

This should close the validity hole, without having to check a tablegen time whether `simm6nonzero` is a subset of `simm12` - effectively deferring that check to runtime?

I think this should work for register classes too? I'm not sure though.

We can then work out how to get rid of redundant checks for an operand afterwards, I think.

https://github.com/llvm/llvm-project/pull/150664


More information about the llvm-commits mailing list