aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Transforms
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2006-02-13 22:41:07 +0000
committerChris Lattner <sabre@nondot.org>2006-02-13 22:41:07 +0000
commitf345fe4d9a48f91cb9b2d396234b928536f5fe00 (patch)
tree5fd998cf16e4c88845610a83b48ec4767c7a2b3d /lib/Transforms
parent3fcb664dbc0ac5c7f625416e9d0ebede4b370728 (diff)
downloadexternal_llvm-f345fe4d9a48f91cb9b2d396234b928536f5fe00.zip
external_llvm-f345fe4d9a48f91cb9b2d396234b928536f5fe00.tar.gz
external_llvm-f345fe4d9a48f91cb9b2d396234b928536f5fe00.tar.bz2
If any of the sign extended bits are demanded, the input sign bit is demanded
for a sign extension. This fixes InstCombine/2006-02-13-DemandedMiscompile.ll and Ptrdist/bc. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26152 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms')
-rw-r--r--lib/Transforms/Scalar/InstructionCombining.cpp12
1 files changed, 9 insertions, 3 deletions
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp
index 4247d8a..d42e0bb 100644
--- a/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/lib/Transforms/Scalar/InstructionCombining.cpp
@@ -889,15 +889,21 @@ bool InstCombiner::SimplifyDemandedBits(Value *V, uint64_t DemandedMask,
KnownZero |= NewBits;
} else {
// Sign extension.
- if (SimplifyDemandedBits(I->getOperand(0),
- DemandedMask & SrcTy->getIntegralTypeMask(),
+ uint64_t InSignBit = 1ULL << (SrcTy->getPrimitiveSizeInBits()-1);
+ int64_t InputDemandedBits = DemandedMask & SrcTy->getIntegralTypeMask();
+
+ // If any of the sign extended bits are demanded, we know that the sign
+ // bit is demanded.
+ if (NewBits & DemandedMask)
+ InputDemandedBits |= InSignBit;
+
+ if (SimplifyDemandedBits(I->getOperand(0), InputDemandedBits,
KnownZero, KnownOne, Depth+1))
return true;
assert((KnownZero & KnownOne) == 0 && "Bits known to be one AND zero?");
// If the sign bit of the input is known set or clear, then we know the
// top bits of the result.
- uint64_t InSignBit = 1ULL << (SrcTy->getPrimitiveSizeInBits()-1);
// If the input sign bit is known zero, or if the NewBits are not demanded
// convert this into a zero extension.