diff options
author | Simon Pilgrim <llvm-dev@redking.me.uk> | 2021-10-16 11:20:07 +0100 |
---|---|---|
committer | Simon Pilgrim <llvm-dev@redking.me.uk> | 2021-10-16 11:20:19 +0100 |
commit | a1b43d2bc946966a64f390058e3bf5fc22ee9304 (patch) | |
tree | aed29e8d1b1bc3276052d193aa0059255113dc87 /llvm/lib/Analysis/LazyValueInfo.cpp | |
parent | c28824179530db3aaa3b76291111b2c8a56face4 (diff) | |
download | llvm-a1b43d2bc946966a64f390058e3bf5fc22ee9304.zip llvm-a1b43d2bc946966a64f390058e3bf5fc22ee9304.tar.gz llvm-a1b43d2bc946966a64f390058e3bf5fc22ee9304.tar.bz2 |
[LazyValueInfo] getPredicateAt - remove unnecessary null pointer check. NFC.
We already dereference the CxtI pointer several times before reaching the "if(CxtI)", we have no need to check it again.
Fixes a coverity warning.
Diffstat (limited to 'llvm/lib/Analysis/LazyValueInfo.cpp')
-rw-r--r-- | llvm/lib/Analysis/LazyValueInfo.cpp | 102 |
1 files changed, 51 insertions, 51 deletions
diff --git a/llvm/lib/Analysis/LazyValueInfo.cpp b/llvm/lib/Analysis/LazyValueInfo.cpp index a624d7a..50fa169 100644 --- a/llvm/lib/Analysis/LazyValueInfo.cpp +++ b/llvm/lib/Analysis/LazyValueInfo.cpp @@ -1779,62 +1779,62 @@ LazyValueInfo::getPredicateAt(unsigned Pred, Value *V, Constant *C, // We could consider extending this to search further backwards through the // CFG and/or value graph, but there are non-obvious compile time vs quality // tradeoffs. - if (CxtI) { - BasicBlock *BB = CxtI->getParent(); - - // Function entry or an unreachable block. Bail to avoid confusing - // analysis below. - pred_iterator PI = pred_begin(BB), PE = pred_end(BB); - if (PI == PE) - return Unknown; - - // If V is a PHI node in the same block as the context, we need to ask - // questions about the predicate as applied to the incoming value along - // each edge. This is useful for eliminating cases where the predicate is - // known along all incoming edges. - if (auto *PHI = dyn_cast<PHINode>(V)) - if (PHI->getParent() == BB) { - Tristate Baseline = Unknown; - for (unsigned i = 0, e = PHI->getNumIncomingValues(); i < e; i++) { - Value *Incoming = PHI->getIncomingValue(i); - BasicBlock *PredBB = PHI->getIncomingBlock(i); - // Note that PredBB may be BB itself. - Tristate Result = getPredicateOnEdge(Pred, Incoming, C, PredBB, BB, - CxtI); - - // Keep going as long as we've seen a consistent known result for - // all inputs. - Baseline = (i == 0) ? Result /* First iteration */ - : (Baseline == Result ? Baseline : Unknown); /* All others */ - if (Baseline == Unknown) - break; - } - if (Baseline != Unknown) - return Baseline; + BasicBlock *BB = CxtI->getParent(); + + // Function entry or an unreachable block. Bail to avoid confusing + // analysis below. + pred_iterator PI = pred_begin(BB), PE = pred_end(BB); + if (PI == PE) + return Unknown; + + // If V is a PHI node in the same block as the context, we need to ask + // questions about the predicate as applied to the incoming value along + // each edge. This is useful for eliminating cases where the predicate is + // known along all incoming edges. + if (auto *PHI = dyn_cast<PHINode>(V)) + if (PHI->getParent() == BB) { + Tristate Baseline = Unknown; + for (unsigned i = 0, e = PHI->getNumIncomingValues(); i < e; i++) { + Value *Incoming = PHI->getIncomingValue(i); + BasicBlock *PredBB = PHI->getIncomingBlock(i); + // Note that PredBB may be BB itself. + Tristate Result = + getPredicateOnEdge(Pred, Incoming, C, PredBB, BB, CxtI); + + // Keep going as long as we've seen a consistent known result for + // all inputs. + Baseline = (i == 0) ? Result /* First iteration */ + : (Baseline == Result ? Baseline + : Unknown); /* All others */ + if (Baseline == Unknown) + break; } + if (Baseline != Unknown) + return Baseline; + } - // 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. - if (!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; - } + // 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. + if (!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; } |