summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms
diff options
context:
space:
mode:
authorDan Gohman <gohman@apple.com>2008-10-28 22:38:57 +0000
committerDan Gohman <gohman@apple.com>2008-10-28 22:38:57 +0000
commit2c34c130bff3661556af9e3b420945a4736f1778 (patch)
tree8474ed0422263048850b693cec0010b0f4dc225d /llvm/lib/Transforms
parent1e3c25ac2dc8db5c25b0707699e40b867420c08a (diff)
downloadbcm5719-llvm-2c34c130bff3661556af9e3b420945a4736f1778.tar.gz
bcm5719-llvm-2c34c130bff3661556af9e3b420945a4736f1778.zip
(A & sext(C)) | (B & ~sext(C) -> C ? A : B
llvm-svn: 58351
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r--llvm/lib/Transforms/Scalar/InstructionCombining.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
index 8ec775b0c32..4ec36ad1514 100644
--- a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
@@ -4337,6 +4337,25 @@ Instruction *InstCombiner::visitOr(BinaryOperator &I) {
return BinaryOperator::CreateAnd(V1, Or);
}
}
+
+ // (A & sext(C0)) | (B & ~sext(C0) -> C0 ? A : B
+ if (isa<SExtInst>(C) &&
+ cast<User>(C)->getOperand(0)->getType() == Type::Int1Ty) {
+ if (match(D, m_Not(m_Value(C))))
+ return SelectInst::Create(cast<User>(C)->getOperand(0), A, B);
+ // And commutes, try both ways.
+ if (match(B, m_Not(m_Value(C))))
+ return SelectInst::Create(cast<User>(C)->getOperand(0), A, D);
+ }
+ // Or commutes, try both ways.
+ if (isa<SExtInst>(D) &&
+ cast<User>(D)->getOperand(0)->getType() == Type::Int1Ty) {
+ if (match(C, m_Not(m_Value(D))))
+ return SelectInst::Create(cast<User>(D)->getOperand(0), A, B);
+ // And commutes, try both ways.
+ if (match(A, m_Not(m_Value(D))))
+ return SelectInst::Create(cast<User>(D)->getOperand(0), C, B);
+ }
}
// (X >> Z) | (Y >> Z) -> (X|Y) >> Z for all shifts.
OpenPOWER on IntegriCloud