Skip to content

Commit 54574d3

Browse files
authored
[AArch64][GlobalISel] Expand handling for fptosi and fptoui (#70635)
Now that we have more types handled for zext/sext and trunc, it is possible to get more types working for the vector float to integer conversions. This patch adds fp16, widening and narrowing vector support to handle more types. The smaller types wil be expanded to the size of the larger element type. A couple of case require more awkward truncates to get working as they go from illegal to illegal types.
1 parent cd60229 commit 54574d3

File tree

4 files changed

+3181
-2376
lines changed

4 files changed

+3181
-2376
lines changed

llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5124,7 +5124,9 @@ LegalizerHelper::moreElementsVector(MachineInstr &MI, unsigned TypeIdx,
51245124
}
51255125
case TargetOpcode::G_TRUNC:
51265126
case TargetOpcode::G_FPTRUNC:
5127-
case TargetOpcode::G_FPEXT: {
5127+
case TargetOpcode::G_FPEXT:
5128+
case TargetOpcode::G_FPTOSI:
5129+
case TargetOpcode::G_FPTOUI: {
51285130
if (TypeIdx != 0)
51295131
return UnableToLegalize;
51305132
Observer.changingInstr(MI);

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

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -643,10 +643,33 @@ AArch64LegalizerInfo::AArch64LegalizerInfo(const AArch64Subtarget &ST)
643643
// Conversions
644644
getActionDefinitionsBuilder({G_FPTOSI, G_FPTOUI})
645645
.legalForCartesianProduct({s32, s64, v2s64, v4s32, v2s32})
646+
.legalIf([=](const LegalityQuery &Query) {
647+
return HasFP16 &&
648+
(Query.Types[1] == s16 || Query.Types[1] == v4s16 ||
649+
Query.Types[1] == v8s16) &&
650+
(Query.Types[0] == s32 || Query.Types[0] == s64 ||
651+
Query.Types[0] == v4s16 || Query.Types[0] == v8s16);
652+
})
646653
.widenScalarToNextPow2(0)
647654
.clampScalar(0, s32, s64)
648655
.widenScalarToNextPow2(1)
649-
.clampScalar(1, s32, s64);
656+
.clampScalarOrElt(1, MinFPScalar, s64)
657+
.moreElementsToNextPow2(0)
658+
.widenScalarIf(
659+
[=](const LegalityQuery &Query) {
660+
return Query.Types[0].getScalarSizeInBits() >
661+
Query.Types[1].getScalarSizeInBits();
662+
},
663+
LegalizeMutations::changeElementSizeTo(1, 0))
664+
.widenScalarIf(
665+
[=](const LegalityQuery &Query) {
666+
return Query.Types[0].getScalarSizeInBits() <
667+
Query.Types[1].getScalarSizeInBits();
668+
},
669+
LegalizeMutations::changeElementSizeTo(0, 1))
670+
.clampNumElements(0, v4s16, v8s16)
671+
.clampNumElements(0, v2s32, v4s32)
672+
.clampMaxNumElements(0, s64, 2);
650673

651674
getActionDefinitionsBuilder({G_SITOFP, G_UITOFP})
652675
.legalForCartesianProduct({s32, s64, v2s64, v4s32, v2s32})

llvm/test/CodeGen/AArch64/GlobalISel/legalizer-info-validation.mir

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -503,12 +503,12 @@
503503
# DEBUG-NEXT: .. the first uncovered type index: 2, OK
504504
# DEBUG-NEXT: .. the first uncovered imm index: 0, OK
505505
# DEBUG-NEXT: G_FPTOSI (opcode {{[0-9]+}}): 2 type indices, 0 imm indices
506-
# DEBUG-NEXT: .. the first uncovered type index: 2, OK
507-
# DEBUG-NEXT: .. the first uncovered imm index: 0, OK
506+
# DEBUG-NEXT: .. type index coverage check SKIPPED: user-defined predicate detected
507+
# DEBUG-NEXT: .. imm index coverage check SKIPPED: user-defined predicate detected
508508
# DEBUG-NEXT: G_FPTOUI (opcode {{[0-9]+}}): 2 type indices, 0 imm indices
509509
# DEBUG-NEXT: .. opcode {{[0-9]+}} is aliased to {{[0-9]+}}
510-
# DEBUG-NEXT: .. the first uncovered type index: 2, OK
511-
# DEBUG-NEXT: .. the first uncovered imm index: 0, OK
510+
# DEBUG-NEXT: .. type index coverage check SKIPPED: user-defined predicate detected
511+
# DEBUG-NEXT: .. imm index coverage check SKIPPED: user-defined predicate detected
512512
# DEBUG-NEXT: G_SITOFP (opcode {{[0-9]+}}): 2 type indices, 0 imm indices
513513
# DEBUG-NEXT: .. type index coverage check SKIPPED: user-defined predicate detected
514514
# DEBUG-NEXT: .. imm index coverage check SKIPPED: user-defined predicate detected

0 commit comments

Comments
 (0)