[llvm] [VPlan] Recognise single-scalar VPInstructions in isUniformAcrossVFsAndUFs (PR #194674)
Madhur Amilkanthwar via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 29 06:22:07 PDT 2026
https://github.com/madhur13490 updated https://github.com/llvm/llvm-project/pull/194674
>From 7143b885fa2f2ab73585f83afeb73f965752ca7e Mon Sep 17 00:00:00 2001
From: Madhur Amilkanthwar <madhura at nvidia.com>
Date: Wed, 29 Apr 2026 02:31:33 -0700
Subject: [PATCH 1/2] [VPlan] Recognise single-scalar VPInstructions in
isUniformAcrossVFsAndUFs
The VPInstruction case of vputils::isUniformAcrossVFsAndUFs only
consults preservesUniformity(opcode), missing single-scalar opcodes
like VScale, ExplicitVectorLength, and ResumeForEpilogue. Mirror the
structure of vputils::isSingleScalar's VPInstruction case: also
accept VPI->isSingleScalar() and VPI->isVectorToScalar(), gated by
the existing all_of(operands, isUniformAcrossVFsAndUFs) recursion.
---
llvm/lib/Transforms/Vectorize/VPlanUtils.cpp | 3 ++-
llvm/unittests/Transforms/Vectorize/VPlanTest.cpp | 15 +++++++++++++++
2 files changed, 17 insertions(+), 1 deletion(-)
diff --git a/llvm/lib/Transforms/Vectorize/VPlanUtils.cpp b/llvm/lib/Transforms/Vectorize/VPlanUtils.cpp
index 0cb64b66e5ccd..3261605933742 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanUtils.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanUtils.cpp
@@ -429,7 +429,8 @@ bool vputils::isUniformAcrossVFsAndUFs(VPValue *V) {
all_of(R->operands(), isUniformAcrossVFsAndUFs);
})
.Case([](const VPInstruction *VPI) {
- return preservesUniformity(VPI->getOpcode()) &&
+ return (VPI->isSingleScalar() || VPI->isVectorToScalar() ||
+ preservesUniformity(VPI->getOpcode())) &&
all_of(VPI->operands(), isUniformAcrossVFsAndUFs);
})
.Case([](const VPWidenCastRecipe *R) {
diff --git a/llvm/unittests/Transforms/Vectorize/VPlanTest.cpp b/llvm/unittests/Transforms/Vectorize/VPlanTest.cpp
index a1ddda7eda969..94435fb734836 100644
--- a/llvm/unittests/Transforms/Vectorize/VPlanTest.cpp
+++ b/llvm/unittests/Transforms/Vectorize/VPlanTest.cpp
@@ -10,6 +10,7 @@
#include "../lib/Transforms/Vectorize/VPlan.h"
#include "../lib/Transforms/Vectorize/VPlanCFG.h"
#include "../lib/Transforms/Vectorize/VPlanHelpers.h"
+#include "../lib/Transforms/Vectorize/VPlanUtils.h"
#include "VPlanTestBase.h"
#include "llvm/ADT/DepthFirstIterator.h"
#include "llvm/ADT/PostOrderIterator.h"
@@ -1787,6 +1788,20 @@ TEST_F(VPInstructionTest, VPSymbolicValueMaterialization) {
EXPECT_TRUE(Plan.getVF().isMaterialized());
}
+using VPUtilsTest = VPlanTestBase;
+
+TEST_F(VPUtilsTest, IsUniformAcrossVFsAndUFsForSingleScalarOpcodes) {
+ VPlan &Plan = getPlan();
+
+ std::unique_ptr<VPInstruction> VScale(
+ new VPInstruction(VPInstruction::VScale, {}));
+ EXPECT_TRUE(vputils::isUniformAcrossVFsAndUFs(VScale.get()));
+
+ std::unique_ptr<VPInstruction> EVL(new VPInstruction(
+ VPInstruction::ExplicitVectorLength, {&Plan.getVF()}));
+ EXPECT_TRUE(vputils::isUniformAcrossVFsAndUFs(EVL.get()));
+}
+
#if defined(GTEST_HAS_DEATH_TEST) && !defined(NDEBUG)
TEST_F(VPInstructionTest, VPSymbolicValueAddUserAfterMaterialization) {
VPlan &Plan = getPlan();
>From 71755f5892892b07b1f1de287130e0e8ea18be68 Mon Sep 17 00:00:00 2001
From: Madhur Amilkanthwar <madhura at nvidia.com>
Date: Wed, 29 Apr 2026 06:21:36 -0700
Subject: [PATCH 2/2] fixup! fix formatting errors.
---
llvm/unittests/Transforms/Vectorize/VPlanTest.cpp | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/llvm/unittests/Transforms/Vectorize/VPlanTest.cpp b/llvm/unittests/Transforms/Vectorize/VPlanTest.cpp
index 94435fb734836..39e01c4641967 100644
--- a/llvm/unittests/Transforms/Vectorize/VPlanTest.cpp
+++ b/llvm/unittests/Transforms/Vectorize/VPlanTest.cpp
@@ -1797,8 +1797,8 @@ TEST_F(VPUtilsTest, IsUniformAcrossVFsAndUFsForSingleScalarOpcodes) {
new VPInstruction(VPInstruction::VScale, {}));
EXPECT_TRUE(vputils::isUniformAcrossVFsAndUFs(VScale.get()));
- std::unique_ptr<VPInstruction> EVL(new VPInstruction(
- VPInstruction::ExplicitVectorLength, {&Plan.getVF()}));
+ std::unique_ptr<VPInstruction> EVL(
+ new VPInstruction(VPInstruction::ExplicitVectorLength, {&Plan.getVF()}));
EXPECT_TRUE(vputils::isUniformAcrossVFsAndUFs(EVL.get()));
}
More information about the llvm-commits
mailing list