[llvm] [Float2Int] Fix pessimization in the MinBW calculation. (PR #86051)

via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 20 17:58:29 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-transforms

Author: Craig Topper (topperc)

<details>
<summary>Changes</summary>

The MinBW was being calculated using the significant bits of the upper and lower bounds. The upper bound is 1 past the last value in the range so I don't think it should be included. Instead get the min and max signed values from the range and use the significant bits of those.

I'm still not sure if the +1 is needed after the std::max.

I haven't investigated if its possible to add a test for this. We only look at whether the MinBW is > 32 right now. So the ranges need to be carefully crafted to see a difference.

CC: @<!-- -->AtariDreams 

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


1 Files Affected:

- (modified) llvm/lib/Transforms/Scalar/Float2Int.cpp (+2-2) 


``````````diff
diff --git a/llvm/lib/Transforms/Scalar/Float2Int.cpp b/llvm/lib/Transforms/Scalar/Float2Int.cpp
index ccca8bcc1a56ac..47042d96b46571 100644
--- a/llvm/lib/Transforms/Scalar/Float2Int.cpp
+++ b/llvm/lib/Transforms/Scalar/Float2Int.cpp
@@ -359,8 +359,8 @@ bool Float2IntPass::validateAndTransform() {
 
     // The number of bits required is the maximum of the upper and
     // lower limits, plus one so it can be signed.
-    unsigned MinBW = std::max(R.getLower().getSignificantBits(),
-                              R.getUpper().getSignificantBits()) +
+    unsigned MinBW = std::max(R.getSignedMin().getSignificantBits(),
+                              R.getSignedMax().getSignificantBits()) +
                      1;
     LLVM_DEBUG(dbgs() << "F2I: MinBitwidth=" << MinBW << ", R: " << R << "\n");
 

``````````

</details>


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


More information about the llvm-commits mailing list