[llvm] b159987 - [VP] Improve the VP intrinsic unittests

Simon Moll via llvm-commits llvm-commits at lists.llvm.org
Tue May 11 02:44:46 PDT 2021


Author: Simon Moll
Date: 2021-05-11T11:44:09+02:00
New Revision: b159987054e12ad9f5b5e373249cbdba90047b84

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

LOG: [VP] Improve the VP intrinsic unittests

Test that all VP intrinsics are tested.
Test intrinsic id -> opcode -> intrinsic id round tripping.
Test property scopes in the include/llvm/IR/VPIntrinsics.def file.

Reviewed By: frasercrmck

Differential Revision: https://reviews.llvm.org/D93534

Added: 
    

Modified: 
    llvm/unittests/IR/VPIntrinsicTest.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/unittests/IR/VPIntrinsicTest.cpp b/llvm/unittests/IR/VPIntrinsicTest.cpp
index b923e35efc32..c04ebf35fe65 100644
--- a/llvm/unittests/IR/VPIntrinsicTest.cpp
+++ b/llvm/unittests/IR/VPIntrinsicTest.cpp
@@ -8,6 +8,7 @@
 
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/AsmParser/Parser.h"
+#include "llvm/CodeGen/ISDOpcodes.h"
 #include "llvm/IR/Constants.h"
 #include "llvm/IR/IRBuilder.h"
 #include "llvm/IR/IntrinsicInst.h"
@@ -16,6 +17,7 @@
 #include "llvm/IR/Verifier.h"
 #include "llvm/Support/SourceMgr.h"
 #include "gtest/gtest.h"
+#include <sstream>
 
 using namespace llvm;
 
@@ -31,24 +33,65 @@ class VPIntrinsicTest : public testing::Test {
   SMDiagnostic Err;
 
   std::unique_ptr<Module> CreateVPDeclarationModule() {
-      return parseAssemblyString(
-" declare <8 x i32> @llvm.vp.add.v8i32(<8 x i32>, <8 x i32>, <8 x i1>, i32) "
-" declare <8 x i32> @llvm.vp.sub.v8i32(<8 x i32>, <8 x i32>, <8 x i1>, i32) "
-" declare <8 x i32> @llvm.vp.mul.v8i32(<8 x i32>, <8 x i32>, <8 x i1>, i32) "
-" declare <8 x i32> @llvm.vp.sdiv.v8i32(<8 x i32>, <8 x i32>, <8 x i1>, i32) "
-" declare <8 x i32> @llvm.vp.srem.v8i32(<8 x i32>, <8 x i32>, <8 x i1>, i32) "
-" declare <8 x i32> @llvm.vp.udiv.v8i32(<8 x i32>, <8 x i32>, <8 x i1>, i32) "
-" declare <8 x i32> @llvm.vp.urem.v8i32(<8 x i32>, <8 x i32>, <8 x i1>, i32) "
-" declare <8 x i32> @llvm.vp.and.v8i32(<8 x i32>, <8 x i32>, <8 x i1>, i32) "
-" declare <8 x i32> @llvm.vp.xor.v8i32(<8 x i32>, <8 x i32>, <8 x i1>, i32) "
-" declare <8 x i32> @llvm.vp.or.v8i32(<8 x i32>, <8 x i32>, <8 x i1>, i32) "
-" declare <8 x i32> @llvm.vp.ashr.v8i32(<8 x i32>, <8 x i32>, <8 x i1>, i32)  "
-" declare <8 x i32> @llvm.vp.lshr.v8i32(<8 x i32>, <8 x i32>, <8 x i1>, i32)  "
-" declare <8 x i32> @llvm.vp.shl.v8i32(<8 x i32>, <8 x i32>, <8 x i1>, i32) ",
-          Err, C);
+    const char *BinaryIntOpcodes[] = {"add",  "sub",  "mul", "sdiv", "srem",
+                                      "udiv", "urem", "and", "xor",  "or",
+                                      "ashr", "lshr", "shl"};
+    std::stringstream Str;
+    for (const char *BinaryIntOpcode : BinaryIntOpcodes)
+      Str << " declare <8 x i32> @llvm.vp." << BinaryIntOpcode
+          << ".v8i32(<8 x i32>, <8 x i32>, <8 x i1>, i32) ";
+
+    return parseAssemblyString(Str.str(), Err, C);
   }
 };
 
+/// Check that the property scopes include/llvm/IR/VPIntrinsics.def are closed.
+TEST_F(VPIntrinsicTest, VPIntrinsicsDefScopes) {
+  Optional<Intrinsic::ID> ScopeVPID;
+#define BEGIN_REGISTER_VP_INTRINSIC(VPID, ...)                                 \
+  ASSERT_FALSE(ScopeVPID.hasValue());                                          \
+  ScopeVPID = Intrinsic::VPID;
+#define END_REGISTER_VP_INTRINSIC(VPID)                                        \
+  ASSERT_TRUE(ScopeVPID.hasValue());                                           \
+  ASSERT_EQ(ScopeVPID.getValue(), Intrinsic::VPID);                            \
+  ScopeVPID = None;
+
+  Optional<ISD::NodeType> ScopeOPC;
+#define BEGIN_REGISTER_VP_SDNODE(SDOPC, ...)                                   \
+  ASSERT_FALSE(ScopeOPC.hasValue());                                           \
+  ScopeOPC = ISD::SDOPC;
+#define END_REGISTER_VP_SDNODE(SDOPC)                                          \
+  ASSERT_TRUE(ScopeOPC.hasValue());                                            \
+  ASSERT_EQ(ScopeOPC.getValue(), ISD::SDOPC);                                  \
+  ScopeOPC = None;
+#include "llvm/IR/VPIntrinsics.def"
+
+  ASSERT_FALSE(ScopeVPID.hasValue());
+  ASSERT_FALSE(ScopeOPC.hasValue());
+}
+
+/// Check that every VP intrinsic in the test module is recognized as a VP
+/// intrinsic.
+TEST_F(VPIntrinsicTest, VPModuleComplete) {
+  std::unique_ptr<Module> M = CreateVPDeclarationModule();
+  assert(M);
+
+  // Check that all @llvm.vp.* functions in the module are recognized vp
+  // intrinsics.
+  std::set<Intrinsic::ID> SeenIDs;
+  for (const auto &VPDecl : *M) {
+    ASSERT_TRUE(VPDecl.isIntrinsic());
+    ASSERT_TRUE(VPIntrinsic::IsVPIntrinsic(VPDecl.getIntrinsicID()));
+    SeenIDs.insert(VPDecl.getIntrinsicID());
+  }
+
+  // Check that every registered VP intrinsic has an instance in the test
+  // module.
+#define BEGIN_REGISTER_VP_INTRINSIC(VPID, ...)                                 \
+  ASSERT_TRUE(SeenIDs.count(Intrinsic::VPID));
+#include "llvm/IR/VPIntrinsics.def"
+}
+
 /// Check that VPIntrinsic:canIgnoreVectorLengthParam() returns true
 /// if the vector length parameter does not mask off any lanes.
 TEST_F(VPIntrinsicTest, CanIgnoreVectorLength) {
@@ -155,4 +198,27 @@ TEST_F(VPIntrinsicTest, OpcodeRoundTrip) {
   ASSERT_NE(FullTripCounts, 0u);
 }
 
+/// Check that going from VP intrinsic to Opcode and back results in the same
+/// intrinsic id.
+TEST_F(VPIntrinsicTest, IntrinsicIDRoundTrip) {
+  std::unique_ptr<Module> M = CreateVPDeclarationModule();
+  assert(M);
+
+  unsigned FullTripCounts = 0;
+  for (const auto &VPDecl : *M) {
+    auto VPID = VPDecl.getIntrinsicID();
+    unsigned OC = VPIntrinsic::GetFunctionalOpcodeForVP(VPID);
+
+    // no equivalent Opcode available
+    if (OC == Instruction::Call)
+      continue;
+
+    Intrinsic::ID RoundTripVPID = VPIntrinsic::GetForOpcode(OC);
+
+    ASSERT_EQ(RoundTripVPID, VPID);
+    ++FullTripCounts;
+  }
+  ASSERT_NE(FullTripCounts, 0u);
+}
+
 } // end anonymous namespace


        


More information about the llvm-commits mailing list