[PATCH] D105796: [RISCV] Optimize multiplication in the zba extension with SH*ADD

LevyHsu via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 12 07:52:55 PDT 2021


LevyHsu added inline comments.


================
Comment at: llvm/lib/Target/RISCV/RISCVInstrInfoB.td:972
 
-let Predicates = [HasStdExtZba] in {
-def : Pat<(add (shl GPR:$rs1, (XLenVT 1)), non_imm12:$rs2),
-          (SH1ADD GPR:$rs1, GPR:$rs2)>;
-def : Pat<(add (shl GPR:$rs1, (XLenVT 2)), non_imm12:$rs2),
-          (SH2ADD GPR:$rs1, GPR:$rs2)>;
-def : Pat<(add (shl GPR:$rs1, (XLenVT 3)), non_imm12:$rs2),
-          (SH3ADD GPR:$rs1, GPR:$rs2)>;
+def addshl : PatFrag<(ops node:$A, node:$B, node:$C, node:$D),
+                     (add (add (shl node:$A, node:$B), (shl node:$A, node:$C)),
----------------
If I understand it correctly, 
(shl node:$A, node:$B) matches (A<<B)
(shl node:$A, node:$C) matches (A<<C)
which makes the pattern like Jessica said: (A<<B) + (A<<C) + D

But on spec those patterns are:

```
uint_xlen_t sh1add(uint_xlen_t rs1, uint_xlen_t rs2)
{
return (rs1 << 1) + rs2;
}
uint_xlen_t sh2add(uint_xlen_t rs1, uint_xlen_t rs2)
{
return (rs1 << 2) + rs2;
}
uint_xlen_t sh3add(uint_xlen_t rs1, uint_xlen_t rs2)
{
return (rs1 << 3) + rs2;
}
```




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

https://reviews.llvm.org/D105796



More information about the llvm-commits mailing list