[llvm] 41c5221 - [ValueTracking] Add support for `vector_reduce_{s,u}{min,max}` in `computeKnownBits`
Noah Goldstein via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 10 08:41:05 PDT 2024
Author: Noah Goldstein
Date: 2024-04-10T10:40:48-05:00
New Revision: 41c52217b003ce9435ae534251b0d0d035495262
URL: https://github.com/llvm/llvm-project/commit/41c52217b003ce9435ae534251b0d0d035495262
DIFF: https://github.com/llvm/llvm-project/commit/41c52217b003ce9435ae534251b0d0d035495262.diff
LOG: [ValueTracking] Add support for `vector_reduce_{s,u}{min,max}` in `computeKnownBits`
Previously missing. We compute by just applying the reduce function on
the knownbits of each element.
Closes #88169
Added:
Modified:
llvm/lib/Analysis/ValueTracking.cpp
llvm/test/Transforms/InstCombine/vector-reduce-min-max-known.ll
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index 869a94d81f4dfd..4120876889dec9 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -1621,6 +1621,14 @@ static void computeKnownBitsFromOperator(const Operator *I,
computeKnownBits(I->getOperand(1), Known2, Depth + 1, Q);
Known = KnownBits::ssub_sat(Known, Known2);
break;
+ // for min/max reduce, any bit common to each element in the input vec
+ // is set in the output.
+ case Intrinsic::vector_reduce_umax:
+ case Intrinsic::vector_reduce_umin:
+ case Intrinsic::vector_reduce_smax:
+ case Intrinsic::vector_reduce_smin:
+ computeKnownBits(I->getOperand(0), Known, Depth + 1, Q);
+ break;
case Intrinsic::umin:
computeKnownBits(I->getOperand(0), Known, Depth + 1, Q);
computeKnownBits(I->getOperand(1), Known2, Depth + 1, Q);
diff --git a/llvm/test/Transforms/InstCombine/vector-reduce-min-max-known.ll b/llvm/test/Transforms/InstCombine/vector-reduce-min-max-known.ll
index 29c08b17ef885a..65d00083532621 100644
--- a/llvm/test/Transforms/InstCombine/vector-reduce-min-max-known.ll
+++ b/llvm/test/Transforms/InstCombine/vector-reduce-min-max-known.ll
@@ -130,10 +130,7 @@ define i1 @vec_reduce_smin_non_zero_fail(<4 x i8> %xx) {
define i8 @vec_reduce_umax_known0(<4 x i8> %xx) {
; CHECK-LABEL: @vec_reduce_umax_known0(
-; CHECK-NEXT: [[X:%.*]] = or <4 x i8> [[XX:%.*]], <i8 1, i8 1, i8 1, i8 1>
-; CHECK-NEXT: [[V:%.*]] = call i8 @llvm.vector.reduce.umax.v4i8(<4 x i8> [[X]])
-; CHECK-NEXT: [[R:%.*]] = and i8 [[V]], 1
-; CHECK-NEXT: ret i8 [[R]]
+; CHECK-NEXT: ret i8 1
;
%x = or <4 x i8> %xx, <i8 1, i8 1, i8 1, i8 1>
%v = call i8 @llvm.vector.reduce.umax(<4 x i8> %x)
@@ -182,10 +179,7 @@ define i8 @vec_reduce_umax_known_fail1(<4 x i8> %xx) {
define i8 @vec_reduce_umin_known0(<4 x i8> %xx) {
; CHECK-LABEL: @vec_reduce_umin_known0(
-; CHECK-NEXT: [[X:%.*]] = or <4 x i8> [[XX:%.*]], <i8 1, i8 1, i8 1, i8 1>
-; CHECK-NEXT: [[V:%.*]] = call i8 @llvm.vector.reduce.umin.v4i8(<4 x i8> [[X]])
-; CHECK-NEXT: [[R:%.*]] = and i8 [[V]], 1
-; CHECK-NEXT: ret i8 [[R]]
+; CHECK-NEXT: ret i8 1
;
%x = or <4 x i8> %xx, <i8 1, i8 1, i8 1, i8 1>
%v = call i8 @llvm.vector.reduce.umin(<4 x i8> %x)
@@ -235,10 +229,7 @@ define i8 @vec_reduce_umin_known_fail1(<4 x i8> %xx) {
define i8 @vec_reduce_smax_known(<4 x i8> %xx) {
; CHECK-LABEL: @vec_reduce_smax_known(
-; CHECK-NEXT: [[X:%.*]] = or <4 x i8> [[XX:%.*]], <i8 4, i8 4, i8 4, i8 5>
-; CHECK-NEXT: [[V:%.*]] = call i8 @llvm.vector.reduce.smax.v4i8(<4 x i8> [[X]])
-; CHECK-NEXT: [[R:%.*]] = and i8 [[V]], 4
-; CHECK-NEXT: ret i8 [[R]]
+; CHECK-NEXT: ret i8 4
;
%x = or <4 x i8> %xx, <i8 4, i8 4, i8 4, i8 5>
%v = call i8 @llvm.vector.reduce.smax(<4 x i8> %x)
@@ -261,10 +252,7 @@ define i8 @vec_reduce_smax_known_fail(<4 x i8> %xx) {
define i8 @vec_reduce_smin_known(<4 x i8> %xx) {
; CHECK-LABEL: @vec_reduce_smin_known(
-; CHECK-NEXT: [[X:%.*]] = or <4 x i8> [[XX:%.*]], <i8 8, i8 24, i8 56, i8 9>
-; CHECK-NEXT: [[V:%.*]] = call i8 @llvm.vector.reduce.smin.v4i8(<4 x i8> [[X]])
-; CHECK-NEXT: [[R:%.*]] = and i8 [[V]], 8
-; CHECK-NEXT: ret i8 [[R]]
+; CHECK-NEXT: ret i8 8
;
%x = or <4 x i8> %xx, <i8 8, i8 24, i8 56, i8 9>
%v = call i8 @llvm.vector.reduce.smin(<4 x i8> %x)
More information about the llvm-commits
mailing list