[llvm] [SLP] Account for GEP pointer-chain cost when root scalars feed load/store indices (PR #192726)

Alexey Bataev via llvm-commits llvm-commits at lists.llvm.org
Fri May 1 10:20:15 PDT 2026


================
@@ -18799,9 +18799,29 @@ InstructionCost BoUpSLP::getTreeCost(InstructionCost TreeCost,
   // On AArch64, this helps in fusing a mov instruction, associated with
   // extractelement, with fmul in the backend so that extractelement is free.
   SmallVector<std::tuple<Value *, User *, int>, 4> ScalarUserAndIdx;
+  bool AllUsersGEPSWithStoresLoads = true;
+  SmallBitVector UsedLanes(VectorizableTree.front()->getVectorFactor());
+  SmallVector<const Value *> Pointers;
+  Type *UserScalarTy = nullptr;
   for (ExternalUser &EU : ExternalUses) {
     ScalarUserAndIdx.emplace_back(EU.Scalar, EU.User, EU.Lane);
+    if (EU.E.Idx == 0) {
+      UsedLanes.set(EU.Lane);
+      auto *User = dyn_cast_if_present<GetElementPtrInst>(EU.User);
+      if (User && User->hasOneUse() &&
+          isa<LoadInst, StoreInst>(User->user_back())) {
+        Type *LocalTy = getValueType(User->user_back());
+        if (!UserScalarTy)
+          UserScalarTy = LocalTy;
+        else if (UserScalarTy != LocalTy)
+          AllUsersGEPSWithStoresLoads = false;
+        Pointers.push_back(User);
+      } else {
+        AllUsersGEPSWithStoresLoads = false;
+      }
----------------
alexey-bataev wrote:

Fixed

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


More information about the llvm-commits mailing list