Skip to content

Commit 77d6684

Browse files
committed
[ValueTracking] Add support for vector_reduce_{s,u}{min,max} in isKnownNonZero
Previously missing, proofs for all implementations: https://alive2.llvm.org/ce/z/G8wpmG
1 parent f9f4aba commit 77d6684

File tree

2 files changed

+9
-12
lines changed

2 files changed

+9
-12
lines changed

llvm/lib/Analysis/ValueTracking.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2824,6 +2824,12 @@ static bool isKnownNonZeroFromOperator(const Operator *I,
28242824
return isNonZeroAdd(DemandedElts, Depth, Q, BitWidth,
28252825
II->getArgOperand(0), II->getArgOperand(1),
28262826
/*NSW=*/true, /* NUW=*/false);
2827+
// umin/smin/smax/smin of all non-zero elements is always non-zero.
2828+
case Intrinsic::vector_reduce_umax:
2829+
case Intrinsic::vector_reduce_umin:
2830+
case Intrinsic::vector_reduce_smax:
2831+
case Intrinsic::vector_reduce_smin:
2832+
return isKnownNonZero(II->getArgOperand(0), Depth, Q);
28272833
case Intrinsic::umax:
28282834
case Intrinsic::uadd_sat:
28292835
return isKnownNonZero(II->getArgOperand(1), DemandedElts, Depth, Q) ||

llvm/test/Transforms/InstCombine/vector-reduce-min-max-known.ll

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,7 @@ define i1 @vec_reduce_umax_non_zero_fail(<4 x i8> %xx) {
2929

3030
define i1 @vec_reduce_umin_non_zero(<4 x i8> %xx) {
3131
; CHECK-LABEL: @vec_reduce_umin_non_zero(
32-
; CHECK-NEXT: [[X:%.*]] = add nuw <4 x i8> [[XX:%.*]], <i8 1, i8 1, i8 1, i8 1>
33-
; CHECK-NEXT: [[V:%.*]] = call i8 @llvm.vector.reduce.umin.v4i8(<4 x i8> [[X]])
34-
; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[V]], 0
35-
; CHECK-NEXT: ret i1 [[R]]
32+
; CHECK-NEXT: ret i1 false
3633
;
3734
%x = add nuw <4 x i8> %xx, <i8 1, i8 1, i8 1, i8 1>
3835
%v = call i8 @llvm.vector.reduce.umin(<4 x i8> %x)
@@ -55,10 +52,7 @@ define i1 @vec_reduce_umin_non_zero_fail(<4 x i8> %xx) {
5552

5653
define i1 @vec_reduce_smax_non_zero0(<4 x i8> %xx) {
5754
; CHECK-LABEL: @vec_reduce_smax_non_zero0(
58-
; CHECK-NEXT: [[X:%.*]] = add nuw <4 x i8> [[XX:%.*]], <i8 1, i8 1, i8 1, i8 1>
59-
; CHECK-NEXT: [[V:%.*]] = call i8 @llvm.vector.reduce.smax.v4i8(<4 x i8> [[X]])
60-
; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[V]], 0
61-
; CHECK-NEXT: ret i1 [[R]]
55+
; CHECK-NEXT: ret i1 false
6256
;
6357
%x = add nuw <4 x i8> %xx, <i8 1, i8 1, i8 1, i8 1>
6458
%v = call i8 @llvm.vector.reduce.smax(<4 x i8> %x)
@@ -98,10 +92,7 @@ define i1 @vec_reduce_smax_non_zero_fail(<4 x i8> %xx) {
9892

9993
define i1 @vec_reduce_smin_non_zero0(<4 x i8> %xx) {
10094
; CHECK-LABEL: @vec_reduce_smin_non_zero0(
101-
; CHECK-NEXT: [[X:%.*]] = add nuw <4 x i8> [[XX:%.*]], <i8 1, i8 1, i8 1, i8 1>
102-
; CHECK-NEXT: [[V:%.*]] = call i8 @llvm.vector.reduce.smin.v4i8(<4 x i8> [[X]])
103-
; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[V]], 0
104-
; CHECK-NEXT: ret i1 [[R]]
95+
; CHECK-NEXT: ret i1 false
10596
;
10697
%x = add nuw <4 x i8> %xx, <i8 1, i8 1, i8 1, i8 1>
10798
%v = call i8 @llvm.vector.reduce.smin(<4 x i8> %x)

0 commit comments

Comments
 (0)