[llvm] [VPlan] Use VPlan::hasTailFolded in materializeConstantVectorTC. (PR #209502)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 14 07:47:47 PDT 2026
https://github.com/fhahn created https://github.com/llvm/llvm-project/pull/209502
The current checks in materializeConstantVectorTripCount miss tail-folded cases when vectorizing loops with fmax without fast-math flags. Use recently added hasTailFolded helper to ensure we always bail out on tail-folded loops.
Fixes https://github.com/llvm/llvm-project/issues/209159.
>From c3d199ffa9761ab7cd4f1c3e632b58c2974ffe7f Mon Sep 17 00:00:00 2001
From: Florian Hahn <flo at fhahn.com>
Date: Tue, 14 Jul 2026 13:26:40 +0100
Subject: [PATCH] [VPlan] Use VPlan::hasTailFolded in
materializeConstantVectorTC.
The current checks in materializeConstantVectorTripCount miss
tail-folded cases when vectorizing loops with fmax without fast-math
flags. Use recently added hasTailFolded helper to ensure we always bail
out on tail-folded loops.
Fixes https://github.com/llvm/llvm-project/issues/209159.
---
llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp | 2 +-
.../Transforms/LoopVectorize/fmax-without-fast-math-flags.ll | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
index 4da74c5146c52..1262d7dfa5f05 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
@@ -5451,7 +5451,7 @@ void VPlanTransforms::materializeConstantVectorTripCount(
// Skip cases for which the trip count may be non-trivial to materialize.
// I.e., when a scalar tail is absent - due to tail folding, or when a scalar
// tail is required.
- if (!Plan.hasScalarTail() ||
+ if (Plan.hasTailFolded() || !Plan.hasScalarTail() ||
Plan.getMiddleBlock()->getSingleSuccessor() ==
Plan.getScalarPreheader() ||
!isa<VPIRValue>(TC))
diff --git a/llvm/test/Transforms/LoopVectorize/fmax-without-fast-math-flags.ll b/llvm/test/Transforms/LoopVectorize/fmax-without-fast-math-flags.ll
index ef01bb29c1589..e04caf61609f4 100644
--- a/llvm/test/Transforms/LoopVectorize/fmax-without-fast-math-flags.ll
+++ b/llvm/test/Transforms/LoopVectorize/fmax-without-fast-math-flags.ll
@@ -819,7 +819,7 @@ define float @fmaxnum_constant_trip_count_tailfold(ptr %src) #0 {
; CHECK-NEXT: [[TMP25:%.*]] = fcmp uno <4 x float> [[TMP23]], [[TMP23]]
; CHECK-NEXT: [[TMP26:%.*]] = freeze <4 x i1> [[TMP25]]
; CHECK-NEXT: [[TMP27:%.*]] = call i1 @llvm.vector.reduce.or.v4i1(<4 x i1> [[TMP26]])
-; CHECK-NEXT: [[TMP28:%.*]] = icmp eq i64 [[INDEX_NEXT]], 28
+; CHECK-NEXT: [[TMP28:%.*]] = icmp eq i64 [[INDEX_NEXT]], 32
; CHECK-NEXT: [[TMP29:%.*]] = or i1 [[TMP27]], [[TMP28]]
; CHECK-NEXT: [[VEC_IND_NEXT]] = add nuw <4 x i8> [[VEC_IND]], splat (i8 4)
; CHECK-NEXT: br i1 [[TMP29]], label %[[MIDDLE_BLOCK:.*]], label %[[VECTOR_BODY]], !llvm.loop [[LOOP12:![0-9]+]]
More information about the llvm-commits
mailing list