diff --git a/llvm/unittests/IR/VPIntrinsicTest.cpp b/llvm/unittests/IR/VPIntrinsicTest.cpp index eab2850ca4e1e8..746f71acb877a3 100644 --- a/llvm/unittests/IR/VPIntrinsicTest.cpp +++ b/llvm/unittests/IR/VPIntrinsicTest.cpp @@ -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 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 M = createVPDeclarationModule(); + assert(M); + + unsigned FullTripCounts = 0; + for (const auto &VPDecl : *M) { + auto VPID = VPDecl.getIntrinsicID(); + std::optional 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 M = createVPDeclarationModule();