Skip to content

Commit 8fa62ed

Browse files
author
git apple-llvm automerger
committed
Merge commit '5a8da55e9b71' from apple/main into swift/next
2 parents 76a9a66 + 5a8da55 commit 8fa62ed

File tree

2 files changed

+8
-12
lines changed

2 files changed

+8
-12
lines changed

llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3335,6 +3335,10 @@ Instruction *InstCombinerImpl::visitXor(BinaryOperator &I) {
33353335
match(Op1, m_Not(m_Specific(A))))
33363336
return BinaryOperator::CreateNot(Builder.CreateAnd(A, B));
33373337

3338+
// (~A & B) ^ A --> A | B -- There are 4 commuted variants.
3339+
if (match(&I, m_c_Xor(m_c_And(m_Not(m_Value(A)), m_Value(B)), m_Deferred(A))))
3340+
return BinaryOperator::CreateOr(A, B);
3341+
33383342
// (A | B) ^ (A | C) --> (B ^ C) & ~A -- There are 4 commuted variants.
33393343
// TODO: Loosen one-use restriction if common operand is a constant.
33403344
Value *D;

llvm/test/Transforms/InstCombine/xor.ll

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,9 +1176,7 @@ define i8 @not_ashr_wrong_const(i8 %x) {
11761176

11771177
define <2 x i32> @xor_andn_commute1(<2 x i32> %a, <2 x i32> %b) {
11781178
; CHECK-LABEL: @xor_andn_commute1(
1179-
; CHECK-NEXT: [[NOTA:%.*]] = xor <2 x i32> [[A:%.*]], <i32 -1, i32 -1>
1180-
; CHECK-NEXT: [[R:%.*]] = and <2 x i32> [[NOTA]], [[B:%.*]]
1181-
; CHECK-NEXT: [[Z:%.*]] = xor <2 x i32> [[R]], [[A]]
1179+
; CHECK-NEXT: [[Z:%.*]] = or <2 x i32> [[A:%.*]], [[B:%.*]]
11821180
; CHECK-NEXT: ret <2 x i32> [[Z]]
11831181
;
11841182
%nota = xor <2 x i32> %a, <i32 -1, i32 -1>
@@ -1192,9 +1190,7 @@ define <2 x i32> @xor_andn_commute1(<2 x i32> %a, <2 x i32> %b) {
11921190
define i33 @xor_andn_commute2(i33 %a, i33 %pb) {
11931191
; CHECK-LABEL: @xor_andn_commute2(
11941192
; CHECK-NEXT: [[B:%.*]] = udiv i33 42, [[PB:%.*]]
1195-
; CHECK-NEXT: [[NOTA:%.*]] = xor i33 [[A:%.*]], -1
1196-
; CHECK-NEXT: [[R:%.*]] = and i33 [[B]], [[NOTA]]
1197-
; CHECK-NEXT: [[Z:%.*]] = xor i33 [[R]], [[A]]
1193+
; CHECK-NEXT: [[Z:%.*]] = or i33 [[B]], [[A:%.*]]
11981194
; CHECK-NEXT: ret i33 [[Z]]
11991195
;
12001196
%b = udiv i33 42, %pb ; thwart complexity-based canonicalization
@@ -1209,9 +1205,7 @@ define i33 @xor_andn_commute2(i33 %a, i33 %pb) {
12091205
define i32 @xor_andn_commute3(i32 %pa, i32 %b) {
12101206
; CHECK-LABEL: @xor_andn_commute3(
12111207
; CHECK-NEXT: [[A:%.*]] = udiv i32 42, [[PA:%.*]]
1212-
; CHECK-NEXT: [[NOTA:%.*]] = xor i32 [[A]], -1
1213-
; CHECK-NEXT: [[R:%.*]] = and i32 [[NOTA]], [[B:%.*]]
1214-
; CHECK-NEXT: [[Z:%.*]] = xor i32 [[A]], [[R]]
1208+
; CHECK-NEXT: [[Z:%.*]] = or i32 [[A]], [[B:%.*]]
12151209
; CHECK-NEXT: ret i32 [[Z]]
12161210
;
12171211
%a = udiv i32 42, %pa ; thwart complexity-based canonicalization
@@ -1227,9 +1221,7 @@ define i32 @xor_andn_commute4(i32 %pa, i32 %pb) {
12271221
; CHECK-LABEL: @xor_andn_commute4(
12281222
; CHECK-NEXT: [[A:%.*]] = udiv i32 42, [[PA:%.*]]
12291223
; CHECK-NEXT: [[B:%.*]] = udiv i32 42, [[PB:%.*]]
1230-
; CHECK-NEXT: [[NOTA:%.*]] = xor i32 [[A]], -1
1231-
; CHECK-NEXT: [[R:%.*]] = and i32 [[B]], [[NOTA]]
1232-
; CHECK-NEXT: [[Z:%.*]] = xor i32 [[A]], [[R]]
1224+
; CHECK-NEXT: [[Z:%.*]] = or i32 [[A]], [[B]]
12331225
; CHECK-NEXT: ret i32 [[Z]]
12341226
;
12351227
%a = udiv i32 42, %pa ; thwart complexity-based canonicalization

0 commit comments

Comments
 (0)