summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms
diff options
context:
space:
mode:
authorDan Gohman <gohman@apple.com>2008-05-02 21:30:02 +0000
committerDan Gohman <gohman@apple.com>2008-05-02 21:30:02 +0000
commit1962c2be6ac54422702e583ce6320112f884ab7b (patch)
treee3141b98f507c46f21da0c93d40e7cfbf0f44244 /llvm/lib/Transforms
parent82b9e962747789d971cbd2f1e7b01686d769bbb1 (diff)
downloadbcm5719-llvm-1962c2be6ac54422702e583ce6320112f884ab7b.tar.gz
bcm5719-llvm-1962c2be6ac54422702e583ce6320112f884ab7b.zip
Fix a mistake in the computation of leading zeros for udiv.
llvm-svn: 50591
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r--llvm/lib/Transforms/Scalar/InstructionCombining.cpp8
1 files changed, 5 insertions, 3 deletions
diff --git a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
index ce052f724e8..d7a5f7be5c5 100644
--- a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
@@ -780,7 +780,7 @@ void InstCombiner::ComputeMaskedBits(Value *V, const APInt &Mask,
case Instruction::UDiv: {
// For the purposes of computing leading zeros we can conservatively
// treat a udiv as a logical right shift by the power of 2 known to
- // be greater than the denominator.
+ // be less than the denominator.
APInt AllOnes = APInt::getAllOnesValue(BitWidth);
ComputeMaskedBits(I->getOperand(0),
AllOnes, KnownZero2, KnownOne2, Depth+1);
@@ -790,8 +790,10 @@ void InstCombiner::ComputeMaskedBits(Value *V, const APInt &Mask,
KnownZero2.clear();
ComputeMaskedBits(I->getOperand(1),
AllOnes, KnownZero2, KnownOne2, Depth+1);
- LeadZ = std::min(BitWidth,
- LeadZ + BitWidth - KnownOne2.countLeadingZeros());
+ unsigned RHSUnknownLeadingOnes = KnownOne2.countLeadingZeros();
+ if (RHSUnknownLeadingOnes != BitWidth)
+ LeadZ = std::min(BitWidth,
+ LeadZ + BitWidth - RHSUnknownLeadingOnes - 1);
KnownZero = APInt::getHighBitsSet(BitWidth, LeadZ) & Mask;
return;
OpenPOWER on IntegriCloud