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

Sander de Smalen via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 19 05:49:45 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);
+
----------------
sdesmalen-arm 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 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.
* The `reverse` when iterating the values in `CandidateVFs` to initialise the VF seemed unnecessary.

I actually had to print the data in CandidateVFs to confirm the code did what I suspected it did :)

In the current code I think it is easier to see what the minimum and maximum values are (the loop starts either at `MaxVF` or `NonPowerOf2VF`, and ends at MinVF), and to understand the increment (it goes from high -> low, dividing by 2).

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


More information about the llvm-commits mailing list