Skip to content

Commit 295edaa

Browse files
committed
[AArch64][GlobalISel] Better vecreduce.fadd lowering. (PR #73294)
This changes the fadd legalization to handle fp16 types, and treats more types as legal so that the backend can produce the correct patterns. This is currently a missing identity fold for `fadd x -0.0 -> x`
1 parent 5eb85c0 commit 295edaa

File tree

3 files changed

+599
-382
lines changed

3 files changed

+599
-382
lines changed

llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2820,6 +2820,7 @@ LegalizerHelper::widenScalar(MachineInstr &MI, unsigned TypeIdx, LLT WideTy) {
28202820
Observer.changedInstr(MI);
28212821
return Legalized;
28222822
}
2823+
case TargetOpcode::G_VECREDUCE_FADD:
28232824
case TargetOpcode::G_VECREDUCE_FMIN:
28242825
case TargetOpcode::G_VECREDUCE_FMAX:
28252826
case TargetOpcode::G_VECREDUCE_FMINIMUM:

llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -970,11 +970,19 @@ AArch64LegalizerInfo::AArch64LegalizerInfo(const AArch64Subtarget &ST)
970970
.legalFor(PackedVectorAllTypeList)
971971
.lowerIf(isScalar(0));
972972

973+
// For fadd reductions we have pairwise operations available. We treat the
974+
// usual legal types as legal and handle the lowering to pairwise instructions
975+
// later.
973976
getActionDefinitionsBuilder(G_VECREDUCE_FADD)
974-
// We only have FADDP to do reduction-like operations. Lower the rest.
975-
.legalFor({{s32, v2s32}, {s64, v2s64}})
977+
.legalFor({{s32, v2s32}, {s32, v4s32}, {s64, v2s64}})
978+
.legalIf([=](const LegalityQuery &Query) {
979+
const auto &Ty = Query.Types[1];
980+
return (Ty == v4s16 || Ty == v8s16) && HasFP16;
981+
})
982+
.minScalarOrElt(0, MinFPScalar)
976983
.clampMaxNumElements(1, s64, 2)
977-
.clampMaxNumElements(1, s32, 2)
984+
.clampMaxNumElements(1, s32, 4)
985+
.clampMaxNumElements(1, s16, 8)
978986
.lower();
979987

980988
getActionDefinitionsBuilder(G_VECREDUCE_ADD)

0 commit comments

Comments
 (0)