[llvm] 4b0df11 - [VPlan] Fix invalid IR in unit test input, run verifier.

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 22 13:12:24 PDT 2023


Author: Florian Hahn
Date: 2023-09-22T21:12:09+01:00
New Revision: 4b0df112daa1d967abeca1473c5e81e21d9af36a

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

LOG: [VPlan] Fix invalid IR in unit test input, run verifier.

Some tests were passing invalid IR to the VPlan construction logic. Fix
the invalid IR and run the verifier on the input to avoid issues in the
future.

Added: 
    

Modified: 
    llvm/unittests/Transforms/Vectorize/VPlanSlpTest.cpp
    llvm/unittests/Transforms/Vectorize/VPlanTestBase.h

Removed: 
    


################################################################################
diff  --git a/llvm/unittests/Transforms/Vectorize/VPlanSlpTest.cpp b/llvm/unittests/Transforms/Vectorize/VPlanSlpTest.cpp
index 986f57a23d4304a..70951f3a656a0b5 100644
--- a/llvm/unittests/Transforms/Vectorize/VPlanSlpTest.cpp
+++ b/llvm/unittests/Transforms/Vectorize/VPlanSlpTest.cpp
@@ -686,7 +686,7 @@ TEST_F(VPlanSlpTest, testInstrsInDifferentBBs) {
       "  br label %for.body\n"
       "for.body:                                         ; preds = %for.body, "
       "%entry\n"
-      "  %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]\n"
+      "  %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %bb2 ]\n"
       "  %A0 = getelementptr inbounds %struct.Test, %struct.Test* %A, i64 "
       "%indvars.iv, i32 0\n"
       "  %vA0 = load i32, i32* %A0, align 4\n"
@@ -749,7 +749,7 @@ TEST_F(VPlanSlpTest, testInstrsInDifferentBBs2) {
       "  br label %for.body\n"
       "for.body:                                         ; preds = %for.body, "
       "%entry\n"
-      "  %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]\n"
+      "  %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %bb2 ]\n"
       "  %A0 = getelementptr inbounds %struct.Test, %struct.Test* %A, i64 "
       "%indvars.iv, i32 0\n"
       "  %vA0 = load i32, i32* %A0, align 4\n"

diff  --git a/llvm/unittests/Transforms/Vectorize/VPlanTestBase.h b/llvm/unittests/Transforms/Vectorize/VPlanTestBase.h
index d9372174fdfa43a..6cd43f6803130aa 100644
--- a/llvm/unittests/Transforms/Vectorize/VPlanTestBase.h
+++ b/llvm/unittests/Transforms/Vectorize/VPlanTestBase.h
@@ -20,6 +20,7 @@
 #include "llvm/Analysis/TargetLibraryInfo.h"
 #include "llvm/AsmParser/Parser.h"
 #include "llvm/IR/Dominators.h"
+#include "llvm/IR/Verifier.h"
 #include "llvm/Support/SourceMgr.h"
 #include "gtest/gtest.h"
 
@@ -62,7 +63,9 @@ class VPlanTestBase : public testing::Test {
   }
 
   VPlanPtr buildHCFG(BasicBlock *LoopHeader) {
-    doAnalysis(*LoopHeader->getParent());
+    Function &F = *LoopHeader->getParent();
+    assert(!verifyFunction(F) && "input function must be valid");
+    doAnalysis(F);
 
     auto Plan = VPlan::createInitialVPlan(
         SE->getBackedgeTakenCount(LI->getLoopFor(LoopHeader)), *SE);
@@ -73,7 +76,9 @@ class VPlanTestBase : public testing::Test {
 
   /// Build the VPlan plain CFG for the loop starting from \p LoopHeader.
   VPlanPtr buildPlainCFG(BasicBlock *LoopHeader) {
-    doAnalysis(*LoopHeader->getParent());
+    Function &F = *LoopHeader->getParent();
+    assert(!verifyFunction(F) && "input function must be valid");
+    doAnalysis(F);
 
     auto Plan = VPlan::createInitialVPlan(
         SE->getBackedgeTakenCount(LI->getLoopFor(LoopHeader)), *SE);


        


More information about the llvm-commits mailing list