Skip to content

Commit d85e347

Browse files
committed
[RISCV] Add a pass to recognize VLS strided loads/store from gather/scatter.
For strided accesses the loop vectorizer seems to prefer creating a vector induction variable with a start value of the form <i32 0, i32 1, i32 2, ...>. This value will be incremented each loop iteration by a splat constant equal to the length of the vector. Within the loop, arithmetic using splat values will be done on this vector induction variable to produce indices for a vector GEP. This pass attempts to dig through the arithmetic back to the phi to create a new scalar induction variable and a stride. We push all of the arithmetic out of the loop by folding it into the start, step, and stride values. Then we create a scalar GEP to use as the base pointer for a strided load or store using the computed stride. Loop strength reduce will run after this pass and can do some cleanups to the scalar GEP and induction variable. Reviewed By: frasercrmck Differential Revision: https://reviews.llvm.org/D107790
1 parent d001ab8 commit d85e347

11 files changed

+1630
-24
lines changed

llvm/include/llvm/IR/IntrinsicsRISCV.td

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1245,4 +1245,15 @@ let TargetPrefix = "riscv" in {
12451245
defm vsuxseg # nf : RISCVISegStore<nf>;
12461246
}
12471247

1248+
// Strided loads/stores for fixed vectors.
1249+
def int_riscv_masked_strided_load
1250+
: Intrinsic<[llvm_anyvector_ty],
1251+
[LLVMMatchType<0>, llvm_anyptr_ty,
1252+
llvm_anyint_ty, LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>],
1253+
[NoCapture<ArgIndex<1>>, IntrReadMem]>;
1254+
def int_riscv_masked_strided_store
1255+
: Intrinsic<[],
1256+
[llvm_anyvector_ty, llvm_anyptr_ty,
1257+
llvm_anyint_ty, LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>],
1258+
[NoCapture<ArgIndex<1>>, IntrWriteMem]>;
12481259
} // TargetPrefix = "riscv"

llvm/lib/Target/RISCV/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ add_llvm_target(RISCVCodeGen
2424
RISCVExpandAtomicPseudoInsts.cpp
2525
RISCVExpandPseudoInsts.cpp
2626
RISCVFrameLowering.cpp
27+
RISCVGatherScatterLowering.cpp
2728
RISCVInsertVSETVLI.cpp
2829
RISCVInstrInfo.cpp
2930
RISCVInstructionSelector.cpp
@@ -50,6 +51,7 @@ add_llvm_target(RISCVCodeGen
5051
SelectionDAG
5152
Support
5253
Target
54+
TransformUtils
5355
GlobalISel
5456

5557
ADD_TO_COMPONENT

llvm/lib/Target/RISCV/RISCV.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ bool LowerRISCVMachineOperandToMCOperand(const MachineOperand &MO,
3737

3838
FunctionPass *createRISCVISelDag(RISCVTargetMachine &TM);
3939

40+
FunctionPass *createRISCVGatherScatterLoweringPass();
41+
void initializeRISCVGatherScatterLoweringPass(PassRegistry &);
42+
4043
FunctionPass *createRISCVMergeBaseOffsetOptPass();
4144
void initializeRISCVMergeBaseOffsetOptPass(PassRegistry &);
4245

0 commit comments

Comments
 (0)