Skip to content

Commit cf9ba40

Browse files
committed
[BypassSlowDivision] Explicitly create bit mask
Explicitly create the high bit mask using getBitsSetFrom() instead of inverting an integer. This avoids relying on implicit truncation.
1 parent 80fc9bc commit cf9ba40

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

llvm/lib/Transforms/Utils/BypassSlowDivision.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -335,10 +335,10 @@ Value *FastDivInsertionTask::insertOperandRuntimeCheck(Value *Op1, Value *Op2) {
335335
else
336336
OrV = Op1 ? Op1 : Op2;
337337

338-
// BitMask is inverted to check if the operands are
339-
// larger than the bypass type
340-
uint64_t BitMask = ~BypassType->getBitMask();
341-
Value *AndV = Builder.CreateAnd(OrV, BitMask);
338+
// Check whether the operands are larger than the bypass type.
339+
Value *AndV = Builder.CreateAnd(
340+
OrV, APInt::getBitsSetFrom(OrV->getType()->getIntegerBitWidth(),
341+
BypassType->getBitWidth()));
342342

343343
// Compare operand values
344344
Value *ZeroV = ConstantInt::getSigned(getSlowType(), 0);

0 commit comments

Comments
 (0)