[llvm] 77ccd85 - [IVDesc] Check loop-preheader for loop-legality when pass-remarks enabled (#166310)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 9 07:02:23 PST 2026
Author: hanbeom
Date: 2026-02-10T00:02:13+09:00
New Revision: 77ccd853d0ec9a96f49c8017030b653ab82bcb45
URL: https://github.com/llvm/llvm-project/commit/77ccd853d0ec9a96f49c8017030b653ab82bcb45
DIFF: https://github.com/llvm/llvm-project/commit/77ccd853d0ec9a96f49c8017030b653ab82bcb45.diff
LOG: [IVDesc] Check loop-preheader for loop-legality when pass-remarks enabled (#166310)
When `-pass-remarks=loop-vectorize` is specified, the subsequent logic
is executed to display detailed debug messages even if no PreHeader
exists in the loop.
Therefore, an assert occurs when the `getLoopPreHeader()` function is
called. This commit resolves that issue.
Fixed: #165377
Added:
llvm/test/Transforms/LoopVectorize/loop-legality-checks-remarks.ll
Modified:
llvm/lib/Analysis/IVDescriptors.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/IVDescriptors.cpp b/llvm/lib/Analysis/IVDescriptors.cpp
index 2a213d6be1470..cf8567673e5e1 100644
--- a/llvm/lib/Analysis/IVDescriptors.cpp
+++ b/llvm/lib/Analysis/IVDescriptors.cpp
@@ -276,11 +276,12 @@ bool RecurrenceDescriptor::AddReductionVar(
if (isMinMaxReductionPhiWithUsersOutsideReductionChain(Phi, Kind, TheLoop,
RedDes))
return true;
-
// Obtain the reduction start value from the value that comes from the loop
// preheader.
- Value *RdxStart = Phi->getIncomingValueForBlock(TheLoop->getLoopPreheader());
+ if (!TheLoop->getLoopPreheader())
+ return false;
+ Value *RdxStart = Phi->getIncomingValueForBlock(TheLoop->getLoopPreheader());
// ExitInstruction is the single value which is used outside the loop.
// We only allow for a single reduction value to be used outside the loop.
// This includes users of the reduction, variables (which form a cycle
@@ -1600,6 +1601,9 @@ bool InductionDescriptor::isInductionPHI(
assert(Phi->getParent() == TheLoop->getHeader() &&
"Invalid Phi node, not present in loop header");
+ if (!TheLoop->getLoopPreheader())
+ return false;
+
Value *StartValue =
Phi->getIncomingValueForBlock(TheLoop->getLoopPreheader());
diff --git a/llvm/test/Transforms/LoopVectorize/loop-legality-checks-remarks.ll b/llvm/test/Transforms/LoopVectorize/loop-legality-checks-remarks.ll
new file mode 100644
index 0000000000000..bd2231d9e47b1
--- /dev/null
+++ b/llvm/test/Transforms/LoopVectorize/loop-legality-checks-remarks.ll
@@ -0,0 +1,24 @@
+; RUN: opt < %s -passes=loop-vectorize -pass-remarks=loop-vectorize -debug -disable-output 2>&1 | FileCheck %s
+; REQUIRES: asserts
+
+; Make sure LV legal bails out when the loop doesn't have a legal pre-header.
+; CHECK-LABEL: 'not_exist_preheader'
+; CHECK: LV: Not vectorizing: Loop doesn't have a legal pre-header.
+define void @not_exist_preheader(ptr %dst, ptr %arg) nounwind uwtable {
+entry:
+ indirectbr ptr %arg, [label %exit.0, label %loop]
+
+exit.0:
+ ret void
+
+loop:
+ %iv = phi i32 [0, %entry], [%iv.next, %loop]
+ %gep = getelementptr inbounds i32, ptr %dst, i32 %iv
+ store i32 0, ptr %gep, align 4
+ %iv.next = add i32 %iv, 1
+ %cmp = icmp slt i32 %iv.next, 4
+ br i1 %cmp, label %loop, label %exit
+
+exit:
+ ret void
+}
More information about the llvm-commits
mailing list