[llvm] [ConstantFPRange][UnitTests] Disable exhaustive testing in debug builds (PR #111276)

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 7 17:30:00 PDT 2024


https://github.com/dtcxzyw updated https://github.com/llvm/llvm-project/pull/111276

>From 34541bc242135cbfb71b207c97a3d517774f77a0 Mon Sep 17 00:00:00 2001
From: Yingwei Zheng <dtcxzyw2333 at gmail.com>
Date: Sun, 6 Oct 2024 11:37:17 +0800
Subject: [PATCH 1/2] [ConstantFPRange][UnitTests] Disable exhaustive testing
 in debug builds

---
 llvm/unittests/IR/ConstantFPRangeTest.cpp | 29 +++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/llvm/unittests/IR/ConstantFPRangeTest.cpp b/llvm/unittests/IR/ConstantFPRangeTest.cpp
index 158d08f9b77a0a..faeb04a83bb927 100644
--- a/llvm/unittests/IR/ConstantFPRangeTest.cpp
+++ b/llvm/unittests/IR/ConstantFPRangeTest.cpp
@@ -15,6 +15,31 @@ using namespace llvm;
 
 namespace {
 
+// Exhaustive testing is expensive in debug builds, so we only do it when
+// optimizations are enabled. We don't use EXPENSIVE_CHECKS here because it's
+// not enabled by default in optimized builds.
+#if defined(__GNUC__)
+// GCC and GCC-compatible compilers define __OPTIMIZE__ when optimizations are
+// enabled.
+#if defined(__OPTIMIZE__)
+#define LLVM_ENABLE_CFR_EXPENSIVE_CHECKS 1
+#else
+#define LLVM_ENABLE_CFR_EXPENSIVE_CHECKS 0
+#endif
+#elif defined(_MSC_VER)
+// MSVC doesn't have a predefined macro indicating if optimizations are enabled.
+// Use _DEBUG instead. This macro actually corresponds to the choice between
+// debug and release CRTs, but it is a reasonable proxy.
+#if defined(_DEBUG)
+#define LLVM_ENABLE_CFR_EXPENSIVE_CHECKS 0
+#else
+#define LLVM_ENABLE_CFR_EXPENSIVE_CHECKS 1
+#endif
+#else
+// Otherwise, for an unknown compiler, assume this is an optimized build.
+#define LLVM_ENABLE_CFR_EXPENSIVE_CHECKS 1
+#endif
+
 class ConstantFPRangeTest : public ::testing::Test {
 protected:
   static const fltSemantics &Sem;
@@ -435,6 +460,7 @@ TEST_F(ConstantFPRangeTest, FPClassify) {
   EXPECT_EQ(SomePos.getSignBit(), false);
   EXPECT_EQ(SomeNeg.getSignBit(), true);
 
+#if LLVM_ENABLE_CFR_EXPENSIVE_CHECKS
   EnumerateConstantFPRanges(
       [](const ConstantFPRange &CR) {
         unsigned Mask = fcNone;
@@ -458,6 +484,7 @@ TEST_F(ConstantFPRangeTest, FPClassify) {
         EXPECT_EQ(Mask, CR.classify()) << CR;
       },
       /*Exhaustive=*/true);
+#endif
 }
 
 TEST_F(ConstantFPRangeTest, Print) {
@@ -500,6 +527,7 @@ TEST_F(ConstantFPRangeTest, MismatchedSemantics) {
 #endif
 
 TEST_F(ConstantFPRangeTest, makeAllowedFCmpRegion) {
+#if LLVM_ENABLE_CFR_EXPENSIVE_CHECKS
   for (auto Pred : FCmpInst::predicates()) {
     EnumerateConstantFPRanges(
         [Pred](const ConstantFPRange &CR) {
@@ -529,6 +557,7 @@ TEST_F(ConstantFPRangeTest, makeAllowedFCmpRegion) {
         },
         /*Exhaustive=*/false);
   }
+#endif
 }
 
 } // anonymous namespace

>From 23f094177917076d44138e06755eff4f89c179be Mon Sep 17 00:00:00 2001
From: Yingwei Zheng <dtcxzyw2333 at gmail.com>
Date: Tue, 8 Oct 2024 08:29:18 +0800
Subject: [PATCH 2/2] [ConstantFPRange] Guard exhaustive checks by
 `EXPENSIVE_CHECKS`

---
 llvm/unittests/IR/ConstantFPRangeTest.cpp | 58 ++++++++++++-----------
 1 file changed, 31 insertions(+), 27 deletions(-)

diff --git a/llvm/unittests/IR/ConstantFPRangeTest.cpp b/llvm/unittests/IR/ConstantFPRangeTest.cpp
index faeb04a83bb927..3c6e468b05bfda 100644
--- a/llvm/unittests/IR/ConstantFPRangeTest.cpp
+++ b/llvm/unittests/IR/ConstantFPRangeTest.cpp
@@ -15,31 +15,6 @@ using namespace llvm;
 
 namespace {
 
-// Exhaustive testing is expensive in debug builds, so we only do it when
-// optimizations are enabled. We don't use EXPENSIVE_CHECKS here because it's
-// not enabled by default in optimized builds.
-#if defined(__GNUC__)
-// GCC and GCC-compatible compilers define __OPTIMIZE__ when optimizations are
-// enabled.
-#if defined(__OPTIMIZE__)
-#define LLVM_ENABLE_CFR_EXPENSIVE_CHECKS 1
-#else
-#define LLVM_ENABLE_CFR_EXPENSIVE_CHECKS 0
-#endif
-#elif defined(_MSC_VER)
-// MSVC doesn't have a predefined macro indicating if optimizations are enabled.
-// Use _DEBUG instead. This macro actually corresponds to the choice between
-// debug and release CRTs, but it is a reasonable proxy.
-#if defined(_DEBUG)
-#define LLVM_ENABLE_CFR_EXPENSIVE_CHECKS 0
-#else
-#define LLVM_ENABLE_CFR_EXPENSIVE_CHECKS 1
-#endif
-#else
-// Otherwise, for an unknown compiler, assume this is an optimized build.
-#define LLVM_ENABLE_CFR_EXPENSIVE_CHECKS 1
-#endif
-
 class ConstantFPRangeTest : public ::testing::Test {
 protected:
   static const fltSemantics &Sem;
@@ -460,7 +435,7 @@ TEST_F(ConstantFPRangeTest, FPClassify) {
   EXPECT_EQ(SomePos.getSignBit(), false);
   EXPECT_EQ(SomeNeg.getSignBit(), true);
 
-#if LLVM_ENABLE_CFR_EXPENSIVE_CHECKS
+#if defined(EXPENSIVE_CHECKS)
   EnumerateConstantFPRanges(
       [](const ConstantFPRange &CR) {
         unsigned Mask = fcNone;
@@ -527,7 +502,36 @@ TEST_F(ConstantFPRangeTest, MismatchedSemantics) {
 #endif
 
 TEST_F(ConstantFPRangeTest, makeAllowedFCmpRegion) {
-#if LLVM_ENABLE_CFR_EXPENSIVE_CHECKS
+  EXPECT_EQ(ConstantFPRange::makeAllowedFCmpRegion(
+                FCmpInst::FCMP_OLE,
+                ConstantFPRange::getNonNaN(APFloat(1.0), APFloat(2.0))),
+            ConstantFPRange::getNonNaN(APFloat::getInf(Sem, /*Negative=*/true),
+                                       APFloat(2.0)));
+  EXPECT_EQ(
+      ConstantFPRange::makeAllowedFCmpRegion(
+          FCmpInst::FCMP_OLT,
+          ConstantFPRange::getNonNaN(APFloat(1.0),
+                                     APFloat::getInf(Sem, /*Negative=*/false))),
+      ConstantFPRange::getNonNaN(APFloat::getInf(Sem, /*Negative=*/true),
+                                 APFloat::getLargest(Sem, /*Negative=*/false)));
+  EXPECT_EQ(
+      ConstantFPRange::makeAllowedFCmpRegion(
+          FCmpInst::FCMP_OGT,
+          ConstantFPRange::getNonNaN(APFloat::getZero(Sem, /*Negative=*/true),
+                                     APFloat(2.0))),
+      ConstantFPRange::getNonNaN(APFloat::getSmallest(Sem, /*Negative=*/false),
+                                 APFloat::getInf(Sem, /*Negative=*/false)));
+  EXPECT_EQ(ConstantFPRange::makeAllowedFCmpRegion(
+                FCmpInst::FCMP_OGE,
+                ConstantFPRange::getNonNaN(APFloat(1.0), APFloat(2.0))),
+            ConstantFPRange::getNonNaN(
+                APFloat(1.0), APFloat::getInf(Sem, /*Negative=*/false)));
+  EXPECT_EQ(ConstantFPRange::makeAllowedFCmpRegion(
+                FCmpInst::FCMP_OEQ,
+                ConstantFPRange::getNonNaN(APFloat(1.0), APFloat(2.0))),
+            ConstantFPRange::getNonNaN(APFloat(1.0), APFloat(2.0)));
+
+#if defined(EXPENSIVE_CHECKS)
   for (auto Pred : FCmpInst::predicates()) {
     EnumerateConstantFPRanges(
         [Pred](const ConstantFPRange &CR) {



More information about the llvm-commits mailing list