[llvm] [SLP][REVEC] Disable strided load if the source is vector instruction. (PR #99462)

Han-Kuan Chen via llvm-commits llvm-commits at lists.llvm.org
Sun Jul 28 23:19:26 PDT 2024


https://github.com/HanKuanChen updated https://github.com/llvm/llvm-project/pull/99462

>From ac6b2551ee0b902e783e596d897709d847a80cd2 Mon Sep 17 00:00:00 2001
From: Han-Kuan Chen <hankuan.chen at sifive.com>
Date: Tue, 9 Jul 2024 01:28:01 -0700
Subject: [PATCH] [SLP][REVEC] Disable strided load if the source is vector
 instruction.

---
 llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index ccb6734d5618c..0eb3f04e09070 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -4582,8 +4582,12 @@ BoUpSLP::LoadsState BoUpSLP::canVectorizeLoads(
     return LoadsState::Gather;
   }
 
+  // If ScalarTy is a FixedVectorType (when REVEC is enabled), it is hard for
+  // being strided load.
+  bool IsSourceScalarInstruction = !isa<FixedVectorType>(VL[0]->getType());
   Align CommonAlignment = computeCommonAlignment<LoadInst>(VL);
-  if (!IsSorted && Sz > MinProfitableStridedLoads && TTI->isTypeLegal(VecTy) &&
+  if (IsSourceScalarInstruction && !IsSorted &&
+      Sz > MinProfitableStridedLoads && TTI->isTypeLegal(VecTy) &&
       TTI->isLegalStridedLoadStore(VecTy, CommonAlignment) &&
       calculateRtStride(PointerOps, ScalarTy, *DL, *SE, Order))
     return LoadsState::StridedVectorize;
@@ -4606,7 +4610,8 @@ BoUpSLP::LoadsState BoUpSLP::canVectorizeLoads(
       if (static_cast<unsigned>(*Diff) == Sz - 1)
         return LoadsState::Vectorize;
       // Simple check if not a strided access - clear order.
-      bool IsPossibleStrided = *Diff % (Sz - 1) == 0;
+      bool IsPossibleStrided =
+          IsSourceScalarInstruction && (*Diff % (Sz - 1) == 0);
       // Try to generate strided load node if:
       // 1. Target with strided load support is detected.
       // 2. The number of loads is greater than MinProfitableStridedLoads,



More information about the llvm-commits mailing list