Skip to content

Commit 1dea0f3

Browse files
committed
Reuse the patterns from Zba for XAndesPerf lea instructions
1 parent ffb5d39 commit 1dea0f3

File tree

6 files changed

+1323
-98
lines changed

6 files changed

+1323
-98
lines changed

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14628,8 +14628,8 @@ static SDValue combineBinOpToReduce(SDNode *N, SelectionDAG &DAG,
1462814628
// (SLLI (SH*ADD x, y), c0), if c1-c0 equals to [1|2|3].
1462914629
static SDValue transformAddShlImm(SDNode *N, SelectionDAG &DAG,
1463014630
const RISCVSubtarget &Subtarget) {
14631-
// Perform this optimization only in the zba extension.
14632-
if (!Subtarget.hasStdExtZba())
14631+
// Perform this optimization only in the zba/xandesperf extension.
14632+
if (!Subtarget.hasStdExtZba() && !Subtarget.hasVendorXAndesPerf())
1463314633
return SDValue();
1463414634

1463514635
// Skip for vector types and larger types.
@@ -15536,8 +15536,9 @@ static SDValue expandMul(SDNode *N, SelectionDAG &DAG,
1553615536
if (VT != Subtarget.getXLenVT())
1553715537
return SDValue();
1553815538

15539-
const bool HasShlAdd =
15540-
Subtarget.hasStdExtZba() || Subtarget.hasVendorXTHeadBa();
15539+
const bool HasShlAdd = Subtarget.hasStdExtZba() ||
15540+
Subtarget.hasVendorXTHeadBa() ||
15541+
Subtarget.hasVendorXAndesPerf();
1554115542

1554215543
ConstantSDNode *CNode = dyn_cast<ConstantSDNode>(N->getOperand(1));
1554315544
if (!CNode)

llvm/lib/Target/RISCV/RISCVInstrInfoXAndes.td

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -360,24 +360,28 @@ def NDS_SDGP : NDSRVInstSDGP<0b111, "nds.sdgp">;
360360
// Patterns
361361

362362
let Predicates = [HasVendorXAndesPerf] in {
363-
class NDS_LEAPat<int shamt, RVInstR Inst>
364-
: Pat<(add (XLenVT GPR:$rs1), (shl GPR:$rs2, (XLenVT shamt))),
365-
(Inst GPR:$rs1, GPR:$rs2)>;
366363

367-
def : NDS_LEAPat<1, NDS_LEA_H>;
368-
def : NDS_LEAPat<2, NDS_LEA_W>;
369-
def : NDS_LEAPat<3, NDS_LEA_D>;
364+
defm : ShxAddPat<1, NDS_LEA_H>;
365+
defm : ShxAddPat<2, NDS_LEA_W>;
366+
defm : ShxAddPat<3, NDS_LEA_D>;
367+
368+
def : CSImm12MulBy4Pat<NDS_LEA_W>;
369+
def : CSImm12MulBy8Pat<NDS_LEA_D>;
370370
} // Predicates = [HasVendorXAndesPerf]
371371

372372
let Predicates = [HasVendorXAndesPerf, IsRV64] in {
373-
def : Pat<(add (XLenVT GPR:$rs1), (zexti32 (i64 GPR:$rs2))),
374-
(NDS_LEA_B_ZE GPR:$rs1, GPR:$rs2)>;
375373

376-
class NDS_LEA_ZEPat<int shamt, RVInstR Inst>
377-
: Pat<(add GPR:$rs1, (shl (zexti32 (XLenVT GPR:$rs2)), (XLenVT shamt))),
378-
(Inst GPR:$rs1, GPR:$rs2)>;
374+
defm : ADD_UWPat<NDS_LEA_B_ZE>;
375+
376+
defm : ShxAdd_UWPat<1, NDS_LEA_H_ZE>;
377+
defm : ShxAdd_UWPat<2, NDS_LEA_W_ZE>;
378+
defm : ShxAdd_UWPat<3, NDS_LEA_D_ZE>;
379+
380+
defm : Sh1Add_UWPat<NDS_LEA_H_ZE>;
381+
defm : Sh2Add_UWPat<NDS_LEA_W_ZE>;
382+
defm : Sh3Add_UWPat<NDS_LEA_D_ZE>;
379383

380-
def : NDS_LEA_ZEPat<1, NDS_LEA_H_ZE>;
381-
def : NDS_LEA_ZEPat<2, NDS_LEA_W_ZE>;
382-
def : NDS_LEA_ZEPat<3, NDS_LEA_D_ZE>;
384+
def : Sh1AddPat<NDS_LEA_H_ZE>;
385+
def : Sh2AddPat<NDS_LEA_W_ZE>;
386+
def : Sh3AddPat<NDS_LEA_D_ZE>;
383387
} // Predicates = [HasVendorXAndesPerf, IsRV64]

llvm/test/CodeGen/RISCV/rv32xandesperf.ll

Lines changed: 0 additions & 33 deletions
This file was deleted.

0 commit comments

Comments
 (0)