diff options
author | Chris Lattner <sabre@nondot.org> | 2010-01-07 23:44:37 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2010-01-07 23:44:37 +0000 |
commit | 8d10f9d4a836907d7bf048be507787a9233959c9 (patch) | |
tree | 21be48bcfc65dcd32560bc00f4e168315adc89ac /lib/Analysis | |
parent | e3874deb61fb01354ca32996e941060956fc4d41 (diff) | |
download | external_llvm-8d10f9d4a836907d7bf048be507787a9233959c9.zip external_llvm-8d10f9d4a836907d7bf048be507787a9233959c9.tar.gz external_llvm-8d10f9d4a836907d7bf048be507787a9233959c9.tar.bz2 |
teach ComputeNumSignBits to look through PHI nodes.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@92964 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis')
-rw-r--r-- | lib/Analysis/ValueTracking.cpp | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/lib/Analysis/ValueTracking.cpp b/lib/Analysis/ValueTracking.cpp index 9a10624..91e5bc3 100644 --- a/lib/Analysis/ValueTracking.cpp +++ b/lib/Analysis/ValueTracking.cpp @@ -726,8 +726,7 @@ unsigned llvm::ComputeNumSignBits(Value *V, const TargetData *TD, Tmp2 = ComputeNumSignBits(U->getOperand(1), TD, Depth+1); if (Tmp2 == 1) return 1; - return std::min(Tmp, Tmp2)-1; - break; + return std::min(Tmp, Tmp2)-1; case Instruction::Sub: Tmp2 = ComputeNumSignBits(U->getOperand(1), TD, Depth+1); @@ -757,8 +756,24 @@ unsigned llvm::ComputeNumSignBits(Value *V, const TargetData *TD, // is, at worst, one more bit than the inputs. Tmp = ComputeNumSignBits(U->getOperand(0), TD, Depth+1); if (Tmp == 1) return 1; // Early out. - return std::min(Tmp, Tmp2)-1; - break; + return std::min(Tmp, Tmp2)-1; + + case Instruction::PHI: { + PHINode *PN = cast<PHINode>(U); + // Don't analyze large in-degree PHIs. + if (PN->getNumIncomingValues() > 4) break; + + // Take the minimum of all incoming values. This can't infinitely loop + // because of our depth threshold. + Tmp = ComputeNumSignBits(PN->getIncomingValue(0), TD, Depth+1); + for (unsigned i = 1, e = PN->getNumIncomingValues(); i != e; ++i) { + if (Tmp == 1) return Tmp; + Tmp = std::min(Tmp, + ComputeNumSignBits(PN->getIncomingValue(1), TD, Depth+1)); + } + return Tmp; + } + case Instruction::Trunc: // FIXME: it's tricky to do anything useful for this, but it is an important // case for targets like X86. |