Skip to content

Commit 10ce319

Browse files
authored
[AArch64][GlobalISel] Expand handling for sitofp and uitofp (#71282)
Similar to #70635, this expands the handling of integer to fp conversions. The code is very similar to the float->integer conversions with types handled oppositely. There are some extra unhandled cases which require more handling for ASR operations.
1 parent 6500268 commit 10ce319

File tree

3 files changed

+6224
-4
lines changed

3 files changed

+6224
-4
lines changed

llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5126,7 +5126,9 @@ LegalizerHelper::moreElementsVector(MachineInstr &MI, unsigned TypeIdx,
51265126
case TargetOpcode::G_FPTRUNC:
51275127
case TargetOpcode::G_FPEXT:
51285128
case TargetOpcode::G_FPTOSI:
5129-
case TargetOpcode::G_FPTOUI: {
5129+
case TargetOpcode::G_FPTOUI:
5130+
case TargetOpcode::G_SITOFP:
5131+
case TargetOpcode::G_UITOFP: {
51305132
if (TypeIdx != 0)
51315133
return UnableToLegalize;
51325134
Observer.changingInstr(MI);

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

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -673,10 +673,33 @@ AArch64LegalizerInfo::AArch64LegalizerInfo(const AArch64Subtarget &ST)
673673

674674
getActionDefinitionsBuilder({G_SITOFP, G_UITOFP})
675675
.legalForCartesianProduct({s32, s64, v2s64, v4s32, v2s32})
676+
.legalIf([=](const LegalityQuery &Query) {
677+
return HasFP16 &&
678+
(Query.Types[0] == s16 || Query.Types[0] == v4s16 ||
679+
Query.Types[0] == v8s16) &&
680+
(Query.Types[1] == s32 || Query.Types[1] == s64 ||
681+
Query.Types[1] == v4s16 || Query.Types[1] == v8s16);
682+
})
683+
.widenScalarToNextPow2(1)
676684
.clampScalar(1, s32, s64)
677-
.minScalarSameAs(1, 0)
678-
.clampScalar(0, s32, s64)
679-
.widenScalarToNextPow2(0);
685+
.widenScalarToNextPow2(0)
686+
.clampScalarOrElt(0, MinFPScalar, s64)
687+
.moreElementsToNextPow2(0)
688+
.widenScalarIf(
689+
[=](const LegalityQuery &Query) {
690+
return Query.Types[0].getScalarSizeInBits() <
691+
Query.Types[1].getScalarSizeInBits();
692+
},
693+
LegalizeMutations::changeElementSizeTo(0, 1))
694+
.widenScalarIf(
695+
[=](const LegalityQuery &Query) {
696+
return Query.Types[0].getScalarSizeInBits() >
697+
Query.Types[1].getScalarSizeInBits();
698+
},
699+
LegalizeMutations::changeElementSizeTo(1, 0))
700+
.clampNumElements(0, v4s16, v8s16)
701+
.clampNumElements(0, v2s32, v4s32)
702+
.clampMaxNumElements(0, s64, 2);
680703

681704
// Control-flow
682705
getActionDefinitionsBuilder(G_BRCOND)

0 commit comments

Comments
 (0)