Skip to content

Commit 362d00e

Browse files
committed
[ARM][VecReduce] Force expand vector_reduce_fmin
Under MVE, we do not have any lowering for fminimum, which a vector_reduce_fmin without NoNan will be expanded into. As with the other recent patches, force this to expand in the pre-isel pass. Note that Neon lowering would be OK because the scalar fminimum uses the vector VMIN instruction, but is probably better to just rely on the scalar operations, which is what is done here. Also fixes what appears to be the reversal of INF vs -INF in the vector_reduce_fmin widening code.
1 parent b8144c0 commit 362d00e

File tree

4 files changed

+2273
-6
lines changed

4 files changed

+2273
-6
lines changed

llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4678,11 +4678,11 @@ SDValue DAGTypeLegalizer::WidenVecOp_VECREDUCE(SDNode *N) {
46784678
break;
46794679
case ISD::VECREDUCE_FMAX:
46804680
NeutralElem = DAG.getConstantFP(
4681-
std::numeric_limits<double>::infinity(), dl, ElemVT);
4681+
-std::numeric_limits<double>::infinity(), dl, ElemVT);
46824682
break;
46834683
case ISD::VECREDUCE_FMIN:
46844684
NeutralElem = DAG.getConstantFP(
4685-
-std::numeric_limits<double>::infinity(), dl, ElemVT);
4685+
std::numeric_limits<double>::infinity(), dl, ElemVT);
46864686
break;
46874687
}
46884688

llvm/lib/Target/ARM/ARMTargetTransformInfo.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,12 +176,15 @@ class ARMTTIImpl : public BasicTTIImplBase<ARMTTIImpl> {
176176
// We don't have legalization support for ordered FP reductions.
177177
if (!II->getFastMathFlags().allowReassoc())
178178
return true;
179-
LLVM_FALLTHROUGH;
179+
// Can't legalize reductions with soft floats.
180+
return TLI->useSoftFloat() || !TLI->getSubtarget()->hasFPRegs();
180181

181182
case Intrinsic::experimental_vector_reduce_fmin:
182183
case Intrinsic::experimental_vector_reduce_fmax:
183-
// Can't legalize reductions with soft floats.
184-
return TLI->useSoftFloat() || !TLI->getSubtarget()->hasFPRegs();
184+
// Can't legalize reductions with soft floats, and NoNan will create
185+
// fminimum which we do not know how to lower.
186+
return TLI->useSoftFloat() || !TLI->getSubtarget()->hasFPRegs() ||
187+
!II->getFastMathFlags().noNaNs();
185188

186189
default:
187190
// Don't expand anything else, let legalization deal with it.

llvm/test/CodeGen/AArch64/vecreduce-fmax-legalization.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ define fp128 @test_v1f128(<1 x fp128> %a) nounwind {
4747
define float @test_v3f32(<3 x float> %a) nounwind {
4848
; CHECK-LABEL: test_v3f32:
4949
; CHECK: // %bb.0:
50-
; CHECK-NEXT: mov w8, #2139095040
50+
; CHECK-NEXT: mov w8, #-8388608
5151
; CHECK-NEXT: fmov s1, w8
5252
; CHECK-NEXT: mov v0.s[3], v1.s[0]
5353
; CHECK-NEXT: fmaxnmv s0, v0.4s

0 commit comments

Comments
 (0)