[llvm] 796efa8 - [Float2Int] Fix pessimization in the MinBW calculation. (#86051)

via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 21 11:09:43 PDT 2024


Author: Craig Topper
Date: 2024-03-21T11:09:40-07:00
New Revision: 796efa8cd5800a42eb8362564be64f3d72512a05

URL: https://github.com/llvm/llvm-project/commit/796efa8cd5800a42eb8362564be64f3d72512a05
DIFF: https://github.com/llvm/llvm-project/commit/796efa8cd5800a42eb8362564be64f3d72512a05.diff

LOG: [Float2Int] Fix pessimization in the MinBW calculation. (#86051)

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 use ConstantRange::getMinSignedBits.

I'm still not sure if the +1 is needed after the getMinSignedBits call.

Added: 
    

Modified: 
    llvm/lib/Transforms/Scalar/Float2Int.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Scalar/Float2Int.cpp b/llvm/lib/Transforms/Scalar/Float2Int.cpp
index ccca8bcc1a56ac..de8c05d5689f5b 100644
--- a/llvm/lib/Transforms/Scalar/Float2Int.cpp
+++ b/llvm/lib/Transforms/Scalar/Float2Int.cpp
@@ -359,9 +359,7 @@ 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()) +
-                     1;
+    unsigned MinBW = R.getMinSignedBits() + 1;
     LLVM_DEBUG(dbgs() << "F2I: MinBitwidth=" << MinBW << ", R: " << R << "\n");
 
     // If we've run off the realms of the exactly representable integers,


        


More information about the llvm-commits mailing list