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

via llvm-commits llvm-commits at lists.llvm.org
Sat Oct 5 20:40:31 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-ir

Author: Yingwei Zheng (dtcxzyw)

<details>
<summary>Changes</summary>

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.

Addresses comment https://github.com/llvm/llvm-project/pull/111056#issuecomment-2393951499.


---
Full diff: https://github.com/llvm/llvm-project/pull/111276.diff


1 Files Affected:

- (modified) llvm/unittests/IR/ConstantFPRangeTest.cpp (+29) 


``````````diff
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

``````````

</details>


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


More information about the llvm-commits mailing list