Skip to content

Commit b6bba9e

Browse files
committed
[InstCombine] Remove sub nuw C_Mask, X -> xor X, C_Mask canoncalization
1 parent 8a1174f commit b6bba9e

File tree

2 files changed

+3
-13
lines changed

2 files changed

+3
-13
lines changed

llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2424,16 +2424,6 @@ Instruction *InstCombinerImpl::visitSub(BinaryOperator &I) {
24242424

24252425
const APInt *Op0C;
24262426
if (match(Op0, m_APInt(Op0C))) {
2427-
if (Op0C->isMask()) {
2428-
// Turn this into a xor if LHS is 2^n-1 and the remaining bits are known
2429-
// zero. We don't use information from dominating conditions so this
2430-
// transform is easier to reverse if necessary.
2431-
KnownBits RHSKnown = llvm::computeKnownBits(
2432-
Op1, 0, SQ.getWithInstruction(&I).getWithoutDomCondCache());
2433-
if ((*Op0C | RHSKnown.Zero).isAllOnes())
2434-
return BinaryOperator::CreateXor(Op1, Op0);
2435-
}
2436-
24372427
// C - ((C3 -nuw X) & C2) --> (C - (C2 & C3)) + (X & C2) when:
24382428
// (C3 - ((C2 & C3) - 1)) is pow2
24392429
// ((C2 + C3) & ((C2 & C3) - 1)) == ((C2 & C3) - 1)

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ declare void @use(i32)
66
define i32 @low_mask_nsw_nuw(i32 %x) {
77
; CHECK-LABEL: @low_mask_nsw_nuw(
88
; CHECK-NEXT: [[AND:%.*]] = and i32 [[X:%.*]], 31
9-
; CHECK-NEXT: [[SUB:%.*]] = xor i32 [[AND]], 63
9+
; CHECK-NEXT: [[SUB:%.*]] = sub nuw nsw i32 63, [[AND]]
1010
; CHECK-NEXT: ret i32 [[SUB]]
1111
;
1212
%and = and i32 %x, 31
@@ -17,7 +17,7 @@ define i32 @low_mask_nsw_nuw(i32 %x) {
1717
define <2 x i32> @low_mask_nsw_nuw_vec(<2 x i32> %x) {
1818
; CHECK-LABEL: @low_mask_nsw_nuw_vec(
1919
; CHECK-NEXT: [[AND:%.*]] = and <2 x i32> [[X:%.*]], splat (i32 31)
20-
; CHECK-NEXT: [[SUB:%.*]] = xor <2 x i32> [[AND]], splat (i32 63)
20+
; CHECK-NEXT: [[SUB:%.*]] = sub nuw nsw <2 x i32> splat (i32 63), [[AND]]
2121
; CHECK-NEXT: ret <2 x i32> [[SUB]]
2222
;
2323
%and = and <2 x i32> %x, <i32 31, i32 31>
@@ -98,7 +98,7 @@ declare i32 @llvm.ctlz.i32(i32, i1)
9898
define i32 @range_masked_sub(i32 %x) {
9999
; CHECK-LABEL: @range_masked_sub(
100100
; CHECK-NEXT: [[COUNT:%.*]] = tail call range(i32 0, 33) i32 @llvm.ctlz.i32(i32 [[X:%.*]], i1 true) #[[ATTR1:[0-9]+]]
101-
; CHECK-NEXT: [[SUB:%.*]] = xor i32 [[COUNT]], 31
101+
; CHECK-NEXT: [[SUB:%.*]] = sub nuw nsw i32 31, [[COUNT]]
102102
; CHECK-NEXT: ret i32 [[SUB]]
103103
;
104104
%count = tail call i32 @llvm.ctlz.i32(i32 %x, i1 true) nounwind readnone

0 commit comments

Comments
 (0)