Skip to content

Conversation

@dtcxzyw
Copy link
Member

@dtcxzyw dtcxzyw commented Oct 16, 2025

As discussed in #111544 (comment), large special member functions in APFloat/ConstantFPRange prevent function inlining and cause compile-time regression. This patch moves them into the cpp file.

Compile-time improvement (with #111544): https://llvm-compile-time-tracker.com/compare.php?from=3df3102ff95af6724e684520d7b75d9f288ceeed&to=e438bae71d1fd55640d942b9ad795de2f60e44f2&stat=instructions:u

On llvm-opt-benchmark, this patch yields about -0.1% improvement: #111544 (comment)

I also did some experiments about outlining special member functions of APInt::Storage: https://llvm-compile-time-tracker.com/compare.php?from=f4359301c033694d36865c7560714164d2050240&to=65f55cdd23a625bd7dc51ae723916b8b5a80c5f8&stat=instructions:u

@dtcxzyw dtcxzyw requested review from arsenm and nikic October 16, 2025 16:15
@dtcxzyw dtcxzyw added the floating-point Floating-point math label Oct 16, 2025
@llvmbot
Copy link
Member

llvmbot commented Oct 16, 2025

@llvm/pr-subscribers-llvm-ir

Author: Yingwei Zheng (dtcxzyw)

Changes

As discussed in #111544 (comment), large special member functions in APFloat/ConstantFPRange prevent function inlining and cause compile-time regression. This patch moves them into the cpp file.

Compile-time improvement (with #111544): https://llvm-compile-time-tracker.com/compare.php?from=3df3102ff95af6724e684520d7b75d9f288ceeed&to=e438bae71d1fd55640d942b9ad795de2f60e44f2&stat=instructions:u

On llvm-opt-benchmark, this patch yields about -0.1% improvement: #111544 (comment)

I also did some experiments about outlining special member functions of APInt::Storage. But the result looks worse: https://llvm-compile-time-tracker.com/compare.php?from=f4359301c033694d36865c7560714164d2050240&to=169ea86103c921b4149a54da526394ec4ac1f138&stat=instructions:u


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

2 Files Affected:

  • (modified) llvm/include/llvm/IR/ConstantFPRange.h (+5)
  • (modified) llvm/lib/IR/ConstantFPRange.cpp (+6)
diff --git a/llvm/include/llvm/IR/ConstantFPRange.h b/llvm/include/llvm/IR/ConstantFPRange.h
index e772095a266cc..577a46fa91570 100644
--- a/llvm/include/llvm/IR/ConstantFPRange.h
+++ b/llvm/include/llvm/IR/ConstantFPRange.h
@@ -59,6 +59,11 @@ class [[nodiscard]] ConstantFPRange {
   /// Initialize a range to hold the single specified value.
   LLVM_ABI explicit ConstantFPRange(const APFloat &Value);
 
+  LLVM_ABI ConstantFPRange(const ConstantFPRange &Other);
+  LLVM_ABI ConstantFPRange(ConstantFPRange &&Other);
+  LLVM_ABI ConstantFPRange &operator=(const ConstantFPRange &Other);
+  LLVM_ABI ConstantFPRange &operator=(ConstantFPRange &&Other);
+
   /// Initialize a range of values explicitly.
   /// Note: If \p LowerVal is greater than \p UpperVal, please use the canonical
   /// form [Inf, -Inf].
diff --git a/llvm/lib/IR/ConstantFPRange.cpp b/llvm/lib/IR/ConstantFPRange.cpp
index 5b8768601928e..5f05c51158d01 100644
--- a/llvm/lib/IR/ConstantFPRange.cpp
+++ b/llvm/lib/IR/ConstantFPRange.cpp
@@ -57,6 +57,12 @@ ConstantFPRange::ConstantFPRange(const APFloat &Value)
   }
 }
 
+ConstantFPRange::ConstantFPRange(const ConstantFPRange &Other) = default;
+ConstantFPRange::ConstantFPRange(ConstantFPRange &&Other) = default;
+ConstantFPRange &
+ConstantFPRange::operator=(const ConstantFPRange &Other) = default;
+ConstantFPRange &ConstantFPRange::operator=(ConstantFPRange &&Other) = default;
+
 // We treat that -0 is less than 0 here.
 static APFloat::cmpResult strictCompare(const APFloat &LHS,
                                         const APFloat &RHS) {

@dtcxzyw dtcxzyw marked this pull request as draft October 18, 2025 14:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

floating-point Floating-point math llvm:ir

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants