Skip to content

Commit 2e43aa5

Browse files
committed
[ValueTracking] Implement computeKnownBits for llvm.vector.reduce.xor
1 parent 3b9341f commit 2e43aa5

File tree

2 files changed

+20
-16
lines changed

2 files changed

+20
-16
lines changed

llvm/lib/Analysis/ValueTracking.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1631,6 +1631,22 @@ static void computeKnownBitsFromOperator(const Operator *I,
16311631
case Intrinsic::vector_reduce_smin:
16321632
computeKnownBits(I->getOperand(0), Known, Depth + 1, Q);
16331633
break;
1634+
case Intrinsic::vector_reduce_xor:
1635+
computeKnownBits(I->getOperand(0), Known, Depth + 1, Q);
1636+
// The zeros common to all vecs are zero in the output.
1637+
// If the number of elements is odd, then the common ones remain. If the
1638+
// number of elements is even, then the common ones becomes zeros.
1639+
if (auto *VecTy =
1640+
dyn_cast<FixedVectorType>(I->getOperand(0)->getType())) {
1641+
// Even, so the ones become zeros.
1642+
if ((VecTy->getNumElements() % 2) == 0) {
1643+
Known.Zero |= Known.One;
1644+
Known.One.clearAllBits();
1645+
}
1646+
1647+
} else
1648+
Known.One.clearAllBits();
1649+
break;
16341650
case Intrinsic::umin:
16351651
computeKnownBits(I->getOperand(0), Known, Depth + 1, Q);
16361652
computeKnownBits(I->getOperand(1), Known2, Depth + 1, Q);

llvm/test/Transforms/InstCombine/known-bits.ll

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,10 +1047,7 @@ define i8 @known_reduce_and_fail(<2 x i8> %xx) {
10471047

10481048
define i8 @known_reduce_xor_even(<2 x i8> %xx) {
10491049
; CHECK-LABEL: @known_reduce_xor_even(
1050-
; CHECK-NEXT: [[X:%.*]] = or <2 x i8> [[XX:%.*]], <i8 5, i8 3>
1051-
; CHECK-NEXT: [[V:%.*]] = call i8 @llvm.vector.reduce.xor.v2i8(<2 x i8> [[X]])
1052-
; CHECK-NEXT: [[R:%.*]] = and i8 [[V]], 1
1053-
; CHECK-NEXT: ret i8 [[R]]
1050+
; CHECK-NEXT: ret i8 0
10541051
;
10551052
%x = or <2 x i8> %xx, <i8 5, i8 3>
10561053
%v = call i8 @llvm.vector.reduce.xor(<2 x i8> %x)
@@ -1060,10 +1057,7 @@ define i8 @known_reduce_xor_even(<2 x i8> %xx) {
10601057

10611058
define i8 @known_reduce_xor_even2(<2 x i8> %xx) {
10621059
; CHECK-LABEL: @known_reduce_xor_even2(
1063-
; CHECK-NEXT: [[X:%.*]] = and <2 x i8> [[XX:%.*]], <i8 15, i8 15>
1064-
; CHECK-NEXT: [[V:%.*]] = call i8 @llvm.vector.reduce.xor.v2i8(<2 x i8> [[X]])
1065-
; CHECK-NEXT: [[R:%.*]] = and i8 [[V]], 16
1066-
; CHECK-NEXT: ret i8 [[R]]
1060+
; CHECK-NEXT: ret i8 0
10671061
;
10681062
%x = and <2 x i8> %xx, <i8 15, i8 15>
10691063
%v = call i8 @llvm.vector.reduce.xor(<2 x i8> %x)
@@ -1086,10 +1080,7 @@ define i8 @known_reduce_xor_even_fail(<2 x i8> %xx) {
10861080

10871081
define i8 @known_reduce_xor_odd(<3 x i8> %xx) {
10881082
; CHECK-LABEL: @known_reduce_xor_odd(
1089-
; CHECK-NEXT: [[X:%.*]] = or <3 x i8> [[XX:%.*]], <i8 5, i8 3, i8 9>
1090-
; CHECK-NEXT: [[V:%.*]] = call i8 @llvm.vector.reduce.xor.v3i8(<3 x i8> [[X]])
1091-
; CHECK-NEXT: [[R:%.*]] = and i8 [[V]], 1
1092-
; CHECK-NEXT: ret i8 [[R]]
1083+
; CHECK-NEXT: ret i8 1
10931084
;
10941085
%x = or <3 x i8> %xx, <i8 5, i8 3, i8 9>
10951086
%v = call i8 @llvm.vector.reduce.xor.v3i8(<3 x i8> %x)
@@ -1099,10 +1090,7 @@ define i8 @known_reduce_xor_odd(<3 x i8> %xx) {
10991090

11001091
define i8 @known_reduce_xor_odd2(<3 x i8> %xx) {
11011092
; CHECK-LABEL: @known_reduce_xor_odd2(
1102-
; CHECK-NEXT: [[X:%.*]] = and <3 x i8> [[XX:%.*]], <i8 15, i8 15, i8 31>
1103-
; CHECK-NEXT: [[V:%.*]] = call i8 @llvm.vector.reduce.xor.v3i8(<3 x i8> [[X]])
1104-
; CHECK-NEXT: [[R:%.*]] = and i8 [[V]], 32
1105-
; CHECK-NEXT: ret i8 [[R]]
1093+
; CHECK-NEXT: ret i8 0
11061094
;
11071095
%x = and <3 x i8> %xx, <i8 15, i8 15, i8 31>
11081096
%v = call i8 @llvm.vector.reduce.xor.v3i8(<3 x i8> %x)

0 commit comments

Comments
 (0)