Skip to content

Commit 217a937

Browse files
committed
[ValueTracking] Have sub and xor in KnownNonZero take the same exact path
If x - y == 0, then x ^ y == 0. Therefore, we can do the exact same checks. https://alive2.llvm.org/ce/z/MtBRoj
1 parent aa21780 commit 217a937

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

llvm/lib/Analysis/ValueTracking.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3036,14 +3036,12 @@ static bool isKnownNonZeroFromOperator(const Operator *I,
30363036
return isKnownNonZero(TI->getOperand(0), DemandedElts, Q, Depth);
30373037
break;
30383038

3039+
// Iff x - y != 0, then x ^ y != 0
3040+
// Therefore we can do the same exact checks
3041+
case Instruction::Xor:
30393042
case Instruction::Sub:
30403043
return isNonZeroSub(DemandedElts, Q, BitWidth, I->getOperand(0),
30413044
I->getOperand(1), Depth);
3042-
case Instruction::Xor:
3043-
// (X ^ (X != 0)) is non zero
3044-
if (matchOpWithOpEqZero(I->getOperand(0), I->getOperand(1)))
3045-
return true;
3046-
break;
30473045
case Instruction::Or:
30483046
// (X | (X != 0)) is non zero
30493047
if (matchOpWithOpEqZero(I->getOperand(0), I->getOperand(1)))

llvm/test/Transforms/InstCombine/ctpop-cttz.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ define i32 @ctpop_xor(i32 %x, i32 %y) {
134134
; CHECK-NEXT: br i1 [[CMP_NOT]], label [[FALSE:%.*]], label [[TRUE:%.*]]
135135
; CHECK: true:
136136
; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[X]], [[Y]]
137-
; CHECK-NEXT: [[RET:%.*]] = call range(i32 0, 33) i32 @llvm.ctpop.i32(i32 [[XOR]])
137+
; CHECK-NEXT: [[RET:%.*]] = call range(i32 1, 33) i32 @llvm.ctpop.i32(i32 [[XOR]])
138138
; CHECK-NEXT: ret i32 [[RET]]
139139
; CHECK: false:
140140
; CHECK-NEXT: ret i32 0

0 commit comments

Comments
 (0)