[llvm] dc8e2ea - [VPlan] Add tests for VPlanVerifier (NFC).

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 24 06:58:41 PST 2023


Author: Florian Hahn
Date: 2023-01-24T14:58:22Z
New Revision: dc8e2ea92953a6d286feedfb821e99fcec081ad1

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

LOG: [VPlan] Add tests for VPlanVerifier (NFC).

Extra test coverage suggested for D140514.

Added: 
    llvm/unittests/Transforms/Vectorize/VPlanVerifierTest.cpp

Modified: 
    llvm/unittests/Transforms/Vectorize/CMakeLists.txt

Removed: 
    


################################################################################
diff  --git a/llvm/unittests/Transforms/Vectorize/CMakeLists.txt b/llvm/unittests/Transforms/Vectorize/CMakeLists.txt
index dd411a2c1f6c0..4f8dd577d0aa7 100644
--- a/llvm/unittests/Transforms/Vectorize/CMakeLists.txt
+++ b/llvm/unittests/Transforms/Vectorize/CMakeLists.txt
@@ -11,6 +11,7 @@ add_llvm_unittest(VectorizeTests
   VPDomTreeTest.cpp
   VPlanHCFGTest.cpp
   VPlanSlpTest.cpp
+  VPlanVerifierTest.cpp
   )
 
 set_property(TARGET VectorizeTests PROPERTY FOLDER "Tests/UnitTests/TransformsTests")

diff  --git a/llvm/unittests/Transforms/Vectorize/VPlanVerifierTest.cpp b/llvm/unittests/Transforms/Vectorize/VPlanVerifierTest.cpp
new file mode 100644
index 0000000000000..b41a8a26fd655
--- /dev/null
+++ b/llvm/unittests/Transforms/Vectorize/VPlanVerifierTest.cpp
@@ -0,0 +1,112 @@
+//===- llvm/unittests/Transforms/Vectorize/VPlanVerifierTest.cpp ----------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "../lib/Transforms/Vectorize/VPlanVerifier.h"
+#include "../lib/Transforms/Vectorize/VPlan.h"
+#include "llvm/IR/Instruction.h"
+#include "llvm/IR/Instructions.h"
+#include "gtest/gtest.h"
+
+using namespace llvm;
+
+namespace {
+TEST(VPVerifierTest, VPInstructionUseBeforeDefSameBB) {
+  VPInstruction *DefI = new VPInstruction(Instruction::Add, {});
+  VPInstruction *UseI = new VPInstruction(Instruction::Sub, {DefI});
+
+  VPBasicBlock *VPBB1 = new VPBasicBlock();
+  VPBB1->appendRecipe(UseI);
+  VPBB1->appendRecipe(DefI);
+
+  VPlan Plan;
+  Plan.setEntry(VPBB1);
+
+#if GTEST_HAS_STREAM_REDIRECTION
+  ::testing::internal::CaptureStderr();
+#endif
+  EXPECT_FALSE(VPlanVerifier::verifyPlanIsValid(Plan));
+#if GTEST_HAS_STREAM_REDIRECTION
+  EXPECT_STREQ("Use before def!\n",
+               ::testing::internal::GetCapturedStderr().c_str());
+#endif
+}
+
+TEST(VPVerifierTest, VPInstructionUseBeforeDefDifferentBB) {
+  VPInstruction *DefI = new VPInstruction(Instruction::Add, {});
+  VPInstruction *UseI = new VPInstruction(Instruction::Sub, {DefI});
+  auto *CanIV = new VPCanonicalIVPHIRecipe(UseI, {});
+  VPInstruction *BranchOnCond =
+      new VPInstruction(VPInstruction::BranchOnCond, {CanIV});
+
+  VPBasicBlock *VPBB1 = new VPBasicBlock();
+  VPBasicBlock *VPBB2 = new VPBasicBlock();
+
+  VPBB1->appendRecipe(UseI);
+  VPBB2->appendRecipe(CanIV);
+  VPBB2->appendRecipe(DefI);
+  VPBB2->appendRecipe(BranchOnCond);
+
+  VPRegionBlock *R1 = new VPRegionBlock(VPBB2, VPBB2, "R1");
+  VPBlockUtils::connectBlocks(VPBB1, R1);
+
+  VPlan Plan;
+  Plan.setEntry(VPBB1);
+
+  // TODO: UseI uses DefI but DefI does not dominate UseI. Currently missed by
+  // the verifier.
+#if GTEST_HAS_STREAM_REDIRECTION
+  ::testing::internal::CaptureStderr();
+#endif
+  EXPECT_TRUE(VPlanVerifier::verifyPlanIsValid(Plan));
+#if GTEST_HAS_STREAM_REDIRECTION
+  EXPECT_STREQ("", ::testing::internal::GetCapturedStderr().c_str());
+#endif
+}
+
+TEST(VPVerifierTest, VPBlendUseBeforeDefDifferentBB) {
+  LLVMContext C;
+  IntegerType *Int32 = IntegerType::get(C, 32);
+  auto *Phi = PHINode::Create(Int32, 1);
+
+  VPInstruction *I1 = new VPInstruction(Instruction::Add, {});
+  VPInstruction *DefI = new VPInstruction(Instruction::Add, {});
+  auto *CanIV = new VPCanonicalIVPHIRecipe(I1, {});
+  VPInstruction *BranchOnCond =
+      new VPInstruction(VPInstruction::BranchOnCond, {CanIV});
+  auto *Blend = new VPBlendRecipe(Phi, {DefI});
+
+  VPBasicBlock *VPBB1 = new VPBasicBlock();
+  VPBasicBlock *VPBB2 = new VPBasicBlock();
+  VPBasicBlock *VPBB3 = new VPBasicBlock();
+  VPBasicBlock *VPBB4 = new VPBasicBlock();
+
+  VPBB1->appendRecipe(I1);
+  VPBB2->appendRecipe(CanIV);
+  VPBB3->appendRecipe(Blend);
+  VPBB4->appendRecipe(DefI);
+  VPBB4->appendRecipe(BranchOnCond);
+
+  VPBlockUtils::connectBlocks(VPBB2, VPBB3);
+  VPBlockUtils::connectBlocks(VPBB3, VPBB4);
+  VPRegionBlock *R1 = new VPRegionBlock(VPBB2, VPBB4, "R1");
+  VPBlockUtils::connectBlocks(VPBB1, R1);
+
+  VPlan Plan;
+  Plan.setEntry(VPBB1);
+
+  // TODO: Blend uses Def but Def does not dominate Blend. Currently missed by
+  // the verifier.
+#if GTEST_HAS_STREAM_REDIRECTION
+  ::testing::internal::CaptureStderr();
+#endif
+  EXPECT_TRUE(VPlanVerifier::verifyPlanIsValid(Plan));
+#if GTEST_HAS_STREAM_REDIRECTION
+  EXPECT_STREQ("", ::testing::internal::GetCapturedStderr().c_str());
+#endif
+}
+} // namespace


        


More information about the llvm-commits mailing list