summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorSanjay Patel <spatel@rotateright.com>2017-05-17 22:29:40 +0000
committerSanjay Patel <spatel@rotateright.com>2017-05-17 22:29:40 +0000
commitba212c241ab233b4830941f36c4608bee4eca4a3 (patch)
tree8c1104adf5fc61d6858fac8f47f5af2af98ca9fe /llvm/lib
parentcde4b3f4e694b544521e40dada45025ed0196afa (diff)
downloadbcm5719-llvm-ba212c241ab233b4830941f36c4608bee4eca4a3.tar.gz
bcm5719-llvm-ba212c241ab233b4830941f36c4608bee4eca4a3.zip
[InstCombine] handle icmp i1 X, C early to avoid creating an unknown pattern
The missing optimization for xor-of-icmps still needs to be added, but by being more efficient (not generating unnecessary logic ops with constants) we avoid the bug. See discussion in post-commit comments: https://reviews.llvm.org/D32143 llvm-svn: 303312
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
index 6a6e831726b..e2729516b40 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
@@ -4266,6 +4266,29 @@ static Instruction *canonicalizeICmpBool(ICmpInst &I,
Value *A = I.getOperand(0), *B = I.getOperand(1);
assert(A->getType()->getScalarType()->isIntegerTy(1) && "Bools only");
+ // A boolean compared to true/false can be simplified to Op0/true/false in
+ // 14 out of the 20 (10 predicates * 2 constants) possible combinations.
+ // Cases not handled by InstSimplify are always 'not' of Op0.
+ if (match(B, m_Zero())) {
+ switch (I.getPredicate()) {
+ case CmpInst::ICMP_EQ: // A == 0 -> !A
+ case CmpInst::ICMP_ULE: // A <=u 0 -> !A
+ case CmpInst::ICMP_SGE: // A >=s 0 -> !A
+ return BinaryOperator::CreateNot(A);
+ default:
+ llvm_unreachable("ICmp i1 X, C not simplified as expected.");
+ }
+ } else if (match(B, m_One())) {
+ switch (I.getPredicate()) {
+ case CmpInst::ICMP_NE: // A != 1 -> !A
+ case CmpInst::ICMP_ULT: // A <u 1 -> !A
+ case CmpInst::ICMP_SGT: // A >s -1 -> !A
+ return BinaryOperator::CreateNot(A);
+ default:
+ llvm_unreachable("ICmp i1 X, C not simplified as expected.");
+ }
+ }
+
switch (I.getPredicate()) {
default:
llvm_unreachable("Invalid icmp instruction!");
OpenPOWER on IntegriCloud