[llvm] ba2dacd - [VPlan] Print use and definition in verifier on violation.

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Tue May 13 01:52:20 PDT 2025


Author: Florian Hahn
Date: 2025-05-13T09:52:02+01:00
New Revision: ba2dacd276522d483a38f786cce66b16a349446b

URL: https://github.com/llvm/llvm-project/commit/ba2dacd276522d483a38f786cce66b16a349446b
DIFF: https://github.com/llvm/llvm-project/commit/ba2dacd276522d483a38f786cce66b16a349446b.diff

LOG: [VPlan] Print use and definition in verifier on violation.

Improves the error message when a use comes before the def by including
the use and def, when print utilities are available.

Added: 
    

Modified: 
    llvm/lib/Transforms/Vectorize/VPlanVerifier.cpp
    llvm/unittests/Transforms/Vectorize/VPlanVerifierTest.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Vectorize/VPlanVerifier.cpp b/llvm/lib/Transforms/Vectorize/VPlanVerifier.cpp
index b1528c401b459..b8205545a4f5e 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanVerifier.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanVerifier.cpp
@@ -16,6 +16,7 @@
 #include "VPlan.h"
 #include "VPlanCFG.h"
 #include "VPlanDominatorTree.h"
+#include "VPlanHelpers.h"
 #include "llvm/ADT/SmallPtrSet.h"
 #include "llvm/ADT/TypeSwitch.h"
 
@@ -230,17 +231,22 @@ bool VPlanVerifier::verifyVPBasicBlock(const VPBasicBlock *VPBB) {
         // If the user is in the same block, check it comes after R in the
         // block.
         if (UI->getParent() == VPBB) {
-          if (RecipeNumbering[UI] < RecipeNumbering[&R]) {
-            errs() << "Use before def!\n";
-            return false;
-          }
-          continue;
+          if (RecipeNumbering[UI] >= RecipeNumbering[&R])
+            continue;
+        } else {
+          if (VPDT.dominates(VPBB, UI->getParent()))
+            continue;
         }
 
-        if (!VPDT.dominates(VPBB, UI->getParent())) {
-          errs() << "Use before def!\n";
-          return false;
-        }
+        errs() << "Use before def!\n";
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+        VPSlotTracker Tracker(VPBB->getPlan());
+        UI->print(errs(), "  ", Tracker);
+        errs() << "\n  before\n";
+        R.print(errs(), "  ", Tracker);
+        errs() << "\n";
+#endif
+        return false;
       }
     }
     if (const auto *EVL = dyn_cast<VPInstruction>(&R)) {

diff  --git a/llvm/unittests/Transforms/Vectorize/VPlanVerifierTest.cpp b/llvm/unittests/Transforms/Vectorize/VPlanVerifierTest.cpp
index 95088bed68e98..84b7e33146811 100644
--- a/llvm/unittests/Transforms/Vectorize/VPlanVerifierTest.cpp
+++ b/llvm/unittests/Transforms/Vectorize/VPlanVerifierTest.cpp
@@ -41,9 +41,17 @@ TEST_F(VPVerifierTest, VPInstructionUseBeforeDefSameBB) {
 #endif
   EXPECT_FALSE(verifyVPlanIsValid(Plan));
 #if GTEST_HAS_STREAM_REDIRECTION
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+  EXPECT_STREQ("Use before def!\n"
+               "  EMIT vp<%1> = sub vp<%2>\n"
+               "  before\n"
+               "  EMIT vp<%2> = add ir<0>\n",
+               ::testing::internal::GetCapturedStderr().c_str());
+#else
   EXPECT_STREQ("Use before def!\n",
                ::testing::internal::GetCapturedStderr().c_str());
 #endif
+#endif
 }
 
 TEST_F(VPVerifierTest, VPInstructionUseBeforeDefDifferentBB) {
@@ -72,9 +80,17 @@ TEST_F(VPVerifierTest, VPInstructionUseBeforeDefDifferentBB) {
 #endif
   EXPECT_FALSE(verifyVPlanIsValid(Plan));
 #if GTEST_HAS_STREAM_REDIRECTION
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+  EXPECT_STREQ("Use before def!\n"
+               "  EMIT vp<%1> = sub vp<%3>\n"
+               "  before\n"
+               "  EMIT vp<%3> = add ir<0>\n",
+               ::testing::internal::GetCapturedStderr().c_str());
+#else
   EXPECT_STREQ("Use before def!\n",
                ::testing::internal::GetCapturedStderr().c_str());
 #endif
+#endif
 }
 
 TEST_F(VPVerifierTest, VPBlendUseBeforeDefDifferentBB) {
@@ -112,8 +128,16 @@ TEST_F(VPVerifierTest, VPBlendUseBeforeDefDifferentBB) {
 #endif
   EXPECT_FALSE(verifyVPlanIsValid(Plan));
 #if GTEST_HAS_STREAM_REDIRECTION
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+  EXPECT_STREQ("Use before def!\n"
+               "  BLEND ir<<badref>> = vp<%2>\n"
+               "  before\n"
+               "  EMIT vp<%2> = add ir<0>\n",
+               ::testing::internal::GetCapturedStderr().c_str());
+#else
   EXPECT_STREQ("Use before def!\n",
                ::testing::internal::GetCapturedStderr().c_str());
+#endif
 #endif
 
   delete Phi;


        


More information about the llvm-commits mailing list