[PATCH] D114339: [InstCombine] simplify (~A | B) ^ A --> ~( A & B)
Mehrnoosh Heidarpour via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sat Nov 27 09:41:33 PST 2021
MehrHeidar updated this revision to Diff 390167.
MehrHeidar marked 2 inline comments as done.
MehrHeidar added a comment.
Addressing review comments.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D114339/new/
https://reviews.llvm.org/D114339
Files:
llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
llvm/test/Transforms/InstCombine/xor.ll
Index: llvm/test/Transforms/InstCombine/xor.ll
===================================================================
--- llvm/test/Transforms/InstCombine/xor.ll
+++ llvm/test/Transforms/InstCombine/xor.ll
@@ -1236,9 +1236,8 @@
define <2 x i64> @xor_orn(<2 x i64> %a, <2 x i64> %b) {
; CHECK-LABEL: @xor_orn(
-; CHECK-NEXT: [[NOTA:%.*]] = xor <2 x i64> [[A:%.*]], <i64 -1, i64 -1>
-; CHECK-NEXT: [[L:%.*]] = or <2 x i64> [[NOTA]], [[B:%.*]]
-; CHECK-NEXT: [[Z:%.*]] = xor <2 x i64> [[L]], [[A]]
+; CHECK-NEXT: [[TMP1:%.*]] = and <2 x i64> [[A:%.*]], [[B:%.*]]
+; CHECK-NEXT: [[Z:%.*]] = xor <2 x i64> [[TMP1]], <i64 -1, i64 -1>
; CHECK-NEXT: ret <2 x i64> [[Z]]
;
%nota = xor <2 x i64> %a, <i64 -1, i64 -1>
@@ -1252,9 +1251,8 @@
define i8 @xor_orn_commute1(i8 %pa, i8 %b) {
; CHECK-LABEL: @xor_orn_commute1(
; CHECK-NEXT: [[A:%.*]] = udiv i8 42, [[PA:%.*]]
-; CHECK-NEXT: [[NOTA:%.*]] = xor i8 [[A]], -1
-; CHECK-NEXT: [[L:%.*]] = or i8 [[NOTA]], [[B:%.*]]
-; CHECK-NEXT: [[Z:%.*]] = xor i8 [[A]], [[L]]
+; CHECK-NEXT: [[TMP1:%.*]] = and i8 [[A]], [[B:%.*]]
+; CHECK-NEXT: [[Z:%.*]] = xor i8 [[TMP1]], -1
; CHECK-NEXT: ret i8 [[Z]]
;
%a = udiv i8 42, %pa
@@ -1269,9 +1267,8 @@
define i32 @xor_orn_commute2(i32 %a, i32 %pb,i32* %s) {
; CHECK-LABEL: @xor_orn_commute2(
; CHECK-NEXT: [[B:%.*]] = udiv i32 42, [[PB:%.*]]
-; CHECK-NEXT: [[NOTA:%.*]] = xor i32 [[A:%.*]], -1
-; CHECK-NEXT: [[L:%.*]] = or i32 [[B]], [[NOTA]]
-; CHECK-NEXT: [[Z:%.*]] = xor i32 [[L]], [[A]]
+; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[B]], [[A:%.*]]
+; CHECK-NEXT: [[Z:%.*]] = xor i32 [[TMP1]], -1
; CHECK-NEXT: ret i32 [[Z]]
;
%b = udiv i32 42, %pb
@@ -1286,9 +1283,9 @@
; CHECK-LABEL: @xor_orn_commute2_1use(
; CHECK-NEXT: [[B:%.*]] = udiv i32 42, [[PB:%.*]]
; CHECK-NEXT: [[NOTA:%.*]] = xor i32 [[A:%.*]], -1
-; CHECK-NEXT: [[L:%.*]] = or i32 [[B]], [[NOTA]]
; CHECK-NEXT: store i32 [[NOTA]], i32* [[S:%.*]], align 4
-; CHECK-NEXT: [[Z:%.*]] = xor i32 [[L]], [[A]]
+; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[B]], [[A]]
+; CHECK-NEXT: [[Z:%.*]] = xor i32 [[TMP1]], -1
; CHECK-NEXT: ret i32 [[Z]]
;
%b = udiv i32 42, %pb
@@ -1305,9 +1302,8 @@
; CHECK-LABEL: @xor_orn_commute3(
; CHECK-NEXT: [[A:%.*]] = udiv i67 42, [[PA:%.*]]
; CHECK-NEXT: [[B:%.*]] = udiv i67 42, [[PB:%.*]]
-; CHECK-NEXT: [[NOTA:%.*]] = xor i67 [[A]], -1
-; CHECK-NEXT: [[L:%.*]] = or i67 [[B]], [[NOTA]]
-; CHECK-NEXT: [[Z:%.*]] = xor i67 [[A]], [[L]]
+; CHECK-NEXT: [[TMP1:%.*]] = and i67 [[A]], [[B]]
+; CHECK-NEXT: [[Z:%.*]] = xor i67 [[TMP1]], -1
; CHECK-NEXT: ret i67 [[Z]]
;
%a = udiv i67 42, %pa
Index: llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
===================================================================
--- llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
+++ llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
@@ -3624,6 +3624,14 @@
if (match(&I, m_c_Xor(m_c_And(m_Not(m_Value(A)), m_Value(B)), m_Deferred(A))))
return BinaryOperator::CreateOr(A, B);
+ // (~A | B) ^ A --> ~(A & B)
+ if (match(Op0, m_OneUse(m_c_Or(m_Not(m_Specific(Op1)), m_Value(B)))))
+ return BinaryOperator::CreateNot(Builder.CreateAnd(Op1, B));
+
+ // A ^ (~A | B) --> ~(A & B)
+ if (match(Op1, m_OneUse(m_c_Or(m_Not(m_Specific(Op0)), m_Value(B)))))
+ return BinaryOperator::CreateNot(Builder.CreateAnd(Op0, B));
+
// (A | B) ^ (A | C) --> (B ^ C) & ~A -- There are 4 commuted variants.
// TODO: Loosen one-use restriction if common operand is a constant.
Value *D;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D114339.390167.patch
Type: text/x-patch
Size: 3599 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211127/73bf1c56/attachment.bin>
More information about the llvm-commits
mailing list