Skip to content

Commit 0549202

Browse files
marcaubererZijunZhaoCCK
authored andcommitted
[InstCombine] Remove unnecessary one-use-check (llvm#66419)
This removes a oneUse check, that is actually unnecessary. Alive2: https://alive2.llvm.org/ce/z/qEkUEf Original patch: https://reviews.llvm.org/D159380
1 parent d095c68 commit 0549202

File tree

2 files changed

+9
-12
lines changed

2 files changed

+9
-12
lines changed

llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3646,10 +3646,9 @@ Instruction *InstCombinerImpl::visitOr(BinaryOperator &I) {
36463646
// ((A & B) ^ B) | ((A & B) ^ A) -> A ^ B
36473647
// (B ^ (A & B)) | (A ^ (A & B)) -> A ^ B
36483648
const auto TryXorOpt = [&](Value *Lhs, Value *Rhs) -> Instruction * {
3649-
if (match(Lhs, m_OneUse(m_c_Xor(m_And(m_Value(A), m_Value(B)),
3650-
m_Deferred(A)))) &&
3651-
match(Rhs, m_OneUse(m_c_Xor(m_And(m_Specific(A), m_Specific(B)),
3652-
m_Deferred(B))))) {
3649+
if (match(Lhs, m_c_Xor(m_And(m_Value(A), m_Value(B)), m_Deferred(A))) &&
3650+
match(Rhs,
3651+
m_c_Xor(m_And(m_Specific(A), m_Specific(B)), m_Deferred(B)))) {
36533652
return BinaryOperator::CreateXor(A, B);
36543653
}
36553654
return nullptr;

llvm/test/Transforms/InstCombine/or-xor-xor.ll

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,10 @@ define i3 @or_xor_xor_normal_multiple_uses_and(i3 %a, i3 %b) {
9797

9898
define i32 @or_xor_xor_negative_multiple_uses_xor1(i32 %a, i32 %b) {
9999
; CHECK-LABEL: @or_xor_xor_negative_multiple_uses_xor1(
100-
; CHECK-NEXT: [[AND:%.*]] = and i32 [[A:%.*]], [[B:%.*]]
101-
; CHECK-NEXT: [[XOR1:%.*]] = xor i32 [[AND]], [[B]]
100+
; CHECK-NEXT: [[AND1:%.*]] = xor i32 [[A:%.*]], -1
101+
; CHECK-NEXT: [[XOR1:%.*]] = and i32 [[AND1]], [[B:%.*]]
102102
; CHECK-NEXT: call void @use.i32(i32 [[XOR1]])
103-
; CHECK-NEXT: [[XOR2:%.*]] = xor i32 [[AND]], [[A]]
104-
; CHECK-NEXT: [[OR:%.*]] = or i32 [[XOR1]], [[XOR2]]
103+
; CHECK-NEXT: [[OR:%.*]] = xor i32 [[A]], [[B]]
105104
; CHECK-NEXT: ret i32 [[OR]]
106105
;
107106
%and = and i32 %a, %b
@@ -114,11 +113,10 @@ define i32 @or_xor_xor_negative_multiple_uses_xor1(i32 %a, i32 %b) {
114113

115114
define i5 @or_xor_xor_negative_multiple_uses_xor2(i5 %a, i5 %b) {
116115
; CHECK-LABEL: @or_xor_xor_negative_multiple_uses_xor2(
117-
; CHECK-NEXT: [[AND:%.*]] = and i5 [[A:%.*]], [[B:%.*]]
118-
; CHECK-NEXT: [[XOR1:%.*]] = xor i5 [[AND]], [[B]]
119-
; CHECK-NEXT: [[XOR2:%.*]] = xor i5 [[AND]], [[A]]
116+
; CHECK-NEXT: [[A1:%.*]] = xor i5 [[B:%.*]], -1
117+
; CHECK-NEXT: [[XOR2:%.*]] = and i5 [[A1]], [[A:%.*]]
120118
; CHECK-NEXT: call void @use.i5(i5 [[XOR2]])
121-
; CHECK-NEXT: [[OR:%.*]] = or i5 [[XOR1]], [[XOR2]]
119+
; CHECK-NEXT: [[OR:%.*]] = xor i5 [[A]], [[B]]
122120
; CHECK-NEXT: ret i5 [[OR]]
123121
;
124122
%and = and i5 %a, %b

0 commit comments

Comments
 (0)