[llvm] cf9ba40 - [BypassSlowDivision] Explicitly create bit mask

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 9 07:14:12 PST 2025


Author: Nikita Popov
Date: 2025-12-09T16:13:59+01:00
New Revision: cf9ba401e3fb2a9c3c728f1a0f49e75db372e704

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

LOG: [BypassSlowDivision] Explicitly create bit mask

Explicitly create the high bit mask using getBitsSetFrom() instead
of inverting an integer. This avoids relying on implicit
truncation.

Added: 
    

Modified: 
    llvm/lib/Transforms/Utils/BypassSlowDivision.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Utils/BypassSlowDivision.cpp b/llvm/lib/Transforms/Utils/BypassSlowDivision.cpp
index 9f6d89e97180f..66d8fea251cbd 100644
--- a/llvm/lib/Transforms/Utils/BypassSlowDivision.cpp
+++ b/llvm/lib/Transforms/Utils/BypassSlowDivision.cpp
@@ -335,10 +335,10 @@ Value *FastDivInsertionTask::insertOperandRuntimeCheck(Value *Op1, Value *Op2) {
   else
     OrV = Op1 ? Op1 : Op2;
 
-  // BitMask is inverted to check if the operands are
-  // larger than the bypass type
-  uint64_t BitMask = ~BypassType->getBitMask();
-  Value *AndV = Builder.CreateAnd(OrV, BitMask);
+  // Check whether the operands are larger than the bypass type.
+  Value *AndV = Builder.CreateAnd(
+      OrV, APInt::getBitsSetFrom(OrV->getType()->getIntegerBitWidth(),
+                                 BypassType->getBitWidth()));
 
   // Compare operand values
   Value *ZeroV = ConstantInt::getSigned(getSlowType(), 0);


        


More information about the llvm-commits mailing list