summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCraig Topper <craig.topper@gmail.com>2017-04-07 07:32:00 +0000
committerCraig Topper <craig.topper@gmail.com>2017-04-07 07:32:00 +0000
commit33e0dbcc5872139a6cdd9337244287fb93fc1a96 (patch)
tree1905c4321e4a9dc413b951dea73d6e4f2f40597c
parentccf85f24c82f4bae943ee68a8d34deae5ae7b1a9 (diff)
downloadbcm5719-llvm-33e0dbcc5872139a6cdd9337244287fb93fc1a96.tar.gz
bcm5719-llvm-33e0dbcc5872139a6cdd9337244287fb93fc1a96.zip
[InstCombine] Handle more commuted cases of ((A & B) | ~A) -> (~A | B)
llvm-svn: 299747
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp7
-rw-r--r--llvm/test/Transforms/InstCombine/or.ll6
2 files changed, 6 insertions, 7 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
index 6b6e362a34c..024949f8eee 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
@@ -2098,9 +2098,10 @@ Instruction *InstCombiner::visitOr(BinaryOperator &I) {
return BinaryOperator::CreateOr(Op0, A);
// ((A & B) | ~A) -> (~A | B)
- if (match(Op0, m_And(m_Value(A), m_Value(B))) &&
- match(Op1, m_Not(m_Specific(A))))
- return BinaryOperator::CreateOr(Builder->CreateNot(A), B);
+ // The NOT is guaranteed to be in the RHS by complexity ordering.
+ if (match(Op1, m_Not(m_Value(A))) &&
+ match(Op0, m_c_And(m_Specific(A), m_Value(B))))
+ return BinaryOperator::CreateOr(Op1, B);
// (A & ~B) | (A ^ B) -> (A ^ B)
// (~B & A) | (A ^ B) -> (A ^ B)
diff --git a/llvm/test/Transforms/InstCombine/or.ll b/llvm/test/Transforms/InstCombine/or.ll
index 57ceff27053..be1e8e6d4a9 100644
--- a/llvm/test/Transforms/InstCombine/or.ll
+++ b/llvm/test/Transforms/InstCombine/or.ll
@@ -544,9 +544,8 @@ define i32 @test40(i32 %a, i32 %b) {
define i32 @test40b(i32 %a, i32 %b) {
; CHECK-LABEL: @test40b(
-; CHECK-NEXT: [[AND:%.*]] = and i32 %b, %a
; CHECK-NEXT: [[XOR:%.*]] = xor i32 %a, -1
-; CHECK-NEXT: [[OR:%.*]] = or i32 [[AND]], [[XOR]]
+; CHECK-NEXT: [[OR:%.*]] = or i32 [[XOR]], %b
; CHECK-NEXT: ret i32 [[OR]]
;
%and = and i32 %b, %a
@@ -557,9 +556,8 @@ define i32 @test40b(i32 %a, i32 %b) {
define i32 @test40c(i32 %a, i32 %b) {
; CHECK-LABEL: @test40c(
-; CHECK-NEXT: [[AND:%.*]] = and i32 %b, %a
; CHECK-NEXT: [[XOR:%.*]] = xor i32 %a, -1
-; CHECK-NEXT: [[OR:%.*]] = or i32 [[AND]], [[XOR]]
+; CHECK-NEXT: [[OR:%.*]] = or i32 [[XOR]], %b
; CHECK-NEXT: ret i32 [[OR]]
;
%and = and i32 %b, %a
OpenPOWER on IntegriCloud