summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Analysis/InstructionSimplify.cpp
diff options
context:
space:
mode:
authorDavid Bolvansky <david.bolvansky@gmail.com>2018-07-31 14:17:15 +0000
committerDavid Bolvansky <david.bolvansky@gmail.com>2018-07-31 14:17:15 +0000
commit16d8a69b90df2effd11315769fefac378cc57aa1 (patch)
tree2e70f9471e6f683f7dfc917b395977efb047d39d /llvm/lib/Analysis/InstructionSimplify.cpp
parenta5ed032118a8df248313a5e4b3cc9c70e2d29135 (diff)
downloadbcm5719-llvm-16d8a69b90df2effd11315769fefac378cc57aa1.tar.gz
bcm5719-llvm-16d8a69b90df2effd11315769fefac378cc57aa1.zip
[InstSimplify] Fold another Select with And/Or pattern
Summary: Proof: https://rise4fun.com/Alive/L5J Reviewers: lebedev.ri, spatel Reviewed By: spatel Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D49975 llvm-svn: 338383
Diffstat (limited to 'llvm/lib/Analysis/InstructionSimplify.cpp')
-rw-r--r--llvm/lib/Analysis/InstructionSimplify.cpp36
1 files changed, 22 insertions, 14 deletions
diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp
index 607ec382074..6ebae37a6a8 100644
--- a/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -65,13 +65,6 @@ static Value *SimplifyCastInst(unsigned, Value *, Type *,
static Value *SimplifyGEPInst(Type *, ArrayRef<Value *>, const SimplifyQuery &,
unsigned);
-/// Fold
-/// %A = icmp ne/eq i8 %X, %V1
-/// %B = icmp ne/eq i8 %X, %V2
-/// %C = or/and i1 %A, %B
-/// %D = select i1 %C, i8 %X, i8 %V1
-/// To
-/// %X/%V1
static Value *foldSelectWithBinaryOp(Value *Cond, Value *TrueVal,
Value *FalseVal) {
BinaryOperator::BinaryOps BinOpCode;
@@ -80,7 +73,7 @@ static Value *foldSelectWithBinaryOp(Value *Cond, Value *TrueVal,
else
return nullptr;
- CmpInst::Predicate ExpectedPred;
+ CmpInst::Predicate ExpectedPred, Pred1, Pred2;
if (BinOpCode == BinaryOperator::Or) {
ExpectedPred = ICmpInst::ICMP_NE;
} else if (BinOpCode == BinaryOperator::And) {
@@ -88,15 +81,30 @@ static Value *foldSelectWithBinaryOp(Value *Cond, Value *TrueVal,
} else
return nullptr;
- CmpInst::Predicate Pred1, Pred2;
- if (!match(
- Cond,
- m_c_BinOp(m_c_ICmp(Pred1, m_Specific(TrueVal), m_Specific(FalseVal)),
- m_c_ICmp(Pred2, m_Specific(TrueVal), m_Value()))) ||
+ // %A = icmp eq %TV, %FV
+ // %B = icmp eq %X, %Y (and one of these is a select operand)
+ // %C = and %A, %B
+ // %D = select %C, %TV, %FV
+ // -->
+ // %FV
+
+ // %A = icmp ne %TV, %FV
+ // %B = icmp ne %X, %Y (and one of these is a select operand)
+ // %C = or %A, %B
+ // %D = select %C, %TV, %FV
+ // -->
+ // %TV
+ Value *X, *Y;
+ if (!match(Cond, m_c_BinOp(m_c_ICmp(Pred1, m_Specific(TrueVal),
+ m_Specific(FalseVal)),
+ m_ICmp(Pred2, m_Value(X), m_Value(Y)))) ||
Pred1 != Pred2 || Pred1 != ExpectedPred)
return nullptr;
- return BinOpCode == BinaryOperator::Or ? TrueVal : FalseVal;
+ if (X == TrueVal || X == FalseVal || Y == TrueVal || Y == FalseVal)
+ return BinOpCode == BinaryOperator::Or ? TrueVal : FalseVal;
+
+ return nullptr;
}
/// For a boolean type or a vector of boolean type, return false or a vector
OpenPOWER on IntegriCloud