[llvm] [LV] Fix crash when forced UserVF and EpilogueVF are ignored (PR #218282)
Hassnaa Hamdi via llvm-commits
llvm-commits at lists.llvm.org
Sun Aug 23 12:43:56 PDT 2026
https://github.com/hassnaaHamdi created https://github.com/llvm/llvm-project/pull/218282
`computeBestVF()` assumes/asserts that there should be only 2 vplans as
long as there is a vplan for `UserVF` and when `EpilogueVF` is forced.
It doesn't consider the case when those VFs are ignored because of invalid costs.
This patch removes the assert and add a check for the vplan size.
>From 9ed41a85c9968f9b34f158e3b349490dcf9181d3 Mon Sep 17 00:00:00 2001
From: Hassnaa Hamdi <hassnaa.hamdi at arm.com>
Date: Sun, 23 Aug 2026 19:55:58 +0100
Subject: [PATCH] [LV] Fix crash when forced UserVF and EpilogueVF are ignored
computeBestVF() assumes/asserts that there should be 2 vplans as long
as there is a vplan for UserVF and when EpilogueVF is forced.
It doesn't consider the case when those VFs are ignored because of
invalid costs.
This patch removes the assert and add a check for the vplan size.
---
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp | 3 +--
llvm/test/Transforms/LoopVectorize/AArch64/scalable-alloca.ll | 2 +-
2 files changed, 2 insertions(+), 3 deletions(-)
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index bf0bb98eb75b8..c3e39f5adf175 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -5820,8 +5820,7 @@ LoopVectorizationPlanner::computeBestVF() {
return {VectorizationFactor(FirstPlan.getSingleVF(), 0, 0), &FirstPlan};
}
- if (hasPlanWithVF(UserVF) && hasForcedEpilogueVF()) {
- assert(VPlans.size() == 2 && "Must have exactly 2 VPlans built");
+ if (hasPlanWithVF(UserVF) && hasForcedEpilogueVF() && VPlans.size() == 2) {
assert(VPlans[0]->getSingleVF() == UserVF &&
"expected second plan to be for the forced UserVF");
assert(VPlans[1]->getSingleVF() == EpilogueVectorizationForceVF &&
diff --git a/llvm/test/Transforms/LoopVectorize/AArch64/scalable-alloca.ll b/llvm/test/Transforms/LoopVectorize/AArch64/scalable-alloca.ll
index 73384c7d383ba..336c9f876bec9 100644
--- a/llvm/test/Transforms/LoopVectorize/AArch64/scalable-alloca.ll
+++ b/llvm/test/Transforms/LoopVectorize/AArch64/scalable-alloca.ll
@@ -1,4 +1,4 @@
-; RUN: opt -S -passes=loop-vectorize -mattr=+sve -mtriple aarch64-unknown-linux-gnu -force-vector-width=2 -pass-remarks-analysis=loop-vectorize -pass-remarks-missed=loop-vectorize < %s 2>%t | FileCheck %s
+; RUN: opt -S -passes=loop-vectorize -mattr=+sve -mtriple aarch64-unknown-linux-gnu -force-vector-width=2 -epilogue-vectorization-force-VF=2 -pass-remarks-analysis=loop-vectorize -pass-remarks-missed=loop-vectorize < %s 2>%t | FileCheck %s
; RUN: FileCheck %s --check-prefix=CHECK-REMARKS < %t
; CHECK-REMARKS: UserVF ignored because of invalid costs.
More information about the llvm-commits
mailing list