diff options
author | Bjorn Steinbrink <bsteinbr@gmail.com> | 2015-05-12 22:31:47 +0000 |
---|---|---|
committer | Bjorn Steinbrink <bsteinbr@gmail.com> | 2015-05-12 22:31:47 +0000 |
commit | 2833966a3c91fc354115b28de4aaaae56674c155 (patch) | |
tree | 94ff81575aa3c4f3b8bac7927c9cff598d99dd66 /llvm/lib/Transforms | |
parent | 311f7106547106fd23022f082762d83c2886db74 (diff) | |
download | bcm5719-llvm-2833966a3c91fc354115b28de4aaaae56674c155.tar.gz bcm5719-llvm-2833966a3c91fc354115b28de4aaaae56674c155.zip |
CVP: Improve handling of Selects used as incoming PHI values
Summary:
If the branch that leads to the PHI node and the Select instruction
depend on correlated conditions, we might be able to directly use the
corresponding value from the Select instruction as the incoming value
for the PHI node, allowing later removal of the select instruction.
Subscribers: llvm-commits
Differential Revision: http://reviews.llvm.org/D9051
llvm-svn: 237201
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r-- | llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp | 41 |
1 files changed, 30 insertions, 11 deletions
diff --git a/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp b/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp index 912d527402a..d1302c6e22f 100644 --- a/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp +++ b/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp @@ -103,24 +103,43 @@ bool CorrelatedValuePropagation::processPHI(PHINode *P) { Value *V = LVI->getConstantOnEdge(Incoming, P->getIncomingBlock(i), BB, P); - // Look if the incoming value is a select with a constant but LVI tells us - // that the incoming value can never be that constant. In that case replace - // the incoming value with the other value of the select. This often allows - // us to remove the select later. + // Look if the incoming value is a select with a scalar condition for which + // LVI can tells us the value. In that case replace the incoming value with + // the appropriate value of the select. This often allows us to remove the + // select later. if (!V) { SelectInst *SI = dyn_cast<SelectInst>(Incoming); if (!SI) continue; - Constant *C = dyn_cast<Constant>(SI->getFalseValue()); - if (!C) continue; + Value *Condition = SI->getCondition(); + if (!Condition->getType()->isVectorTy()) { + if (Constant *C = LVI->getConstantOnEdge(Condition, P->getIncomingBlock(i), BB, P)) { + if (C == ConstantInt::getTrue(Condition->getType())) { + V = SI->getTrueValue(); + } else { + V = SI->getFalseValue(); + } + // Once LVI learns to handle vector types, we could also add support + // for vector type constants that are not all zeroes or all ones. + } + } - if (LVI->getPredicateOnEdge(ICmpInst::ICMP_EQ, SI, C, - P->getIncomingBlock(i), BB, P) != - LazyValueInfo::False) - continue; + // Look if the select has a constant but LVI tells us that the incoming + // value can never be that constant. In that case replace the incoming + // value with the other value of the select. This often allows us to + // remove the select later. + if (!V) { + Constant *C = dyn_cast<Constant>(SI->getFalseValue()); + if (!C) continue; + + if (LVI->getPredicateOnEdge(ICmpInst::ICMP_EQ, SI, C, + P->getIncomingBlock(i), BB, P) != + LazyValueInfo::False) + continue; + V = SI->getTrueValue(); + } DEBUG(dbgs() << "CVP: Threading PHI over " << *SI << '\n'); - V = SI->getTrueValue(); } P->setIncomingValue(i, V); |