Skip to content

Commit 346f499

Browse files
authored
[RISCV] Add add_like PatFrags to reduce number of required patterns [nfc] (#86983)
This is an NFC prep patch for an upcoming change which is going to support or_is_add in a bunch more cases. Posting separately because tblgen is not particularly my strong suit.
1 parent 6f10dcc commit 346f499

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

llvm/lib/Target/RISCV/RISCVInstrInfo.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1259,6 +1259,10 @@ def or_is_add : PatFrag<(ops node:$lhs, node:$rhs), (or node:$lhs, node:$rhs),[{
12591259
}]>;
12601260
def : PatGprSimm12<or_is_add, ADDI>;
12611261

1262+
def add_like : PatFrags<(ops node:$lhs, node:$rhs),
1263+
[(or_is_add node:$lhs, node:$rhs),
1264+
(add node:$lhs, node:$rhs)]>;
1265+
12621266
// negate of low bit can be done via two (compressible) shifts. The negate
12631267
// is never compressible since rs1 and rd can't be the same register.
12641268
def : Pat<(XLenVT (sub 0, (and_oneuse GPR:$rs, 1))),

llvm/lib/Target/RISCV/RISCVInstrInfoZb.td

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ class binop_with_non_imm12<SDPatternOperator binop>
255255
}];
256256
}
257257
def add_non_imm12 : binop_with_non_imm12<add>;
258-
def or_is_add_non_imm12 : binop_with_non_imm12<or_is_add>;
258+
def add_like_non_imm12 : binop_with_non_imm12<add_like>;
259259

260260
def Shifted32OnesMask : IntImmLeaf<XLenVT, [{
261261
if (!Imm.isShiftedMask())
@@ -756,13 +756,10 @@ def : Pat<(i64 (shl (and GPR:$rs1, 0xFFFFFFFF), uimm5:$shamt)),
756756
def : Pat<(i64 (and GPR:$rs1, Shifted32OnesMask:$mask)),
757757
(SLLI_UW (XLenVT (SRLI GPR:$rs1, Shifted32OnesMask:$mask)),
758758
Shifted32OnesMask:$mask)>;
759-
def : Pat<(i64 (add_non_imm12 (and GPR:$rs1, 0xFFFFFFFF), GPR:$rs2)),
759+
def : Pat<(i64 (add_like_non_imm12 (and GPR:$rs1, 0xFFFFFFFF), GPR:$rs2)),
760760
(ADD_UW GPR:$rs1, GPR:$rs2)>;
761761
def : Pat<(i64 (and GPR:$rs, 0xFFFFFFFF)), (ADD_UW GPR:$rs, (XLenVT X0))>;
762762

763-
def : Pat<(i64 (or_is_add_non_imm12 (and GPR:$rs1, 0xFFFFFFFF), GPR:$rs2)),
764-
(ADD_UW GPR:$rs1, GPR:$rs2)>;
765-
766763
foreach i = {1,2,3} in {
767764
defvar shxadd_uw = !cast<Instruction>("SH"#i#"ADD_UW");
768765
def : Pat<(i64 (add_non_imm12 (shl (and GPR:$rs1, 0xFFFFFFFF), (i64 i)), (XLenVT GPR:$rs2))),
@@ -876,13 +873,10 @@ let Predicates = [HasStdExtZba, IsRV64] in {
876873
def : Pat<(shl (i64 (zext i32:$rs1)), uimm5:$shamt),
877874
(SLLI_UW GPR:$rs1, uimm5:$shamt)>;
878875

879-
def : Pat<(i64 (add_non_imm12 (zext GPR:$rs1), GPR:$rs2)),
876+
def : Pat<(i64 (add_like_non_imm12 (zext GPR:$rs1), GPR:$rs2)),
880877
(ADD_UW GPR:$rs1, GPR:$rs2)>;
881878
def : Pat<(zext GPR:$src), (ADD_UW GPR:$src, (XLenVT X0))>;
882879

883-
def : Pat<(i64 (or_is_add_non_imm12 (zext GPR:$rs1), GPR:$rs2)),
884-
(ADD_UW GPR:$rs1, GPR:$rs2)>;
885-
886880
foreach i = {1,2,3} in {
887881
defvar shxadd = !cast<Instruction>("SH"#i#"ADD");
888882
def : Pat<(i32 (add_non_imm12 (shl GPR:$rs1, (i64 i)), GPR:$rs2)),

0 commit comments

Comments
 (0)