[llvm] [AArch64][GlobalISel] Legalize s16 G_FCONSTANT to avoid widening to G_CONSTANT (PR #161205)

via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 29 07:25:17 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-backend-aarch64

Author: Ryan Cowan (HolyMolyCowMan)

<details>
<summary>Changes</summary>

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.

---
Full diff: https://github.com/llvm/llvm-project/pull/161205.diff


1 Files Affected:

- (modified) llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp (+2-2) 


``````````diff
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

``````````

</details>


https://github.com/llvm/llvm-project/pull/161205


More information about the llvm-commits mailing list