[llvm-branch-commits] [llvm] release/18.x: [AArch64][GlobalISel] Fail legalization for unknown libcalls. (#81873) (PR #82103)
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Sat Feb 17 01:04:05 PST 2024
https://github.com/llvmbot created https://github.com/llvm/llvm-project/pull/82103
Backport 47c65cf62d06add9f55a77c9d45390fa3b986fc5
Requested by: @davemgreen
>From 8a3d8f0c2531877c84203298a979419a2ba652ee Mon Sep 17 00:00:00 2001
From: David Green <david.green at arm.com>
Date: Sat, 17 Feb 2024 08:57:14 +0000
Subject: [PATCH] [AArch64][GlobalISel] Fail legalization for unknown libcalls.
(#81873)
If, like powi on windows, the libcall is unavailable we should fall back
to SDAG. Currently we try and generate a call to "".
(cherry picked from commit 47c65cf62d06add9f55a77c9d45390fa3b986fc5)
---
.../CodeGen/GlobalISel/LegalizerHelper.cpp | 2 +
llvm/test/CodeGen/AArch64/win64-fpowi.ll | 136 ++++++++++++++++++
2 files changed, 138 insertions(+)
create mode 100644 llvm/test/CodeGen/AArch64/win64-fpowi.ll
diff --git a/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp b/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
index 3b2cf319109273..c0c22e36004f72 100644
--- a/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
@@ -596,6 +596,8 @@ llvm::createLibcall(MachineIRBuilder &MIRBuilder, RTLIB::Libcall Libcall,
LostDebugLocObserver &LocObserver, MachineInstr *MI) {
auto &TLI = *MIRBuilder.getMF().getSubtarget().getTargetLowering();
const char *Name = TLI.getLibcallName(Libcall);
+ if (!Name)
+ return LegalizerHelper::UnableToLegalize;
const CallingConv::ID CC = TLI.getLibcallCallingConv(Libcall);
return createLibcall(MIRBuilder, Name, Result, Args, CC, LocObserver, MI);
}
diff --git a/llvm/test/CodeGen/AArch64/win64-fpowi.ll b/llvm/test/CodeGen/AArch64/win64-fpowi.ll
new file mode 100644
index 00000000000000..3eb74f8394ec4e
--- /dev/null
+++ b/llvm/test/CodeGen/AArch64/win64-fpowi.ll
@@ -0,0 +1,136 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 3
+; RUN: llc -mtriple=aarch64-pc-windows-msvc19 -verify-machineinstrs %s -o - | FileCheck %s
+; RUN: llc -mtriple=aarch64-pc-windows-msvc19 -global-isel -global-isel-abort=2 -verify-machineinstrs %s -o - | FileCheck %s
+
+define double @powi_f64(double %a, i32 %b) {
+; CHECK-LABEL: powi_f64:
+; CHECK: // %bb.0: // %entry
+; CHECK-NEXT: scvtf d1, w0
+; CHECK-NEXT: b pow
+entry:
+ %c = call double @llvm.powi.f64.i32(double %a, i32 %b)
+ ret double %c
+}
+
+define float @powi_f32(float %a, i32 %b) {
+; CHECK-LABEL: powi_f32:
+; CHECK: // %bb.0: // %entry
+; CHECK-NEXT: scvtf s1, w0
+; CHECK-NEXT: b powf
+entry:
+ %c = call float @llvm.powi.f32.i32(float %a, i32 %b)
+ ret float %c
+}
+
+define half @powi_f16(half %a, i32 %b) {
+; CHECK-LABEL: powi_f16:
+; CHECK: .seh_proc powi_f16
+; CHECK-NEXT: // %bb.0: // %entry
+; CHECK-NEXT: str x30, [sp, #-16]! // 8-byte Folded Spill
+; CHECK-NEXT: .seh_save_reg_x x30, 16
+; CHECK-NEXT: .seh_endprologue
+; CHECK-NEXT: fcvt s0, h0
+; CHECK-NEXT: scvtf s1, w0
+; CHECK-NEXT: bl powf
+; CHECK-NEXT: fcvt h0, s0
+; CHECK-NEXT: .seh_startepilogue
+; CHECK-NEXT: ldr x30, [sp], #16 // 8-byte Folded Reload
+; CHECK-NEXT: .seh_save_reg_x x30, 16
+; CHECK-NEXT: .seh_endepilogue
+; CHECK-NEXT: ret
+; CHECK-NEXT: .seh_endfunclet
+; CHECK-NEXT: .seh_endproc
+entry:
+ %c = call half @llvm.powi.f16.i32(half %a, i32 %b)
+ ret half %c
+}
+
+define <2 x double> @powi_v2f64(<2 x double> %a, i32 %b) {
+; CHECK-LABEL: powi_v2f64:
+; CHECK: .seh_proc powi_v2f64
+; CHECK-NEXT: // %bb.0: // %entry
+; CHECK-NEXT: sub sp, sp, #48
+; CHECK-NEXT: .seh_stackalloc 48
+; CHECK-NEXT: str x30, [sp, #32] // 8-byte Folded Spill
+; CHECK-NEXT: .seh_save_reg x30, 32
+; CHECK-NEXT: str d8, [sp, #40] // 8-byte Folded Spill
+; CHECK-NEXT: .seh_save_freg d8, 40
+; CHECK-NEXT: .seh_endprologue
+; CHECK-NEXT: scvtf d8, w0
+; CHECK-NEXT: str q0, [sp] // 16-byte Folded Spill
+; CHECK-NEXT: mov d0, v0.d[1]
+; CHECK-NEXT: fmov d1, d8
+; CHECK-NEXT: bl pow
+; CHECK-NEXT: fmov d1, d8
+; CHECK-NEXT: // kill: def $d0 killed $d0 def $q0
+; CHECK-NEXT: str q0, [sp, #16] // 16-byte Folded Spill
+; CHECK-NEXT: ldr q0, [sp] // 16-byte Folded Reload
+; CHECK-NEXT: // kill: def $d0 killed $d0 killed $q0
+; CHECK-NEXT: bl pow
+; CHECK-NEXT: ldr q1, [sp, #16] // 16-byte Folded Reload
+; CHECK-NEXT: // kill: def $d0 killed $d0 def $q0
+; CHECK-NEXT: mov v0.d[1], v1.d[0]
+; CHECK-NEXT: .seh_startepilogue
+; CHECK-NEXT: ldr d8, [sp, #40] // 8-byte Folded Reload
+; CHECK-NEXT: .seh_save_freg d8, 40
+; CHECK-NEXT: ldr x30, [sp, #32] // 8-byte Folded Reload
+; CHECK-NEXT: .seh_save_reg x30, 32
+; CHECK-NEXT: add sp, sp, #48
+; CHECK-NEXT: .seh_stackalloc 48
+; CHECK-NEXT: .seh_endepilogue
+; CHECK-NEXT: ret
+; CHECK-NEXT: .seh_endfunclet
+; CHECK-NEXT: .seh_endproc
+entry:
+ %c = call <2 x double> @llvm.powi.v2f64.i32(<2 x double> %a, i32 %b)
+ ret <2 x double> %c
+}
+
+define <2 x float> @powi_v2f32(<2 x float> %a, i32 %b) {
+; CHECK-LABEL: powi_v2f32:
+; CHECK: .seh_proc powi_v2f32
+; CHECK-NEXT: // %bb.0: // %entry
+; CHECK-NEXT: sub sp, sp, #48
+; CHECK-NEXT: .seh_stackalloc 48
+; CHECK-NEXT: str x30, [sp, #32] // 8-byte Folded Spill
+; CHECK-NEXT: .seh_save_reg x30, 32
+; CHECK-NEXT: str d8, [sp, #40] // 8-byte Folded Spill
+; CHECK-NEXT: .seh_save_freg d8, 40
+; CHECK-NEXT: .seh_endprologue
+; CHECK-NEXT: scvtf s8, w0
+; CHECK-NEXT: // kill: def $d0 killed $d0 def $q0
+; CHECK-NEXT: str q0, [sp] // 16-byte Folded Spill
+; CHECK-NEXT: mov s0, v0.s[1]
+; CHECK-NEXT: fmov s1, s8
+; CHECK-NEXT: bl powf
+; CHECK-NEXT: fmov s1, s8
+; CHECK-NEXT: // kill: def $s0 killed $s0 def $q0
+; CHECK-NEXT: str q0, [sp, #16] // 16-byte Folded Spill
+; CHECK-NEXT: ldr q0, [sp] // 16-byte Folded Reload
+; CHECK-NEXT: // kill: def $s0 killed $s0 killed $q0
+; CHECK-NEXT: bl powf
+; CHECK-NEXT: ldr q1, [sp, #16] // 16-byte Folded Reload
+; CHECK-NEXT: // kill: def $s0 killed $s0 def $q0
+; CHECK-NEXT: mov v0.s[1], v1.s[0]
+; CHECK-NEXT: // kill: def $d0 killed $d0 killed $q0
+; CHECK-NEXT: .seh_startepilogue
+; CHECK-NEXT: ldr d8, [sp, #40] // 8-byte Folded Reload
+; CHECK-NEXT: .seh_save_freg d8, 40
+; CHECK-NEXT: ldr x30, [sp, #32] // 8-byte Folded Reload
+; CHECK-NEXT: .seh_save_reg x30, 32
+; CHECK-NEXT: add sp, sp, #48
+; CHECK-NEXT: .seh_stackalloc 48
+; CHECK-NEXT: .seh_endepilogue
+; CHECK-NEXT: ret
+; CHECK-NEXT: .seh_endfunclet
+; CHECK-NEXT: .seh_endproc
+entry:
+ %c = call <2 x float> @llvm.powi.v2f32.i32(<2 x float> %a, i32 %b)
+ ret <2 x float> %c
+}
+
+declare <2 x double> @llvm.powi.v2f64.i32(<2 x double>, i32)
+declare <2 x float> @llvm.powi.v2f32.i32(<2 x float>, i32)
+declare double @llvm.powi.f64.i32(double, i32)
+declare float @llvm.powi.f32.i32(float, i32)
+declare half @llvm.powi.f16.i32(half, i32)
More information about the llvm-branch-commits
mailing list