Loading llvm/test/Transforms/InstCombine/and-xor-or.ll +74 −0 Original line number Diff line number Diff line Loading @@ -516,3 +516,77 @@ define i64 @sext_or_chain_two_uses2(i64 %a, i16 %b, i16 %c, i64 %d) { %use2 = udiv i64 %or2, %use1 ret i64 %use2 } ; (a & ~b) & ~c --> a & ~(b | c) define i32 @not_and_and_not(i32 %a0, i32 %b, i32 %c) { ; CHECK-LABEL: @not_and_and_not( ; CHECK-NEXT: [[A:%.*]] = sdiv i32 42, [[A0:%.*]] ; CHECK-NEXT: [[NOT1:%.*]] = xor i32 [[B:%.*]], -1 ; CHECK-NEXT: [[NOT2:%.*]] = xor i32 [[C:%.*]], -1 ; CHECK-NEXT: [[AND1:%.*]] = and i32 [[A]], [[NOT1]] ; CHECK-NEXT: [[AND2:%.*]] = and i32 [[AND1]], [[NOT2]] ; CHECK-NEXT: ret i32 [[AND2]] ; %a = sdiv i32 42, %a0 ; thwart complexity-based canonicalization %not1 = xor i32 %b, -1 %not2 = xor i32 %c, -1 %and1 = and i32 %a, %not1 %and2 = and i32 %and1, %not2 ret i32 %and2 } define <4 x i64> @not_and_and_not_4i64(<4 x i64> %a0, <4 x i64> %b, <4 x i64> %c) { ; CHECK-LABEL: @not_and_and_not_4i64( ; CHECK-NEXT: [[A:%.*]] = sdiv <4 x i64> <i64 42, i64 42, i64 42, i64 42>, [[A0:%.*]] ; CHECK-NEXT: [[NOT1:%.*]] = xor <4 x i64> [[B:%.*]], <i64 -1, i64 -1, i64 -1, i64 -1> ; CHECK-NEXT: [[NOT2:%.*]] = xor <4 x i64> [[C:%.*]], <i64 -1, i64 -1, i64 -1, i64 -1> ; CHECK-NEXT: [[AND1:%.*]] = and <4 x i64> [[A]], [[NOT1]] ; CHECK-NEXT: [[AND2:%.*]] = and <4 x i64> [[AND1]], [[NOT2]] ; CHECK-NEXT: ret <4 x i64> [[AND2]] ; %a = sdiv <4 x i64> <i64 42, i64 42, i64 42, i64 42>, %a0 ; thwart complexity-based canonicalization %not1 = xor <4 x i64> %b, <i64 -1, i64 -1, i64 -1, i64 -1> %not2 = xor <4 x i64> %c, <i64 -1, i64 -1, i64 -1, i64 -1> %and1 = and <4 x i64> %a, %not1 %and2 = and <4 x i64> %and1, %not2 ret <4 x i64> %and2 } ; (~b & a) & ~c --> a & ~(b | c) define i32 @not_and_and_not_commute1(i32 %a0, i32 %b, i32 %c) { ; CHECK-LABEL: @not_and_and_not_commute1( ; CHECK-NEXT: [[A:%.*]] = sdiv i32 42, [[A0:%.*]] ; CHECK-NEXT: [[NOT1:%.*]] = xor i32 [[B:%.*]], -1 ; CHECK-NEXT: [[NOT2:%.*]] = xor i32 [[C:%.*]], -1 ; CHECK-NEXT: [[AND1:%.*]] = and i32 [[A]], [[NOT1]] ; CHECK-NEXT: [[AND2:%.*]] = and i32 [[AND1]], [[NOT2]] ; CHECK-NEXT: ret i32 [[AND2]] ; %a = sdiv i32 42, %a0 ; thwart complexity-based canonicalization %not1 = xor i32 %b, -1 %not2 = xor i32 %c, -1 %and1 = and i32 %not1, %a %and2 = and i32 %and1, %not2 ret i32 %and2 } ; ~c & (a & ~b) --> a & ~(b | c) define i32 @not_and_and_not_commute2(i32 %a0, i32 %b, i32 %c) { ; CHECK-LABEL: @not_and_and_not_commute2( ; CHECK-NEXT: [[A:%.*]] = sdiv i32 42, [[A0:%.*]] ; CHECK-NEXT: [[NOT1:%.*]] = xor i32 [[B:%.*]], -1 ; CHECK-NEXT: [[NOT2:%.*]] = xor i32 [[C:%.*]], -1 ; CHECK-NEXT: [[AND1:%.*]] = and i32 [[A]], [[NOT1]] ; CHECK-NEXT: [[AND2:%.*]] = and i32 [[AND1]], [[NOT2]] ; CHECK-NEXT: ret i32 [[AND2]] ; %a = sdiv i32 42, %a0 ; thwart complexity-based canonicalization %not1 = xor i32 %b, -1 %not2 = xor i32 %c, -1 %and1 = and i32 %a, %not1 %and2 = and i32 %not2, %and1 ret i32 %and2 } Loading
llvm/test/Transforms/InstCombine/and-xor-or.ll +74 −0 Original line number Diff line number Diff line Loading @@ -516,3 +516,77 @@ define i64 @sext_or_chain_two_uses2(i64 %a, i16 %b, i16 %c, i64 %d) { %use2 = udiv i64 %or2, %use1 ret i64 %use2 } ; (a & ~b) & ~c --> a & ~(b | c) define i32 @not_and_and_not(i32 %a0, i32 %b, i32 %c) { ; CHECK-LABEL: @not_and_and_not( ; CHECK-NEXT: [[A:%.*]] = sdiv i32 42, [[A0:%.*]] ; CHECK-NEXT: [[NOT1:%.*]] = xor i32 [[B:%.*]], -1 ; CHECK-NEXT: [[NOT2:%.*]] = xor i32 [[C:%.*]], -1 ; CHECK-NEXT: [[AND1:%.*]] = and i32 [[A]], [[NOT1]] ; CHECK-NEXT: [[AND2:%.*]] = and i32 [[AND1]], [[NOT2]] ; CHECK-NEXT: ret i32 [[AND2]] ; %a = sdiv i32 42, %a0 ; thwart complexity-based canonicalization %not1 = xor i32 %b, -1 %not2 = xor i32 %c, -1 %and1 = and i32 %a, %not1 %and2 = and i32 %and1, %not2 ret i32 %and2 } define <4 x i64> @not_and_and_not_4i64(<4 x i64> %a0, <4 x i64> %b, <4 x i64> %c) { ; CHECK-LABEL: @not_and_and_not_4i64( ; CHECK-NEXT: [[A:%.*]] = sdiv <4 x i64> <i64 42, i64 42, i64 42, i64 42>, [[A0:%.*]] ; CHECK-NEXT: [[NOT1:%.*]] = xor <4 x i64> [[B:%.*]], <i64 -1, i64 -1, i64 -1, i64 -1> ; CHECK-NEXT: [[NOT2:%.*]] = xor <4 x i64> [[C:%.*]], <i64 -1, i64 -1, i64 -1, i64 -1> ; CHECK-NEXT: [[AND1:%.*]] = and <4 x i64> [[A]], [[NOT1]] ; CHECK-NEXT: [[AND2:%.*]] = and <4 x i64> [[AND1]], [[NOT2]] ; CHECK-NEXT: ret <4 x i64> [[AND2]] ; %a = sdiv <4 x i64> <i64 42, i64 42, i64 42, i64 42>, %a0 ; thwart complexity-based canonicalization %not1 = xor <4 x i64> %b, <i64 -1, i64 -1, i64 -1, i64 -1> %not2 = xor <4 x i64> %c, <i64 -1, i64 -1, i64 -1, i64 -1> %and1 = and <4 x i64> %a, %not1 %and2 = and <4 x i64> %and1, %not2 ret <4 x i64> %and2 } ; (~b & a) & ~c --> a & ~(b | c) define i32 @not_and_and_not_commute1(i32 %a0, i32 %b, i32 %c) { ; CHECK-LABEL: @not_and_and_not_commute1( ; CHECK-NEXT: [[A:%.*]] = sdiv i32 42, [[A0:%.*]] ; CHECK-NEXT: [[NOT1:%.*]] = xor i32 [[B:%.*]], -1 ; CHECK-NEXT: [[NOT2:%.*]] = xor i32 [[C:%.*]], -1 ; CHECK-NEXT: [[AND1:%.*]] = and i32 [[A]], [[NOT1]] ; CHECK-NEXT: [[AND2:%.*]] = and i32 [[AND1]], [[NOT2]] ; CHECK-NEXT: ret i32 [[AND2]] ; %a = sdiv i32 42, %a0 ; thwart complexity-based canonicalization %not1 = xor i32 %b, -1 %not2 = xor i32 %c, -1 %and1 = and i32 %not1, %a %and2 = and i32 %and1, %not2 ret i32 %and2 } ; ~c & (a & ~b) --> a & ~(b | c) define i32 @not_and_and_not_commute2(i32 %a0, i32 %b, i32 %c) { ; CHECK-LABEL: @not_and_and_not_commute2( ; CHECK-NEXT: [[A:%.*]] = sdiv i32 42, [[A0:%.*]] ; CHECK-NEXT: [[NOT1:%.*]] = xor i32 [[B:%.*]], -1 ; CHECK-NEXT: [[NOT2:%.*]] = xor i32 [[C:%.*]], -1 ; CHECK-NEXT: [[AND1:%.*]] = and i32 [[A]], [[NOT1]] ; CHECK-NEXT: [[AND2:%.*]] = and i32 [[AND1]], [[NOT2]] ; CHECK-NEXT: ret i32 [[AND2]] ; %a = sdiv i32 42, %a0 ; thwart complexity-based canonicalization %not1 = xor i32 %b, -1 %not2 = xor i32 %c, -1 %and1 = and i32 %a, %not1 %and2 = and i32 %not2, %and1 ret i32 %and2 }