[PATCH] D140319: [RISCV] Match neg (and x, 1) to two shifts to improve codesize

Jessica Clarke via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 19 10:56:47 PST 2022


jrtc27 added inline comments.


================
Comment at: llvm/lib/Target/RISCV/RISCVInstrInfo.td:1244
+// is never compressible since rs1 and rd can't be the same register.
+let Predicates = [IsRV64, HasStdExtC] in {
+def : Pat<(XLenVT (sub 0x0, (and_oneuse GPR:$rs, 0x1))),
----------------
reames wrote:
> This shouldn't be specific to RV64, but my attempts to write a pattern which used ImmSubFromVLen kept failing type inference.  Any suggestions on how to write such a pattern?
ImmSubFromXLen (XLenVT 1), as the issue is TableGen has no way of knowing that the type of the input is the same as the output, it just sees the input as unconstrained, only the output constrained by its use. Normally that doesn't matter because the input is a pre-existing node whose type is constrained by the pattern being matched.


================
Comment at: llvm/lib/Target/RISCV/RISCVInstrInfo.td:1245
+let Predicates = [IsRV64, HasStdExtC] in {
+def : Pat<(XLenVT (sub 0x0, (and_oneuse GPR:$rs, 0x1))),
+          (SRAI (SLLI $rs, 63), 63)>;
----------------
Why explicit hex?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D140319/new/

https://reviews.llvm.org/D140319



More information about the llvm-commits mailing list