diff options
author | Pete Cooper <peter_cooper@apple.com> | 2016-08-12 01:00:15 +0000 |
---|---|---|
committer | Pete Cooper <peter_cooper@apple.com> | 2016-08-12 01:00:15 +0000 |
commit | 54a0255679f2a68ba166b0051a87b5175ca6d0d3 (patch) | |
tree | 75e82a25e7c7d591b0f15daac3d73cdbc0f81b1c | |
parent | 2de509c370a7af9d51ef9a32e2b4f299b71cc088 (diff) | |
download | bcm5719-llvm-54a0255679f2a68ba166b0051a87b5175ca6d0d3.tar.gz bcm5719-llvm-54a0255679f2a68ba166b0051a87b5175ca6d0d3.zip |
Refactor isValidAssumeForContext to reduce duplication and indentation. NFC.
This method had some duplicate code when we did or did not have a dom tree. Refactor
it to remove the duplication, but also clean up the control flow to have less duplication.
llvm-svn: 278450
-rw-r--r-- | llvm/lib/Analysis/ValueTracking.cpp | 48 |
1 files changed, 21 insertions, 27 deletions
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp index 97c49310db2..0f566bf7d7b 100644 --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -468,45 +468,39 @@ bool llvm::isValidAssumeForContext(const Instruction *Inv, // the assume). if (DT) { - if (DT->dominates(Inv, CxtI)) { + if (DT->dominates(Inv, CxtI)) return true; - } else if (Inv->getParent() == CxtI->getParent()) { - // The context comes first, but they're both in the same block. Make sure - // there is nothing in between that might interrupt the control flow. - for (BasicBlock::const_iterator I = - std::next(BasicBlock::const_iterator(CxtI)), - IE(Inv); I != IE; ++I) - if (!isSafeToSpeculativelyExecute(&*I) && !isAssumeLikeIntrinsic(&*I)) - return false; - - return !isEphemeralValueOf(Inv, CxtI); - } + } else if (Inv->getParent() == CxtI->getParent()->getSinglePredecessor()) { + // We don't have a DT, but this trivially dominates. + return true; + } + // With or without a DT, the only remaining case we will check is if the + // instructions are in the same BB. Give up if that is not the case. + if (Inv->getParent() != CxtI->getParent()) return false; - } - // When we don't have a DT, we do a limited search... - if (Inv->getParent() == CxtI->getParent()->getSinglePredecessor()) { - return true; - } else if (Inv->getParent() == CxtI->getParent()) { + // If we have a dom tree, then we now know that the assume doens't dominate + // the other instruction. If we don't have a dom tree then we can check if + // the assume is first in the BB. + if (!DT) { // Search forward from the assume until we reach the context (or the end // of the block); the common case is that the assume will come first. for (auto I = std::next(BasicBlock::const_iterator(Inv)), IE = Inv->getParent()->end(); I != IE; ++I) if (&*I == CxtI) return true; - - // The context must come first... - for (BasicBlock::const_iterator I = - std::next(BasicBlock::const_iterator(CxtI)), - IE(Inv); I != IE; ++I) - if (!isSafeToSpeculativelyExecute(&*I) && !isAssumeLikeIntrinsic(&*I)) - return false; - - return !isEphemeralValueOf(Inv, CxtI); } - return false; + // The context comes first, but they're both in the same block. Make sure + // there is nothing in between that might interrupt the control flow. + for (BasicBlock::const_iterator I = + std::next(BasicBlock::const_iterator(CxtI)), IE(Inv); + I != IE; ++I) + if (!isSafeToSpeculativelyExecute(&*I) && !isAssumeLikeIntrinsic(&*I)) + return false; + + return !isEphemeralValueOf(Inv, CxtI); } static void computeKnownBitsFromAssume(Value *V, APInt &KnownZero, |