[llvm] [SLP] NFC: Simplify CandidateVFs initialization (PR #144882)

Alexey Bataev via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 19 06:57:49 PDT 2025


================
@@ -21207,13 +21211,11 @@ bool SLPVectorizerPass::vectorizeStores(
         continue;
       }
 
-      unsigned Sz = 1 + Log2_32(MaxVF) - Log2_32(MinVF);
-      SmallVector<unsigned> CandidateVFs(Sz + (NonPowerOf2VF > 0 ? 1 : 0));
-      unsigned Size = MinVF;
-      for (unsigned &VF : reverse(CandidateVFs)) {
-        VF = Size > MaxVF ? NonPowerOf2VF : Size;
-        Size *= 2;
-      }
+      SmallVector<unsigned> CandidateVFs;
+      for (unsigned VF = std::max(MaxVF, NonPowerOf2VF); VF >= MinVF;
+           VF = divideCeil(VF, 2))
+        CandidateVFs.push_back(VF);
+
----------------
alexey-bataev wrote:

> The reason for making this change is because I found it really hard to understand:
> 
> * What the min-max range of resulting VFs are.
> * Whether the list of VF goes from high to low, or low to high.
> 

The code is pretty small, so I don't see much difference 

> The parts that I found specifically difficult to follow are:
> 
> * Calculation for the size of the SmallVector. This requires adding and subtracting logarithm of min/max VF, and a conditional `+ 1`. I'm also not sure what the value is of passing a size to the constructor. By default this list will be small and SmallVector already allocates a minimum size which is likely to be big enough in practice.

It highly depends on the target. True for something like X86 to ARM NEON, false for others


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


More information about the llvm-commits mailing list