diff --git a/llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp b/llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp --- a/llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp +++ b/llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp @@ -71,6 +71,11 @@ return; } + // Some instructions only support s16 if the subtarget has full 16-bit FP + // support. + const bool HasFP16 = ST.hasFullFP16(); + const LLT &MinFPScalar = HasFP16 ? s16 : s32; + getActionDefinitionsBuilder({G_IMPLICIT_DEF, G_FREEZE}) .legalFor({p0, s1, s8, s16, s32, s64}) .legalFor(PackedVectorAllTypeList) @@ -323,9 +328,13 @@ .clampScalar(0, s8, s64) .widenScalarToNextPow2(0); getActionDefinitionsBuilder(G_FCONSTANT) - .legalFor({s32, s64}) - .clampScalar(0, s32, s64); - + .legalIf([=](const LegalityQuery &Query) { + const auto &Ty = Query.Types[0]; + if (HasFP16 && Ty == s16) + return true; + return Ty == s32 || Ty == s64; + }) + .clampScalar(0, MinFPScalar, s64); getActionDefinitionsBuilder({G_ICMP, G_FCMP}) .legalFor({{s32, s32}, diff --git a/llvm/test/CodeGen/AArch64/GlobalISel/legalize-fp16-fconstant.mir b/llvm/test/CodeGen/AArch64/GlobalISel/legalize-fp16-fconstant.mir new file mode 100644 --- /dev/null +++ b/llvm/test/CodeGen/AArch64/GlobalISel/legalize-fp16-fconstant.mir @@ -0,0 +1,22 @@ +# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py +# RUN: llc -mtriple aarch64-unknown-unknown -verify-machineinstrs -run-pass=legalizer %s -o - | FileCheck %s --check-prefix=NO-FP16 +# RUN: llc -mtriple aarch64-unknown-unknown -verify-machineinstrs -mattr=+fullfp16 -run-pass=legalizer %s -o - | FileCheck %s --check-prefix=FP16 + +--- +name: fp16 +tracksRegLiveness: true +body: | + bb.0: + ; NO-FP16-LABEL: name: fp16 + ; NO-FP16: [[C:%[0-9]+]]:_(s32) = G_FCONSTANT float 0.000000e+00 + ; NO-FP16: %cst:_(s16) = G_FPTRUNC [[C]](s32) + ; NO-FP16: $h0 = COPY %cst(s16) + ; NO-FP16: RET_ReallyLR implicit $h0 + ; FP16-LABEL: name: fp16 + ; FP16: %cst:_(s16) = G_FCONSTANT half 0xH0000 + ; FP16: $h0 = COPY %cst(s16) + ; FP16: RET_ReallyLR implicit $h0 + %cst:_(s16) = G_FCONSTANT half 0.0 + $h0 = COPY %cst + RET_ReallyLR implicit $h0 + diff --git a/llvm/test/CodeGen/AArch64/GlobalISel/legalizer-info-validation.mir b/llvm/test/CodeGen/AArch64/GlobalISel/legalizer-info-validation.mir --- a/llvm/test/CodeGen/AArch64/GlobalISel/legalizer-info-validation.mir +++ b/llvm/test/CodeGen/AArch64/GlobalISel/legalizer-info-validation.mir @@ -247,8 +247,8 @@ # DEBUG-NEXT: .. the first uncovered type index: 1, OK # DEBUG-NEXT: .. the first uncovered imm index: 0, OK # DEBUG-NEXT: G_FCONSTANT (opcode {{[0-9]+}}): 1 type index, 0 imm indices -# DEBUG-NEXT: .. the first uncovered type index: 1, OK -# DEBUG-NEXT: .. the first uncovered imm index: 0, OK +# DEBUG-NEXT: .. type index coverage check SKIPPED: user-defined predicate detected +# DEBUG-NEXT: .. imm index coverage check SKIPPED: user-defined predicate detected # DEBUG-NEXT: G_VASTART (opcode {{[0-9]+}}): 1 type index, 0 imm indices # DEBUG-NEXT: .. the first uncovered type index: 1, OK # DEBUG-NEXT: .. the first uncovered imm index: 0, OK diff --git a/llvm/test/CodeGen/AArch64/GlobalISel/select-fp16-fconstant.mir b/llvm/test/CodeGen/AArch64/GlobalISel/select-fp16-fconstant.mir new file mode 100644 --- /dev/null +++ b/llvm/test/CodeGen/AArch64/GlobalISel/select-fp16-fconstant.mir @@ -0,0 +1,17 @@ +# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py +# RUN: llc -mtriple=aarch64-unknown-unknown -mattr=+fullfp16 -run-pass=instruction-select -verify-machineinstrs %s -o - | FileCheck %s + +--- +name: positive_zero +legalized: true +regBankSelected: true +tracksRegLiveness: true +body: | + bb.0: + ; CHECK-LABEL: name: positive_zero + ; CHECK: [[FMOVH0_:%[0-9]+]]:fpr16 = FMOVH0 + ; CHECK: $h0 = COPY [[FMOVH0_]] + ; CHECK: RET_ReallyLR implicit $h0 + %0:fpr(s16) = G_FCONSTANT half 0.0 + $h0 = COPY %0(s16) + RET_ReallyLR implicit $h0