File tree 2 files changed +23
-0
lines changed
lib/Transforms/InstCombine
test/Transforms/InstCombine
2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -2522,6 +2522,16 @@ Instruction *InstCombiner::visitXor(BinaryOperator &I) {
2522
2522
match (Op1I, m_Or (m_Specific (A), m_Not (m_Specific (B))))) {
2523
2523
return BinaryOperator::CreateXor (A, B);
2524
2524
}
2525
+ // (A & ~B) ^ (~A & B) -> A ^ B
2526
+ if (match (Op0I, m_And (m_Value (A), m_Not (m_Value (B)))) &&
2527
+ match (Op1I, m_And (m_Not (m_Specific (A)), m_Specific (B)))) {
2528
+ return BinaryOperator::CreateXor (A, B);
2529
+ }
2530
+ // (~A & B) ^ (A & ~B) -> A ^ B
2531
+ if (match (Op0I, m_And (m_Not (m_Value (A)), m_Value (B))) &&
2532
+ match (Op1I, m_And (m_Specific (A), m_Not (m_Specific (B))))) {
2533
+ return BinaryOperator::CreateXor (A, B);
2534
+ }
2525
2535
// (A ^ B)^(A | B) -> A & B
2526
2536
if (match (Op0I, m_Xor (m_Value (A), m_Value (B))) &&
2527
2537
match (Op1I, m_Or (m_Value (C), m_Value (D)))) {
Original file line number Diff line number Diff line change @@ -160,3 +160,16 @@ define i32 @test16(i32 %x, i32 %y) {
160
160
; CHECK-NEXT: %xor = xor i32 %x, %y
161
161
; CHECK-NEXT: ret i32 %xor
162
162
}
163
+
164
+ ; ((x & ~y) ^ (~x & y)) -> x ^ y
165
+ define i32 @test17 (i32 %x , i32 %y ) {
166
+ %noty = xor i32 %y , -1
167
+ %notx = xor i32 %x , -1
168
+ %and1 = and i32 %x , %noty
169
+ %and2 = and i32 %notx , %y
170
+ %xor = xor i32 %and1 , %and2
171
+ ret i32 %xor
172
+ ; CHECK-LABEL: @test17(
173
+ ; CHECK-NEXT: %xor = xor i32 %x, %y
174
+ ; CHECK-NEXT: ret i32 %xor
175
+ }
You can’t perform that action at this time.
0 commit comments