Skip to content

Commit aecde43

Browse files
committed
[ValueTracking] Implement computeKnownFPClass for llvm.vector.reduce.{fmin,fmax,fmaximum,fminimum}
1 parent bda0fc0 commit aecde43

File tree

2 files changed

+13
-16
lines changed

2 files changed

+13
-16
lines changed

llvm/lib/Analysis/ValueTracking.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5004,6 +5004,15 @@ void computeKnownFPClass(const Value *V, const APInt &DemandedElts,
50045004

50055005
break;
50065006
}
5007+
// reduce min/max will choose an element from one of the vector elements,
5008+
// so we can infer and class information that is common to all elements.
5009+
case Intrinsic::vector_reduce_fmax:
5010+
case Intrinsic::vector_reduce_fmin:
5011+
case Intrinsic::vector_reduce_fmaximum:
5012+
case Intrinsic::vector_reduce_fminimum:
5013+
computeKnownFPClass(II->getArgOperand(0), Known, InterestedClasses,
5014+
Depth + 1, Q);
5015+
break;
50075016
case Intrinsic::trunc:
50085017
case Intrinsic::floor:
50095018
case Intrinsic::ceil:

llvm/test/Transforms/InstSimplify/known-never-infinity.ll

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,10 +1112,7 @@ define float @fcmp_ult_neginf_implies_class_assert(float %arg) {
11121112
define i1 @isKnownNeverInfinity_vector_reduce_maximum(<4 x double> %x) {
11131113
; CHECK-LABEL: define i1 @isKnownNeverInfinity_vector_reduce_maximum
11141114
; CHECK-SAME: (<4 x double> [[X:%.*]]) {
1115-
; CHECK-NEXT: [[NINF_X:%.*]] = fadd ninf <4 x double> [[X]], <double 1.000000e+00, double 1.000000e+00, double 1.000000e+00, double 1.000000e+00>
1116-
; CHECK-NEXT: [[OP:%.*]] = call double @llvm.vector.reduce.fmaximum.v4f64(<4 x double> [[NINF_X]])
1117-
; CHECK-NEXT: [[CMP:%.*]] = fcmp une double [[OP]], 0x7FF0000000000000
1118-
; CHECK-NEXT: ret i1 [[CMP]]
1115+
; CHECK-NEXT: ret i1 true
11191116
;
11201117
%ninf.x = fadd ninf <4 x double> %x, <double 1.0, double 1.0, double 1.0, double 1.0>
11211118
%op = call double @llvm.vector.reduce.fmaximum(<4 x double> %ninf.x)
@@ -1140,10 +1137,7 @@ define i1 @isKnownNeverInfinity_vector_reduce_maximum_fail(<4 x double> %x) {
11401137
define i1 @isKnownNeverInfinity_vector_reduce_minimum(<4 x double> %x) {
11411138
; CHECK-LABEL: define i1 @isKnownNeverInfinity_vector_reduce_minimum
11421139
; CHECK-SAME: (<4 x double> [[X:%.*]]) {
1143-
; CHECK-NEXT: [[NINF_X:%.*]] = fadd ninf <4 x double> [[X]], <double 1.000000e+00, double 1.000000e+00, double 1.000000e+00, double 1.000000e+00>
1144-
; CHECK-NEXT: [[OP:%.*]] = call double @llvm.vector.reduce.fminimum.v4f64(<4 x double> [[NINF_X]])
1145-
; CHECK-NEXT: [[CMP:%.*]] = fcmp une double [[OP]], 0x7FF0000000000000
1146-
; CHECK-NEXT: ret i1 [[CMP]]
1140+
; CHECK-NEXT: ret i1 true
11471141
;
11481142
%ninf.x = fadd ninf <4 x double> %x, <double 1.0, double 1.0, double 1.0, double 1.0>
11491143
%op = call double @llvm.vector.reduce.fminimum(<4 x double> %ninf.x)
@@ -1168,10 +1162,7 @@ define i1 @isKnownNeverInfinity_vector_reduce_minimum_fail(<4 x double> %x) {
11681162
define i1 @isKnownNeverInfinity_vector_reduce_fmax(<4 x double> %x) {
11691163
; CHECK-LABEL: define i1 @isKnownNeverInfinity_vector_reduce_fmax
11701164
; CHECK-SAME: (<4 x double> [[X:%.*]]) {
1171-
; CHECK-NEXT: [[NINF_X:%.*]] = fadd ninf <4 x double> [[X]], <double 1.000000e+00, double 1.000000e+00, double 1.000000e+00, double 1.000000e+00>
1172-
; CHECK-NEXT: [[OP:%.*]] = call double @llvm.vector.reduce.fmax.v4f64(<4 x double> [[NINF_X]])
1173-
; CHECK-NEXT: [[CMP:%.*]] = fcmp une double [[OP]], 0x7FF0000000000000
1174-
; CHECK-NEXT: ret i1 [[CMP]]
1165+
; CHECK-NEXT: ret i1 true
11751166
;
11761167
%ninf.x = fadd ninf <4 x double> %x, <double 1.0, double 1.0, double 1.0, double 1.0>
11771168
%op = call double @llvm.vector.reduce.fmax(<4 x double> %ninf.x)
@@ -1196,10 +1187,7 @@ define i1 @isKnownNeverInfinity_vector_reduce_fmax_fail(<4 x double> %x) {
11961187
define i1 @isKnownNeverInfinity_vector_reduce_fmin(<4 x double> %x) {
11971188
; CHECK-LABEL: define i1 @isKnownNeverInfinity_vector_reduce_fmin
11981189
; CHECK-SAME: (<4 x double> [[X:%.*]]) {
1199-
; CHECK-NEXT: [[NINF_X:%.*]] = fadd ninf <4 x double> [[X]], <double 1.000000e+00, double 1.000000e+00, double 1.000000e+00, double 1.000000e+00>
1200-
; CHECK-NEXT: [[OP:%.*]] = call double @llvm.vector.reduce.fmin.v4f64(<4 x double> [[NINF_X]])
1201-
; CHECK-NEXT: [[CMP:%.*]] = fcmp une double [[OP]], 0x7FF0000000000000
1202-
; CHECK-NEXT: ret i1 [[CMP]]
1190+
; CHECK-NEXT: ret i1 true
12031191
;
12041192
%ninf.x = fadd ninf <4 x double> %x, <double 1.0, double 1.0, double 1.0, double 1.0>
12051193
%op = call double @llvm.vector.reduce.fmin(<4 x double> %ninf.x)

0 commit comments

Comments
 (0)