[llvm] [LV] Enable Histogram autovectorization by default (PR #158292)

via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 12 06:44:07 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-transforms

Author: Graham Hunter (huntergr-arm)

<details>
<summary>Changes</summary>

Enabling the feature by default in order to get further testing data.

There are a few loops in popular benchmarks where this kicks in,
but none of them are particularly hot, so I don't know if this is
beneficial on current hardware. But I haven't seen any regressions yet
either.

I'll take another look at the cost functions to see if there's improvements
I can make (as separate PRs).

---
Full diff: https://github.com/llvm/llvm-project/pull/158292.diff


2 Files Affected:

- (modified) llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp (+1-1) 
- (modified) llvm/test/Transforms/LoopVectorize/increment.ll (+1-3) 


``````````diff
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp
index ff35db14f7094..3c771492a1e92 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp
@@ -80,7 +80,7 @@ static cl::opt<LoopVectorizeHints::ScalableForceKind>
                 "cost is inconclusive.")));
 
 static cl::opt<bool> EnableHistogramVectorization(
-    "enable-histogram-loop-vectorization", cl::init(false), cl::Hidden,
+    "enable-histogram-loop-vectorization", cl::init(true), cl::Hidden,
     cl::desc("Enables autovectorization of some loops containing histograms"));
 
 /// Maximum vectorization interleave count.
diff --git a/llvm/test/Transforms/LoopVectorize/increment.ll b/llvm/test/Transforms/LoopVectorize/increment.ll
index b5af65a8c99c8..e71b50544ff67 100644
--- a/llvm/test/Transforms/LoopVectorize/increment.ll
+++ b/llvm/test/Transforms/LoopVectorize/increment.ll
@@ -33,13 +33,11 @@ define void @inc(i32 %n) nounwind uwtable noinline ssp {
   ret void
 }
 
-; Can't vectorize this loop because the access to A[X] is non-linear.
-;
 ;  for (i = 0; i < n; ++i) {
 ;    A[B[i]]++;
 ;
 ;CHECK-LABEL: @histogram(
-;CHECK-NOT: <4 x i32>
+;CHECK:  call void @llvm.experimental.vector.histogram.add.v4p0.i32(<4 x ptr> %{{.*}}, i32 1, <4 x i1> splat (i1 true))
 ;CHECK: ret i32
 define i32 @histogram(ptr nocapture noalias %A, ptr nocapture noalias %B, i32 %n) nounwind uwtable ssp {
 entry:

``````````

</details>


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


More information about the llvm-commits mailing list