Skip to content

Commit

Permalink
Add unittests
Browse files Browse the repository at this point in the history
  • Loading branch information
Mel-Chen committed Jul 19, 2024
1 parent 741d6c0 commit 86f96f1
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions llvm/unittests/IR/VPIntrinsicTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,59 @@ TEST_F(VPIntrinsicTest, IntrinsicIDRoundTrip) {
ASSERT_NE(FullTripCounts, 0u);
}

/// Check that going from intrinsic to VP intrinsic and back results in the same
/// intrinsic.
TEST_F(VPIntrinsicTest, IntrinsicToVPRoundTrip) {
unsigned FullTripCounts = 0;
Intrinsic::ID IntrinsicID = Intrinsic::not_intrinsic + 1;
for (; IntrinsicID < Intrinsic::num_intrinsics; IntrinsicID++) {
Intrinsic::ID VPID = VPIntrinsic::getForIntrinsic(IntrinsicID);
// No equivalent VP intrinsic available.
if (VPID == Intrinsic::not_intrinsic)
continue;

// Return itself if passed intrinsic ID is VP intrinsic.
if (VPIntrinsic::isVPIntrinsic(IntrinsicID)) {
ASSERT_EQ(IntrinsicID, VPID);
continue;
}

std::optional<Intrinsic::ID> RoundTripIntrinsicID =
VPIntrinsic::getFunctionalIntrinsicIDForVP(VPID);
// No equivalent non-predicated intrinsic available.
if (!RoundTripIntrinsicID)
continue;

ASSERT_EQ(*RoundTripIntrinsicID, IntrinsicID);
++FullTripCounts;
}
ASSERT_NE(FullTripCounts, 0u);
}

/// Check that going from VP intrinsic to equivalent non-predicated intrinsic
/// and back results in the same intrinsic.
TEST_F(VPIntrinsicTest, VPToNonPredIntrinsicRoundTrip) {
std::unique_ptr<Module> M = createVPDeclarationModule();
assert(M);

unsigned FullTripCounts = 0;
for (const auto &VPDecl : *M) {
auto VPID = VPDecl.getIntrinsicID();
std::optional<Intrinsic::ID> NonPredID =
VPIntrinsic::getFunctionalIntrinsicIDForVP(VPID);

// No equivalent non-predicated intrinsic available
if (!NonPredID)
continue;

Intrinsic::ID RoundTripVPID = VPIntrinsic::getForIntrinsic(*NonPredID);

ASSERT_EQ(RoundTripVPID, VPID);
++FullTripCounts;
}
ASSERT_NE(FullTripCounts, 0u);
}

/// Check that VPIntrinsic::getDeclarationForParams works.
TEST_F(VPIntrinsicTest, VPIntrinsicDeclarationForParams) {
std::unique_ptr<Module> M = createVPDeclarationModule();
Expand Down

0 comments on commit 86f96f1

Please sign in to comment.