diff options
author | Philip Reames <listmail@philipreames.com> | 2015-06-16 00:49:59 +0000 |
---|---|---|
committer | Philip Reames <listmail@philipreames.com> | 2015-06-16 00:49:59 +0000 |
commit | 66ab0f045a37c25833dd22e0e725fe4833c92497 (patch) | |
tree | 759043ceb5878b7a328e63fd57a9c24c914f2365 /llvm/lib/Analysis/LazyValueInfo.cpp | |
parent | 51149d558953695f1fd9654496eddf38f0617677 (diff) | |
download | bcm5719-llvm-66ab0f045a37c25833dd22e0e725fe4833c92497.tar.gz bcm5719-llvm-66ab0f045a37c25833dd22e0e725fe4833c92497.zip |
Move logic from JumpThreading into LazyValue info to simplify caller.
This change is hopefully NFC. The only tricky part is that I changed the context instruction being used to the branch rather than the comparison. I believe both to be correct, but the branch is strictly more powerful. With the moved code, using the branch instruction is required for the basic block comparison test to return the same result. The previous code was able to directly access both the branch and the comparison where the revised code is not.
Differential Revision: http://reviews.llvm.org/D9652
llvm-svn: 239797
Diffstat (limited to 'llvm/lib/Analysis/LazyValueInfo.cpp')
-rw-r--r-- | llvm/lib/Analysis/LazyValueInfo.cpp | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/llvm/lib/Analysis/LazyValueInfo.cpp b/llvm/lib/Analysis/LazyValueInfo.cpp index e6f586ac702..a6ae7f2229c 100644 --- a/llvm/lib/Analysis/LazyValueInfo.cpp +++ b/llvm/lib/Analysis/LazyValueInfo.cpp @@ -1262,8 +1262,40 @@ LazyValueInfo::getPredicateAt(unsigned Pred, Value *V, Constant *C, Instruction *CxtI) { const DataLayout &DL = CxtI->getModule()->getDataLayout(); LVILatticeVal Result = getCache(PImpl, AC, &DL, DT).getValueAt(V, CxtI); - - return getPredicateResult(Pred, C, Result, DL, TLI); + Tristate Ret = getPredicateResult(Pred, C, Result, DL, TLI); + if (Ret != Unknown) + return Ret; + + // TODO: Move this logic inside getValueAt so that it can be cached rather + // than re-queried on each call. This would also allow us to merge the + // underlying lattice values to get more information + if (CxtI) { + // For a comparison where the V is outside this block, it's possible + // that we've branched on it before. Look to see if the value is known + // on all incoming edges. + BasicBlock *BB = CxtI->getParent(); + pred_iterator PI = pred_begin(BB), PE = pred_end(BB); + if (PI != PE && + (!isa<Instruction>(V) || + cast<Instruction>(V)->getParent() != BB)) { + // For predecessor edge, determine if the comparison is true or false + // on that edge. If they're all true or all false, we can conclude + // the value of the comparison in this block. + Tristate Baseline = getPredicateOnEdge(Pred, V, C, *PI, BB, CxtI); + if (Baseline != Unknown) { + // Check that all remaining incoming values match the first one. + while (++PI != PE) { + Tristate Ret = getPredicateOnEdge(Pred, V, C, *PI, BB, CxtI); + if (Ret != Baseline) break; + } + // If we terminated early, then one of the values didn't match. + if (PI == PE) { + return Baseline; + } + } + } + } + return Unknown; } void LazyValueInfo::threadEdge(BasicBlock *PredBB, BasicBlock *OldSucc, |