[llvm] [VPlan] Recognise single-scalar VPInstructions in isUniformAcrossVFsAndUFs (PR #194674)

Madhur Amilkanthwar via llvm-commits llvm-commits at lists.llvm.org
Mon May 4 02:53:58 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/3] [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 51b04f663c0e1bc812c8aa2fc80691da89ebcb5a 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/3] 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()));
 }
 

>From 9653784708d5dd0f6ace85c95fff1e23a6d6c1de Mon Sep 17 00:00:00 2001
From: Madhur Amilkanthwar <madhura at nvidia.com>
Date: Mon, 4 May 2026 02:51:24 -0700
Subject: [PATCH 3/3] fixup! add tests for isVectorToScalar and isSingleScalar
 with operands

---
 llvm/unittests/Transforms/Vectorize/VPlanTest.cpp | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/llvm/unittests/Transforms/Vectorize/VPlanTest.cpp b/llvm/unittests/Transforms/Vectorize/VPlanTest.cpp
index 39e01c4641967..06c42d3685466 100644
--- a/llvm/unittests/Transforms/Vectorize/VPlanTest.cpp
+++ b/llvm/unittests/Transforms/Vectorize/VPlanTest.cpp
@@ -1793,13 +1793,20 @@ using VPUtilsTest = VPlanTestBase;
 TEST_F(VPUtilsTest, IsUniformAcrossVFsAndUFsForSingleScalarOpcodes) {
   VPlan &Plan = getPlan();
 
+  // isSingleScalar opcode without operands.
   std::unique_ptr<VPInstruction> VScale(
       new VPInstruction(VPInstruction::VScale, {}));
   EXPECT_TRUE(vputils::isUniformAcrossVFsAndUFs(VScale.get()));
 
+  // isSingleScalar opcode with a uniform operand.
   std::unique_ptr<VPInstruction> EVL(
       new VPInstruction(VPInstruction::ExplicitVectorLength, {&Plan.getVF()}));
   EXPECT_TRUE(vputils::isUniformAcrossVFsAndUFs(EVL.get()));
+
+  // isVectorToScalar opcode with a uniform operand.
+  std::unique_ptr<VPInstruction> FirstActiveLane(
+      new VPInstruction(VPInstruction::FirstActiveLane, {&Plan.getVF()}));
+  EXPECT_TRUE(vputils::isUniformAcrossVFsAndUFs(FirstActiveLane.get()));
 }
 
 #if defined(GTEST_HAS_DEATH_TEST) && !defined(NDEBUG)



More information about the llvm-commits mailing list