[llvm] [RISCV] Match strided vector bases in RISCVGatherScatterLowering (PR #93972)

Luke Lau via llvm-commits llvm-commits at lists.llvm.org
Fri May 31 11:04:49 PDT 2024


================
@@ -349,6 +349,22 @@ RISCVGatherScatterLowering::determineBaseAndStride(Instruction *Ptr,
 
   SmallVector<Value *, 2> Ops(GEP->operands());
 
+  // If the base pointer is a vector, check if it's strided.
+  if (GEP->getPointerOperand()->getType()->isVectorTy()) {
+    auto [BaseBase, Stride] = determineBaseAndStride(
+        cast<Instruction>(GEP->getPointerOperand()), Builder);
+    // If GEP's offset is scalar then we can add it to the base pointer's base.
+    auto IsScalar = [](Value *Idx) { return !Idx->getType()->isVectorTy(); };
+    if (BaseBase && all_of(GEP->indices(), IsScalar)) {
+      Builder.SetInsertPoint(GEP);
+      SmallVector<Value *> Indices(GEP->indices());
+      Value *OffsetBase =
+          Builder.CreateGEP(GEP->getSourceElementType(), BaseBase, Indices, "",
----------------
lukel97 wrote:

The old GEP might still lie around if it has another user, do we still need to take the name?

https://github.com/llvm/llvm-project/pull/93972


More information about the llvm-commits mailing list