Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[InstCombine] Remove unnecessary one-use-check #66419

Merged
merged 1 commit into from
Sep 15, 2023

Conversation

marcauberer
Copy link
Member

This removes a oneUse check, that is actually unecessary (see Alive2 link).

Alive2: https://alive2.llvm.org/ce/z/qEkUEf
Original patch: https://reviews.llvm.org/D159380

@llvmbot
Copy link
Collaborator

llvmbot commented Sep 14, 2023

@llvm/pr-subscribers-llvm-transforms

Changes This removes a oneUse check, that is actually unecessary (see Alive2 link).

Alive2: https://alive2.llvm.org/ce/z/qEkUEf
Original patch: https://reviews.llvm.org/D159380

Full diff: https://github.com/llvm/llvm-project/pull/66419.diff

2 Files Affected:

  • (modified) llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp (+2-4)
  • (modified) llvm/test/Transforms/InstCombine/or-xor-xor.ll (-53)
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
index d8c2827d25831d3..858df7bb6b12f2c 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
@@ -3646,10 +3646,8 @@ Instruction *InstCombinerImpl::visitOr(BinaryOperator &I) {
     // ((A & B) ^ B) | ((A & B) ^ A) -> A ^ B
     // (B ^ (A & B)) | (A ^ (A & B)) -> A ^ B
     const auto TryXorOpt = [&](Value *Lhs, Value *Rhs) -> Instruction * {
-      if (match(Lhs, m_OneUse(m_c_Xor(m_And(m_Value(A), m_Value(B)),
-                                      m_Deferred(A)))) &&
-          match(Rhs, m_OneUse(m_c_Xor(m_And(m_Specific(A), m_Specific(B)),
-                                      m_Deferred(B))))) {
+      if (match(Lhs, m_c_Xor(m_And(m_Value(A), m_Value(B)), m_Deferred(A))) &&
+          match(Rhs, m_c_Xor(m_And(m_Specific(A), m_Specific(B)), m_Deferred(B)))) {
         return BinaryOperator::CreateXor(A, B);
       }
       return nullptr;
diff --git a/llvm/test/Transforms/InstCombine/or-xor-xor.ll b/llvm/test/Transforms/InstCombine/or-xor-xor.ll
index 3f0066d7f00b1dc..9bcaeaaafd1ce39 100644
--- a/llvm/test/Transforms/InstCombine/or-xor-xor.ll
+++ b/llvm/test/Transforms/InstCombine/or-xor-xor.ll
@@ -1,10 +1,6 @@
 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
 ; RUN: opt < %s -passes=instcombine -S | FileCheck %s
 
-declare void @use.i3(i1)
-declare void @use.i5(i5)
-declare void @use.i32(i5)
-
 define i1 @or_xor_xor_normal_variant1(i1 %a, i1 %b) {
 ; CHECK-LABEL: @or_xor_xor_normal_variant1(
 ; CHECK-NEXT:    [[OR:%.*]] = xor i1 [[A:%.*]], [[B:%.*]]
@@ -79,52 +75,3 @@ define <3 x i1> @or_xor_xor_normal_vector(<3 x i1> %a, <3 x i1> %b) {
   %or = or <3 x i1> %xor1, %xor2
   ret <3 x i1> %or
 }
-
-define i3 @or_xor_xor_normal_multiple_uses_and(i3 %a, i3 %b) {
-; CHECK-LABEL: @or_xor_xor_normal_multiple_uses_and(
-; CHECK-NEXT:    [[AND:%.*]] = and i3 [[A:%.*]], [[B:%.*]]
-; CHECK-NEXT:    call void @use.i3(i3 [[AND]])
-; CHECK-NEXT:    [[OR:%.*]] = xor i3 [[A]], [[B]]
-; CHECK-NEXT:    ret i3 [[OR]]
-;
-  %and = and i3 %a, %b
-  call void @use.i3(i3 %and)
-  %xor1 = xor i3 %b, %and
-  %xor2 = xor i3 %a, %and
-  %or = or i3 %xor1, %xor2
-  ret i3 %or
-}
-
-define i32 @or_xor_xor_negative_multiple_uses_xor1(i32 %a, i32 %b) {
-; CHECK-LABEL: @or_xor_xor_negative_multiple_uses_xor1(
-; CHECK-NEXT:    [[AND:%.*]] = and i32 [[A:%.*]], [[B:%.*]]
-; CHECK-NEXT:    [[XOR1:%.*]] = xor i32 [[AND]], [[B]]
-; CHECK-NEXT:    call void @use.i32(i32 [[XOR1]])
-; CHECK-NEXT:    [[XOR2:%.*]] = xor i32 [[AND]], [[A]]
-; CHECK-NEXT:    [[OR:%.*]] = or i32 [[XOR1]], [[XOR2]]
-; CHECK-NEXT:    ret i32 [[OR]]
-;
-  %and = and i32 %a, %b
-  %xor1 = xor i32 %and, %b
-  call void @use.i32(i32 %xor1)
-  %xor2 = xor i32 %and, %a
-  %or = or i32 %xor1, %xor2
-  ret i32 %or
-}
-
-define i5 @or_xor_xor_negative_multiple_uses_xor2(i5 %a, i5 %b) {
-; CHECK-LABEL: @or_xor_xor_negative_multiple_uses_xor2(
-; CHECK-NEXT:    [[AND:%.*]] = and i5 [[A:%.*]], [[B:%.*]]
-; CHECK-NEXT:    [[XOR1:%.*]] = xor i5 [[AND]], [[B]]
-; CHECK-NEXT:    [[XOR2:%.*]] = xor i5 [[AND]], [[A]]
-; CHECK-NEXT:    call void @use.i5(i5 [[XOR2]])
-; CHECK-NEXT:    [[OR:%.*]] = or i5 [[XOR1]], [[XOR2]]
-; CHECK-NEXT:    ret i5 [[OR]]
-;
-  %and = and i5 %a, %b
-  %xor1 = xor i5 %and, %b
-  %xor2 = xor i5 %and, %a
-  call void @use.i5(i5 %xor2)
-  %or = or i5 %xor1, %xor2
-  ret i5 %or
-}

marcauberer referenced this pull request Sep 14, 2023
Depends on D159379

((A & B) ^ A) | ((A & B) ^ B) -> A ^ B
(A ^ (A & B)) | (B ^ (A & B)) -> A ^ B
((A & B) ^ B) | ((A & B) ^ A) -> A ^ B
(B ^ (A & B)) | (A ^ (A & B)) -> A ^ B

Alive2: https://alive2.llvm.org/ce/z/i44xmq
Baseline tests: https://reviews.llvm.org/D159379

Reviewed By: huihuiz

Differential Revision: https://reviews.llvm.org/D159380
Copy link
Contributor

@nikic nikic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@marcauberer
Copy link
Member Author

@nikic can you merge? I do not have permissions to do so.

@nikic nikic merged commit 1f31303 into llvm:main Sep 15, 2023
1 of 2 checks passed
@marcauberer marcauberer deleted the fix/remove-oneuse-check branch September 16, 2023 11:06
ZijunZhaoCCK pushed a commit to ZijunZhaoCCK/llvm-project that referenced this pull request Sep 19, 2023
This removes a oneUse check, that is actually unnecessary.

Alive2: https://alive2.llvm.org/ce/z/qEkUEf
Original patch: https://reviews.llvm.org/D159380
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants