[llvm] [AArch64][GlobalISel] Generate libcall for s128 G_FPTRUNC (PR #96602)
Madhur Amilkanthwar via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 25 03:02:36 PDT 2024
https://github.com/madhur13490 updated https://github.com/llvm/llvm-project/pull/96602
>From 85a056e39fec9ca1afcb548e1d77968bcd9f1315 Mon Sep 17 00:00:00 2001
From: Madhur Amilkanthwar <madhura at nvidia.com>
Date: Mon, 24 Jun 2024 14:24:48 +0530
Subject: [PATCH 1/2] [AArch64][GlobalISel] Generate libcall for s128 source
type for G_FPTRUNC
This patch would generate libcall if source type is s128. It matches
DAG behaviour.
---
.../AArch64/GISel/AArch64LegalizerInfo.cpp | 1 +
.../GlobalISel/legalizer-info-validation.mir | 5 +++--
llvm/test/CodeGen/AArch64/fptrunc.ll | 18 ++++++++++++++++++
3 files changed, 22 insertions(+), 2 deletions(-)
diff --git a/llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp b/llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp
index fef0b722efe45..fab1cf066382b 100644
--- a/llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp
+++ b/llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp
@@ -646,6 +646,7 @@ AArch64LegalizerInfo::AArch64LegalizerInfo(const AArch64Subtarget &ST)
// FP conversions
getActionDefinitionsBuilder(G_FPTRUNC)
+ .libcallIf(typeIs(1, s128))
.legalFor(
{{s16, s32}, {s16, s64}, {s32, s64}, {v4s16, v4s32}, {v2s32, v2s64}})
.clampNumElements(0, v4s16, v4s16)
diff --git a/llvm/test/CodeGen/AArch64/GlobalISel/legalizer-info-validation.mir b/llvm/test/CodeGen/AArch64/GlobalISel/legalizer-info-validation.mir
index f03491924f7f4..d2e371255e1fb 100644
--- a/llvm/test/CodeGen/AArch64/GlobalISel/legalizer-info-validation.mir
+++ b/llvm/test/CodeGen/AArch64/GlobalISel/legalizer-info-validation.mir
@@ -1,3 +1,4 @@
+# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 5
# RUN: llc -mtriple=aarch64-- -run-pass=legalizer %s \
# RUN: -mcpu=cortex-a75 -o - 2>&1 | FileCheck %s --check-prefixes=CHECK
@@ -510,8 +511,8 @@
# DEBUG-NEXT: .. the first uncovered type index: 2, OK
# DEBUG-NEXT: .. the first uncovered imm index: 0, OK
# DEBUG-NEXT: G_FPTRUNC (opcode {{[0-9]+}}): 2 type indices, 0 imm indices
-# DEBUG-NEXT: .. the first uncovered type index: 2, 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_FPTOSI (opcode {{[0-9]+}}): 2 type indices, 0 imm indices
# DEBUG-NEXT: .. type index coverage check SKIPPED: user-defined predicate detected
# DEBUG-NEXT: .. imm index coverage check SKIPPED: user-defined predicate detected
diff --git a/llvm/test/CodeGen/AArch64/fptrunc.ll b/llvm/test/CodeGen/AArch64/fptrunc.ll
index 9d0672d1c95ea..d16f574c32183 100644
--- a/llvm/test/CodeGen/AArch64/fptrunc.ll
+++ b/llvm/test/CodeGen/AArch64/fptrunc.ll
@@ -32,6 +32,24 @@ entry:
ret half %c
}
+define double @fptrunc_f128_f64(fp128 %a) {
+; CHECK-SD-LABEL: fptrunc_f128_f64:
+; CHECK-SD: // %bb.0: // %entry
+; CHECK-SD-NEXT: str x30, [sp, #-16]! // 8-byte Folded Spill
+; CHECK-SD-NEXT: .cfi_def_cfa_offset 16
+; CHECK-SD-NEXT: .cfi_offset w30, -16
+; CHECK-SD-NEXT: bl __trunctfdf2
+; CHECK-SD-NEXT: ldr x30, [sp], #16 // 8-byte Folded Reload
+; CHECK-SD-NEXT: ret
+;
+; CHECK-GI-LABEL: fptrunc_f128_f64:
+; CHECK-GI: // %bb.0: // %entry
+; CHECK-GI-NEXT: b __trunctfdf2
+entry:
+ %c = fptrunc fp128 %a to double
+ ret double %c
+}
+
define <2 x float> @fptrunc_v2f64_v2f32(<2 x double> %a) {
; CHECK-LABEL: fptrunc_v2f64_v2f32:
; CHECK: // %bb.0: // %entry
>From 1119b67736f35437818ce70a4af1c40f30631d3f Mon Sep 17 00:00:00 2001
From: Madhur Amilkanthwar <madhura at nvidia.com>
Date: Tue, 25 Jun 2024 15:32:02 +0530
Subject: [PATCH 2/2] Address review comments
---
.../AArch64/GISel/AArch64LegalizerInfo.cpp | 2 +-
llvm/test/CodeGen/AArch64/fptrunc.ll | 35 +++++++++++++++++++
2 files changed, 36 insertions(+), 1 deletion(-)
diff --git a/llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp b/llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp
index fab1cf066382b..4ac12d10d08d8 100644
--- a/llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp
+++ b/llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp
@@ -646,9 +646,9 @@ AArch64LegalizerInfo::AArch64LegalizerInfo(const AArch64Subtarget &ST)
// FP conversions
getActionDefinitionsBuilder(G_FPTRUNC)
- .libcallIf(typeIs(1, s128))
.legalFor(
{{s16, s32}, {s16, s64}, {s32, s64}, {v4s16, v4s32}, {v2s32, v2s64}})
+ .libcallFor({{s16, s128}, {s32, s128}, {s64, s128}})
.clampNumElements(0, v4s16, v4s16)
.clampNumElements(0, v2s32, v2s32)
.scalarize(0);
diff --git a/llvm/test/CodeGen/AArch64/fptrunc.ll b/llvm/test/CodeGen/AArch64/fptrunc.ll
index d16f574c32183..c0347cc59e67c 100644
--- a/llvm/test/CodeGen/AArch64/fptrunc.ll
+++ b/llvm/test/CodeGen/AArch64/fptrunc.ll
@@ -50,6 +50,41 @@ entry:
ret double %c
}
+define half @fptrunc_f128_f16(fp128 %a) {
+; CHECK-SD-LABEL: fptrunc_f128_f16:
+; CHECK-SD: // %bb.0: // %entry
+; CHECK-SD-NEXT: str x30, [sp, #-16]! // 8-byte Folded Spill
+; CHECK-SD-NEXT: .cfi_def_cfa_offset 16
+; CHECK-SD-NEXT: .cfi_offset w30, -16
+; CHECK-SD-NEXT: bl __trunctfhf2
+; CHECK-SD-NEXT: ldr x30, [sp], #16 // 8-byte Folded Reload
+; CHECK-SD-NEXT: ret
+;
+; CHECK-GI-LABEL: fptrunc_f128_f16:
+; CHECK-GI: // %bb.0: // %entry
+; CHECK-GI-NEXT: b __trunctfhf2
+entry:
+ %c = fptrunc fp128 %a to half
+ ret half %c
+}
+
+define float @fptrunc_f128_f32(fp128 %a) {
+; CHECK-SD-LABEL: fptrunc_f128_f32:
+; CHECK-SD: // %bb.0: // %entry
+; CHECK-SD-NEXT: str x30, [sp, #-16]! // 8-byte Folded Spill
+; CHECK-SD-NEXT: .cfi_def_cfa_offset 16
+; CHECK-SD-NEXT: .cfi_offset w30, -16
+; CHECK-SD-NEXT: bl __trunctfsf2
+; CHECK-SD-NEXT: ldr x30, [sp], #16 // 8-byte Folded Reload
+; CHECK-SD-NEXT: ret
+;
+; CHECK-GI-LABEL: fptrunc_f128_f32:
+; CHECK-GI: // %bb.0: // %entry
+; CHECK-GI-NEXT: b __trunctfsf2
+entry:
+ %c = fptrunc fp128 %a to float
+ ret float %c
+}
define <2 x float> @fptrunc_v2f64_v2f32(<2 x double> %a) {
; CHECK-LABEL: fptrunc_v2f64_v2f32:
; CHECK: // %bb.0: // %entry
More information about the llvm-commits
mailing list