[llvm] [LoadStoreVectorizer] Fill gaps in load/store chains to enable vectorization (PR #159388)

Drew Kersnar via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 5 07:46:44 PST 2025


================
@@ -831,7 +914,60 @@ std::vector<Chain> Vectorizer::splitChainByAlignment(Chain &C) {
         }
       }
 
-      if (!IsAllowedAndFast(Alignment)) {
+      // Attempt to extend non-power-of-2 chains to the next power of 2.
+      Chain ExtendingLoadsStores;
+      if (NumVecElems < TargetVF && NumVecElems % 2 != 0 && VecElemBits >= 8) {
+        // TargetVF may be a lot higher than NumVecElems,
+        // so only extend to the next power of 2.
+        assert(VecElemBits % 8 == 0);
+        unsigned VecElemBytes = VecElemBits / 8;
+        unsigned NewNumVecElems = PowerOf2Ceil(NumVecElems);
+        unsigned NewSizeBytes = VecElemBytes * NewNumVecElems;
+
+        assert(NewNumVecElems <= TargetVF);
----------------
dakersnar wrote:

> Is this because TargetVF is always a power of 2?
Yes, that is what is being implicitly asserted. I suppose it would be safer to add that assumption to the if condition that wraps this whole optimization, in case that is not true for a target.

>  If NewNumVecElems < TargetVF, then will vectorization be legal?
Yes, for example, you could extend a chain of 3 loads to a chain of 4 even if the target supports up to a VF of 8.

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


More information about the llvm-commits mailing list