summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorChad Rosier <mcrosier@codeaurora.org>2016-04-29 21:12:31 +0000
committerChad Rosier <mcrosier@codeaurora.org>2016-04-29 21:12:31 +0000
commitcd62bf58219d78e9557a20eddb886c7cc582feb7 (patch)
tree4c21b58c944cf35b5e32b631c2524270473cbea6 /llvm/lib
parent00c750cd12e7670136ae3bbddcd27ef4b8561feb (diff)
downloadbcm5719-llvm-cd62bf58219d78e9557a20eddb886c7cc582feb7.tar.gz
bcm5719-llvm-cd62bf58219d78e9557a20eddb886c7cc582feb7.zip
[InstCombine] Determine the result of a select based on a dominating condition.
Differential Revision: http://reviews.llvm.org/D19550 llvm-svn: 268104
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Analysis/ValueTracking.cpp5
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp18
2 files changed, 22 insertions, 1 deletions
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index feddbafa0d5..4097322a2b9 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -3941,7 +3941,10 @@ Optional<bool> llvm::isImpliedCondition(Value *LHS, Value *RHS,
unsigned Depth, AssumptionCache *AC,
const Instruction *CxtI,
const DominatorTree *DT) {
- assert(LHS->getType() == RHS->getType() && "mismatched type");
+ // A mismatch occurs when we compare a scalar cmp to a vector cmp, for example.
+ if (LHS->getType() != RHS->getType())
+ return None;
+
Type *OpTy = LHS->getType();
assert(OpTy->getScalarType()->isIntegerTy(1));
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
index 8595996c29c..ecf94dc70a7 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
@@ -1213,5 +1213,23 @@ Instruction *InstCombiner::visitSelectInst(SelectInst &SI) {
}
}
+ // See if we can determine the result of this select based on a dominating
+ // condition.
+ BasicBlock *Parent = SI.getParent();
+ if (BasicBlock *Dom = Parent->getSinglePredecessor()) {
+ auto *PBI = dyn_cast_or_null<BranchInst>(Dom->getTerminator());
+ if (PBI && PBI->isConditional() &&
+ PBI->getSuccessor(0) != PBI->getSuccessor(1) &&
+ (PBI->getSuccessor(0) == Parent || PBI->getSuccessor(1) == Parent)) {
+ bool CondIsFalse = PBI->getSuccessor(1) == Parent;
+ Optional<bool> Implication = isImpliedCondition(
+ PBI->getCondition(), SI.getCondition(), DL, CondIsFalse);
+ if (Implication) {
+ Value *V = *Implication ? TrueVal : FalseVal;
+ return replaceInstUsesWith(SI, V);
+ }
+ }
+ }
+
return nullptr;
}
OpenPOWER on IntegriCloud