diff --git a/llvm/lib/Target/RISCV/RISCVISelDAGToDAG.h b/llvm/lib/Target/RISCV/RISCVISelDAGToDAG.h --- a/llvm/lib/Target/RISCV/RISCVISelDAGToDAG.h +++ b/llvm/lib/Target/RISCV/RISCVISelDAGToDAG.h @@ -44,6 +44,7 @@ std::vector &OutOps) override; bool SelectAddrFI(SDValue Addr, SDValue &Base); + bool SelectRVVBaseAddr(SDValue Addr, SDValue &Base); bool isUnneededShiftMask(SDNode *N, unsigned Width) const; diff --git a/llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp b/llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp --- a/llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp +++ b/llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp @@ -846,13 +846,23 @@ } bool RISCVDAGToDAGISel::SelectAddrFI(SDValue Addr, SDValue &Base) { - if (auto FIN = dyn_cast(Addr)) { + if (auto *FIN = dyn_cast(Addr)) { Base = CurDAG->getTargetFrameIndex(FIN->getIndex(), Subtarget->getXLenVT()); return true; } return false; } +bool RISCVDAGToDAGISel::SelectRVVBaseAddr(SDValue Addr, SDValue &Base) { + // If this is FrameIndex, select it directly. Otherwise just let it get + // selected to a register independently. + if (auto *FIN = dyn_cast(Addr)) + Base = CurDAG->getTargetFrameIndex(FIN->getIndex(), Subtarget->getXLenVT()); + else + Base = Addr; + return true; +} + // Helper to detect unneeded and instructions on shift amounts. Called // from PatFrags in tablegen. bool RISCVDAGToDAGISel::isUnneededShiftMask(SDNode *N, unsigned Width) const { diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfoVSDPatterns.td b/llvm/lib/Target/RISCV/RISCVInstrInfoVSDPatterns.td --- a/llvm/lib/Target/RISCV/RISCVInstrInfoVSDPatterns.td +++ b/llvm/lib/Target/RISCV/RISCVInstrInfoVSDPatterns.td @@ -39,6 +39,8 @@ def SplatPat_simm5 : ComplexPattern; def SplatPat_uimm5 : ComplexPattern; +def RVVBaseAddr : ComplexPattern; + class SwapHelper { dag Value = !con(Prefix, !if(swap, B, A), !if(swap, A, B), Suffix); } @@ -48,23 +50,16 @@ int sew, LMULInfo vlmul, OutPatFrag avl, - RegisterClass reg_rs1, VReg reg_class> { defvar load_instr = !cast("PseudoVLE"#sew#"_V_"#vlmul.MX); defvar store_instr = !cast("PseudoVSE"#sew#"_V_"#vlmul.MX); // Load - def : Pat<(type (load reg_rs1:$rs1)), - (load_instr reg_rs1:$rs1, avl, sew)>; + def : Pat<(type (load RVVBaseAddr:$rs1)), + (load_instr RVVBaseAddr:$rs1, avl, sew)>; // Store - def : Pat<(store type:$rs2, reg_rs1:$rs1), - (store_instr reg_class:$rs2, reg_rs1:$rs1, avl, sew)>; -} - -multiclass VPatUSLoadStoreSDNodes { - foreach vti = AllVectors in - defm "" : VPatUSLoadStoreSDNode; + def : Pat<(store type:$rs2, RVVBaseAddr:$rs1), + (store_instr reg_class:$rs2, RVVBaseAddr:$rs1, avl, sew)>; } class VPatBinarySDNode_VV; -defm "" : VPatUSLoadStoreSDNodes; +foreach vti = AllVectors in + defm "" : VPatUSLoadStoreSDNode; // 12.1. Vector Single-Width Integer Add and Subtract defm "" : VPatBinarySDNode_VV_VX_VI;