[llvm] [SLP]Try detect strided loads, if any pointer op require extraction. (PR #101668)

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 5 07:18:23 PDT 2024


================
@@ -4617,12 +4617,21 @@ BoUpSLP::LoadsState BoUpSLP::canVectorizeLoads(
       // 3. The loads are ordered, or number of unordered loads <=
       // MaxProfitableUnorderedLoads, or loads are in reversed order.
       // (this check is to avoid extra costs for very expensive shuffles).
-      if (IsPossibleStrided && (((Sz > MinProfitableStridedLoads ||
-                                  (static_cast<unsigned>(std::abs(*Diff)) <=
-                                       MaxProfitableLoadStride * Sz &&
-                                   isPowerOf2_32(std::abs(*Diff)))) &&
-                                 static_cast<unsigned>(std::abs(*Diff)) > Sz) ||
-                                *Diff == -(static_cast<int>(Sz) - 1))) {
+      // 4. Any pointer operand is an instruction with the users outside of the
+      // current graph (for masked gathers extra extractelement instructions
+      // might be required).
+      if (IsPossibleStrided &&
+          (((Sz > MinProfitableStridedLoads ||
+             (static_cast<unsigned>(std::abs(*Diff)) <=
+                  MaxProfitableLoadStride * Sz &&
+              isPowerOf2_32(std::abs(*Diff)))) &&
+            static_cast<unsigned>(std::abs(*Diff)) > Sz) ||
+           *Diff == -(static_cast<int>(Sz) - 1) ||
+           any_of(PointerOps, [&](Value *V) {
+             return isa<Instruction>(V) && any_of(V->users(), [&](User *U) {
+                      return !getTreeEntry(U) && !MustGather.contains(U);
+                    });
----------------
RKSimon wrote:

(observation not request) - its very tricky to check the logic in this now, but I'm not sure whether its worth pulling this out into a helper.

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


More information about the llvm-commits mailing list