[llvm] [AArch64][GlobalISel] Legalize s16 G_FCONSTANT to avoid widening to G_CONSTANT (PR #161205)
Ryan Cowan via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 29 07:24:45 PDT 2025
https://github.com/HolyMolyCowMan created https://github.com/llvm/llvm-project/pull/161205
When widening a `G_FCONSTANT` it is converted to a `G_CONSTANT` to avoid loss in accuracy (see https://github.com/llvm/llvm-project/issues/56454). This means that some folds such as `G_FPEXT(G_FCONSTANT)` fail to work when the scalar has been widened.
This PR legalizes `s16`s by default in line with how s16 `G_CONSTANT`s are treated.
>From d3ea33e1477c5b1a4e9e22aa9915f6ac4aaaeb08 Mon Sep 17 00:00:00 2001
From: Ryan Cowan <ryan.cowan at arm.com>
Date: Mon, 29 Sep 2025 14:17:11 +0000
Subject: [PATCH] [AArch64][GlobalISel] Legalize s16 G_FCONSTANT to avoid
widening to G_CONSTANT
---
llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp b/llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp
index 7ee54c5932b15..1593f32d1fc6c 100644
--- a/llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp
+++ b/llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp
@@ -678,8 +678,8 @@ AArch64LegalizerInfo::AArch64LegalizerInfo(const AArch64Subtarget &ST)
.widenScalarToNextPow2(0)
.clampScalar(0, s8, s64);
getActionDefinitionsBuilder(G_FCONSTANT)
- .legalFor({s32, s64, s128})
- .legalFor(HasFP16, {s16})
+ // Always legalize s16 to prevent G_FCONSTANT being widened to G_CONSTANT
+ .legalFor({s16, s32, s64, s128})
.clampScalar(0, MinFPScalar, s128);
// FIXME: fix moreElementsToNextPow2
More information about the llvm-commits
mailing list