aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Analysis/ValueTracking.cpp
diff options
context:
space:
mode:
authorDan Gohman <gohman@apple.com>2009-05-21 02:28:33 +0000
committerDan Gohman <gohman@apple.com>2009-05-21 02:28:33 +0000
commit2bc21561cfce6fe595822c74fd56e99786c1b263 (patch)
tree537c7db81d2ade0b3a765258ac8f71fd2900371b /lib/Analysis/ValueTracking.cpp
parentc308c5087f9aa950cb9a17144a3364e3b7bb8544 (diff)
downloadexternal_llvm-2bc21561cfce6fe595822c74fd56e99786c1b263.zip
external_llvm-2bc21561cfce6fe595822c74fd56e99786c1b263.tar.gz
external_llvm-2bc21561cfce6fe595822c74fd56e99786c1b263.tar.bz2
Teach ValueTracking a new way to analyze PHI nodes, and and teach
Instcombine to be more aggressive about using SimplifyDemandedBits on shift nodes. This allows a shift to be simplified to zero in the included test case. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@72204 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/ValueTracking.cpp')
-rw-r--r--lib/Analysis/ValueTracking.cpp29
1 files changed, 27 insertions, 2 deletions
diff --git a/lib/Analysis/ValueTracking.cpp b/lib/Analysis/ValueTracking.cpp
index c4f6faf..3c21e20 100644
--- a/lib/Analysis/ValueTracking.cpp
+++ b/lib/Analysis/ValueTracking.cpp
@@ -48,8 +48,9 @@ static unsigned getOpcode(const Value *V) {
void llvm::ComputeMaskedBits(Value *V, const APInt &Mask,
APInt &KnownZero, APInt &KnownOne,
TargetData *TD, unsigned Depth) {
+ const unsigned MaxDepth = 6;
assert(V && "No Value?");
- assert(Depth <= 6 && "Limit Search Depth");
+ assert(Depth <= MaxDepth && "Limit Search Depth");
unsigned BitWidth = Mask.getBitWidth();
assert((V->getType()->isInteger() || isa<PointerType>(V->getType())) &&
"Not integer or pointer type!");
@@ -88,7 +89,7 @@ void llvm::ComputeMaskedBits(Value *V, const APInt &Mask,
KnownZero.clear(); KnownOne.clear(); // Start out not knowing anything.
- if (Depth == 6 || Mask == 0)
+ if (Depth == MaxDepth || Mask == 0)
return; // Limit search depth.
User *I = dyn_cast<User>(V);
@@ -522,6 +523,30 @@ void llvm::ComputeMaskedBits(Value *V, const APInt &Mask,
}
}
}
+
+ // Otherwise take the unions of the known bit sets of the operands,
+ // taking conservative care to avoid excessive recursion.
+ if (Depth < MaxDepth - 1 && !KnownZero && !KnownOne) {
+ KnownZero = APInt::getAllOnesValue(BitWidth);
+ KnownOne = APInt::getAllOnesValue(BitWidth);
+ for (unsigned i = 0, e = P->getNumIncomingValues(); i != e; ++i) {
+ // Skip direct self references.
+ if (P->getIncomingValue(i) == P) continue;
+
+ KnownZero2 = APInt(BitWidth, 0);
+ KnownOne2 = APInt(BitWidth, 0);
+ // Recurse, but cap the recursion to one level, because we don't
+ // want to waste time spinning around in loops.
+ ComputeMaskedBits(P->getIncomingValue(i), KnownZero | KnownOne,
+ KnownZero2, KnownOne2, TD, MaxDepth-1);
+ KnownZero &= KnownZero2;
+ KnownOne &= KnownOne2;
+ // If all bits have been ruled out, there's no need to check
+ // more operands.
+ if (!KnownZero && !KnownOne)
+ break;
+ }
+ }
break;
}
case Instruction::Call: