From 2a09b9acfb6fa14bbb08df3c13fb9fb0d09069d1 Mon Sep 17 00:00:00 2001 From: Serge Pavlov Date: Tue, 13 Aug 2019 05:21:18 +0000 Subject: [PATCH] Added unit tests to check supported rounding modes Also added fixed misspelled metadata name. Differential Revision: https://reviews.llvm.org/D66073 llvm-svn: 368650 --- llvm/lib/IR/IntrinsicInst.cpp | 2 +- llvm/unittests/IR/IRBuilderTest.cpp | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/llvm/lib/IR/IntrinsicInst.cpp b/llvm/lib/IR/IntrinsicInst.cpp index 7a042326f67f..b24711280072 100644 --- a/llvm/lib/IR/IntrinsicInst.cpp +++ b/llvm/lib/IR/IntrinsicInst.cpp @@ -143,7 +143,7 @@ ConstrainedFPIntrinsic::RoundingModeToStr(RoundingMode UseRounding) { RoundingStr = "round.upward"; break; case ConstrainedFPIntrinsic::rmTowardZero: - RoundingStr = "round.tozero"; + RoundingStr = "round.towardzero"; break; } return RoundingStr; diff --git a/llvm/unittests/IR/IRBuilderTest.cpp b/llvm/unittests/IR/IRBuilderTest.cpp index f73cf140e19f..f7a932e29190 100644 --- a/llvm/unittests/IR/IRBuilderTest.cpp +++ b/llvm/unittests/IR/IRBuilderTest.cpp @@ -187,6 +187,34 @@ TEST_F(IRBuilderTest, ConstrainedFP) { ASSERT_TRUE(CII->getExceptionBehavior() == ConstrainedFPIntrinsic::ebIgnore); ASSERT_TRUE(CII->getRoundingMode() == ConstrainedFPIntrinsic::rmUpward); + Builder.setDefaultConstrainedExcept(ConstrainedFPIntrinsic::ebIgnore); + Builder.setDefaultConstrainedRounding(ConstrainedFPIntrinsic::rmToNearest); + V = Builder.CreateFAdd(V, V); + CII = cast(V); + ASSERT_TRUE(CII->getExceptionBehavior() == ConstrainedFPIntrinsic::ebIgnore); + ASSERT_TRUE(CII->getRoundingMode() == ConstrainedFPIntrinsic::rmToNearest); + + Builder.setDefaultConstrainedExcept(ConstrainedFPIntrinsic::ebMayTrap); + Builder.setDefaultConstrainedRounding(ConstrainedFPIntrinsic::rmDownward); + V = Builder.CreateFAdd(V, V); + CII = cast(V); + ASSERT_TRUE(CII->getExceptionBehavior() == ConstrainedFPIntrinsic::ebMayTrap); + ASSERT_TRUE(CII->getRoundingMode() == ConstrainedFPIntrinsic::rmDownward); + + Builder.setDefaultConstrainedExcept(ConstrainedFPIntrinsic::ebStrict); + Builder.setDefaultConstrainedRounding(ConstrainedFPIntrinsic::rmTowardZero); + V = Builder.CreateFAdd(V, V); + CII = cast(V); + ASSERT_TRUE(CII->getExceptionBehavior() == ConstrainedFPIntrinsic::ebStrict); + ASSERT_TRUE(CII->getRoundingMode() == ConstrainedFPIntrinsic::rmTowardZero); + + Builder.setDefaultConstrainedExcept(ConstrainedFPIntrinsic::ebIgnore); + Builder.setDefaultConstrainedRounding(ConstrainedFPIntrinsic::rmDynamic); + V = Builder.CreateFAdd(V, V); + CII = cast(V); + ASSERT_TRUE(CII->getExceptionBehavior() == ConstrainedFPIntrinsic::ebIgnore); + ASSERT_TRUE(CII->getRoundingMode() == ConstrainedFPIntrinsic::rmDynamic); + // Now override the defaults. Call = Builder.CreateConstrainedFPBinOp( Intrinsic::experimental_constrained_fadd, V, V, nullptr, "", nullptr,