[llvm] [LV] Fix missing entry in willGenerateVectors (PR #136712)
Ramkumar Ramachandra via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 22 09:09:41 PDT 2025
https://github.com/artagnon updated https://github.com/llvm/llvm-project/pull/136712
>From dafa614df51f693f6289d2f88d9cf2d87f3c696f Mon Sep 17 00:00:00 2001
From: Ramkumar Ramachandra <ramkumar.ramachandra at codasip.com>
Date: Tue, 22 Apr 2025 16:26:02 +0100
Subject: [PATCH 1/2] [LV] Fix missing entry in willGenerateVectors
willGenerateVectors switches on opcodes of a recipe, but Histogram is
missing in the switch statement, which could cause a crash in some
cases. The crash was initially observed when developing another patch:
no test case is included with this patch, as the bug is evident.
---
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp | 1 +
1 file changed, 1 insertion(+)
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index 32c3435ccb38d..4f607f4732aba 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -4460,6 +4460,7 @@ static bool willGenerateVectors(VPlan &Plan, ElementCount VF,
case VPDef::VPWidenSelectSC:
case VPDef::VPBlendSC:
case VPDef::VPFirstOrderRecurrencePHISC:
+ case VPDef::VPHistogramSC:
case VPDef::VPWidenPHISC:
case VPDef::VPWidenIntOrFpInductionSC:
case VPDef::VPWidenPointerInductionSC:
>From 221e5112c57e786ecf4efa9bd3a7303c6bef8977 Mon Sep 17 00:00:00 2001
From: Ramkumar Ramachandra <ramkumar.ramachandra at codasip.com>
Date: Tue, 22 Apr 2025 17:08:28 +0100
Subject: [PATCH 2/2] [LV] Add test for crash
---
.../LoopVectorize/AArch64/sve2-histcnt.ll | 23 +++++++++++++++++++
1 file changed, 23 insertions(+)
diff --git a/llvm/test/Transforms/LoopVectorize/AArch64/sve2-histcnt.ll b/llvm/test/Transforms/LoopVectorize/AArch64/sve2-histcnt.ll
index 56cea996f3d80..0a2a41ccada3a 100644
--- a/llvm/test/Transforms/LoopVectorize/AArch64/sve2-histcnt.ll
+++ b/llvm/test/Transforms/LoopVectorize/AArch64/sve2-histcnt.ll
@@ -753,6 +753,29 @@ for.exit:
ret void
}
+; The histogram operation generates vectors. This example used to crash
+; due to a missing entry in a switch statement.
+define void @histogram_generates_vectors_crash(ptr %data_array) {
+entry:
+ br label %for.body
+
+for.body:
+ %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]
+ %gep.indices = getelementptr [1048576 x i32], ptr null, i64 %iv
+ %l.idx = load i32, ptr %gep.indices, align 4
+ %idxprom5 = sext i32 %l.idx to i64
+ %gep.bucket = getelementptr [1048576 x i32], ptr %data_array, i64 %idxprom5
+ %l.bucket = load i32, ptr %gep.bucket, align 4
+ %inc = add i32 %l.bucket, 0
+ store i32 %inc, ptr %gep.bucket, align 4
+ %iv.next = add i64 %iv, 1
+ %exitcond = icmp eq i64 %iv, 1
+ br i1 %exitcond, label %for.exit, label %for.body
+
+for.exit:
+ ret void
+}
+
attributes #0 = { "target-features"="+sve2" vscale_range(1,16) }
!0 = distinct !{!0, !1}
More information about the llvm-commits
mailing list