[llvm-branch-commits] [llvm] DAG: Remove special case ldexp libcall recognition (PR #241467)
Matt Arsenault via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Wed Nov 11 11:54:22 PST 2026
https://github.com/arsenm created https://github.com/llvm/llvm-project/pull/241467
InstCombine now turns the eligible cases into the intrinsic.
Co-authored-by: Claude Opus 5.5 <noreply at anthropic.com>
>From fbd4bd3582923c25d2aa4ff2592aee4dc6076a5a Mon Sep 17 00:00:00 2001
From: Matt Arsenault <Matthew.Arsenault at amd.com>
Date: Wed, 11 Nov 2026 11:49:39 -0800
Subject: [PATCH] DAG: Remove special case ldexp libcall recognition
InstCombine now turns the eligible cases into the intrinsic.
Co-authored-by: Claude Opus 5.5 <noreply at anthropic.com>
---
.../SelectionDAG/SelectionDAGBuilder.cpp | 6 --
llvm/test/CodeGen/AArch64/ldexp.ll | 76 +------------------
llvm/test/CodeGen/PowerPC/ldexp-libcall.ll | 12 +--
llvm/test/CodeGen/X86/ldexp-avx512.ll | 6 +-
llvm/test/CodeGen/X86/ldexp-libcall.ll | 50 +++---------
llvm/test/CodeGen/X86/ldexp-not-readonly.ll | 50 ------------
.../test/CodeGen/X86/ldexp-wrong-signature.ll | 54 -------------
.../CodeGen/X86/ldexp-wrong-signature2.ll | 49 ------------
8 files changed, 16 insertions(+), 287 deletions(-)
delete mode 100644 llvm/test/CodeGen/X86/ldexp-not-readonly.ll
delete mode 100644 llvm/test/CodeGen/X86/ldexp-wrong-signature.ll
delete mode 100644 llvm/test/CodeGen/X86/ldexp-wrong-signature2.ll
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
index 381f46f3f04b72..20e74dae9f07df 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
@@ -10064,12 +10064,6 @@ void SelectionDAGBuilder::visitCall(const CallInst &I) {
if (visitUnaryFloatCall(I, ISD::FEXP10))
return;
break;
- case LibFunc_ldexp:
- case LibFunc_ldexpf:
- case LibFunc_ldexpl:
- if (visitBinaryFloatCall(I, ISD::FLDEXP))
- return;
- break;
case LibFunc_strstr:
if (visitStrstrCall(I))
return;
diff --git a/llvm/test/CodeGen/AArch64/ldexp.ll b/llvm/test/CodeGen/AArch64/ldexp.ll
index edcdf1c4414b8a..4e2faf8bbc47a7 100644
--- a/llvm/test/CodeGen/AArch64/ldexp.ll
+++ b/llvm/test/CodeGen/AArch64/ldexp.ll
@@ -1,37 +1,11 @@
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 3
-; RUN: llc -mtriple=aarch64 -mattr=+sve < %s -o - | FileCheck -check-prefixes=SVE,SVELINUX %s
+; RUN: llc -mtriple=aarch64 -mattr=+sve < %s -o - | FileCheck -check-prefixes=SVE %s
; RUN: llc -mtriple=aarch64 -global-isel -global-isel-abort=2 < %s -o - 2>&1 | FileCheck -check-prefixes=GISEL %s
-; RUN: llc -mtriple=aarch64-windows-msvc -mattr=+sve < %s -o - | FileCheck -check-prefixes=SVE,SVEWINDOWS %s
+; RUN: llc -mtriple=aarch64-windows-msvc -mattr=+sve < %s -o - | FileCheck -check-prefixes=SVE %s
; RUN: llc -mtriple=aarch64-windows-msvc < %s -o - | FileCheck -check-prefixes=WINDOWS %s
; GISEL: warning: Instruction selection used fallback path for testExpIntrinsic_i16
-define double @testExp(double %val, i32 %a) {
-; SVE-LABEL: testExp:
-; SVE: // %bb.0: // %entry
-; SVE-NEXT: // kill: def $w0 killed $w0 def $x0
-; SVE-NEXT: sxtw x8, w0
-; SVE-NEXT: ptrue p0.d
-; SVE-NEXT: // kill: def $d0 killed $d0 def $z0
-; SVE-NEXT: fmov d1, x8
-; SVE-NEXT: fscale z0.d, p0/m, z0.d, z1.d
-; SVE-NEXT: // kill: def $d0 killed $d0 killed $z0
-; SVE-NEXT: ret
-;
-; GISEL-LABEL: testExp:
-; GISEL: // %bb.0: // %entry
-; GISEL-NEXT: b ldexp
-;
-; WINDOWS-LABEL: testExp:
-; WINDOWS: // %bb.0: // %entry
-; WINDOWS-NEXT: b ldexp
-entry:
- %call = tail call fast double @ldexp(double %val, i32 %a)
- ret double %call
-}
-
-declare double @ldexp(double, i32) memory(none)
-
define double @testExpIntrinsic(double %val, i32 %a) {
; SVE-LABEL: testExpIntrinsic:
; SVE: // %bb.0: // %entry
@@ -87,32 +61,6 @@ entry:
ret double %call
}
-define float @testExpf(float %val, i32 %a) {
-; SVELINUX-LABEL: testExpf:
-; SVELINUX: // %bb.0: // %entry
-; SVELINUX-NEXT: fmov s1, w0
-; SVELINUX-NEXT: ptrue p0.s
-; SVELINUX-NEXT: // kill: def $s0 killed $s0 def $z0
-; SVELINUX-NEXT: fscale z0.s, p0/m, z0.s, z1.s
-; SVELINUX-NEXT: // kill: def $s0 killed $s0 killed $z0
-; SVELINUX-NEXT: ret
-;
-; GISEL-LABEL: testExpf:
-; GISEL: // %bb.0: // %entry
-; GISEL-NEXT: b ldexpf
-;
-; SVEWINDOWS-LABEL: testExpf:
-; SVEWINDOWS: // %bb.0: // %entry
-; SVEWINDOWS-NEXT: b ldexpf
-;
-; WINDOWS-LABEL: testExpf:
-; WINDOWS: // %bb.0: // %entry
-; WINDOWS-NEXT: b ldexpf
-entry:
- %call = tail call fast float @ldexpf(float %val, i32 %a)
- ret float %call
-}
-
define float @testExpfIntrinsic(float %val, i32 %a) {
; SVE-LABEL: testExpfIntrinsic:
; SVE: // %bb.0: // %entry
@@ -233,26 +181,6 @@ define <2 x float> @test_ldexp_v2f32_v2i32(<2 x float> %Val, <2 x i32> %Exp) {
ret <2 x float> %result
}
-declare float @ldexpf(float, i32) memory(none)
-
-define fp128 @testExpl(fp128 %val, i32 %a) {
-; SVE-LABEL: testExpl:
-; SVE: // %bb.0: // %entry
-; SVE-NEXT: b ldexpl
-;
-; GISEL-LABEL: testExpl:
-; GISEL: // %bb.0: // %entry
-; GISEL-NEXT: b ldexpl
-;
-; WINDOWS-LABEL: testExpl:
-; WINDOWS: // %bb.0: // %entry
-; WINDOWS-NEXT: b ldexpl
-entry:
- %call = tail call fast fp128 @ldexpl(fp128 %val, i32 %a)
- ret fp128 %call
-}
-
-declare fp128 @ldexpl(fp128, i32) memory(none)
define half @testExpf16(half %val, i32 %a) {
; SVE-LABEL: testExpf16:
diff --git a/llvm/test/CodeGen/PowerPC/ldexp-libcall.ll b/llvm/test/CodeGen/PowerPC/ldexp-libcall.ll
index 680c99bd1e98de..ae425dfe42e0c1 100644
--- a/llvm/test/CodeGen/PowerPC/ldexp-libcall.ll
+++ b/llvm/test/CodeGen/PowerPC/ldexp-libcall.ll
@@ -15,7 +15,7 @@ define float @call_ldexpf(float %a, i32 %b) nounwind {
; CHECK-NEXT: ld r0, 16(r1)
; CHECK-NEXT: mtlr r0
; CHECK-NEXT: blr
- %result = call float @ldexpf(float %a, i32 %b)
+ %result = call float @llvm.ldexp.f32.i32(float %a, i32 %b)
ret float %result
}
@@ -32,7 +32,7 @@ define double @call_ldexp(double %a, i32 %b) nounwind {
; CHECK-NEXT: ld r0, 16(r1)
; CHECK-NEXT: mtlr r0
; CHECK-NEXT: blr
- %result = call double @ldexp(double %a, i32 %b)
+ %result = call double @llvm.ldexp.f64.i32(double %a, i32 %b)
ret double %result
}
@@ -49,12 +49,6 @@ define ppc_fp128 @call_ldexpl(ppc_fp128 %a, i32 %b) nounwind {
; CHECK-NEXT: ld r0, 16(r1)
; CHECK-NEXT: mtlr r0
; CHECK-NEXT: blr
- %result = call ppc_fp128 @ldexpl(ppc_fp128 %a, i32 %b)
+ %result = call ppc_fp128 @llvm.ldexp.ppcf128.i32(ppc_fp128 %a, i32 %b)
ret ppc_fp128 %result
}
-
-declare float @ldexpf(float %a, i32 %b) #0
-declare double @ldexp(double %a, i32 %b) #0
-declare ppc_fp128 @ldexpl(ppc_fp128 %a, i32 %b) #0
-
-attributes #0 = { nounwind readonly }
diff --git a/llvm/test/CodeGen/X86/ldexp-avx512.ll b/llvm/test/CodeGen/X86/ldexp-avx512.ll
index 3abac6b5f26d98..672632fd9fb0fb 100644
--- a/llvm/test/CodeGen/X86/ldexp-avx512.ll
+++ b/llvm/test/CodeGen/X86/ldexp-avx512.ll
@@ -45,10 +45,9 @@ define float @test_float(float %x, i32 %exp) nounwind {
; CHECK-NEXT: vscalefss %xmm1, %xmm0, %xmm0
; CHECK-NEXT: retq
entry:
- %r = tail call fast float @ldexpf(float %x, i32 %exp)
+ %r = tail call fast float @llvm.ldexp.f32.i32(float %x, i32 %exp)
ret float %r
}
-declare float @ldexpf(float, i32) memory(none)
define double @test_double(double %x, i32 %exp) nounwind {
; CHECK-LABEL: test_double:
@@ -57,10 +56,9 @@ define double @test_double(double %x, i32 %exp) nounwind {
; CHECK-NEXT: vscalefsd %xmm1, %xmm0, %xmm0
; CHECK-NEXT: retq
entry:
- %r = tail call fast double @ldexp(double %x, i32 %exp)
+ %r = tail call fast double @llvm.ldexp.f64.i32(double %x, i32 %exp)
ret double %r
}
-declare double @ldexp(double, i32) memory(none)
define x86_fp80 @test_fp80(x86_fp80 %x, i32 %exp) nounwind {
; CHECK-LABEL: test_fp80:
diff --git a/llvm/test/CodeGen/X86/ldexp-libcall.ll b/llvm/test/CodeGen/X86/ldexp-libcall.ll
index 74256c801d0295..63e8ef6f3df95e 100644
--- a/llvm/test/CodeGen/X86/ldexp-libcall.ll
+++ b/llvm/test/CodeGen/X86/ldexp-libcall.ll
@@ -9,15 +9,17 @@ define float @call_ldexpf(float %a, i32 %b) nounwind {
;
; CHECK-WIN-LABEL: call_ldexpf:
; CHECK-WIN: # %bb.0:
-; CHECK-WIN-NEXT: subl $8, %esp
-; CHECK-WIN-NEXT: flds {{[0-9]+}}(%esp)
+; CHECK-WIN-NEXT: subl $16, %esp
; CHECK-WIN-NEXT: movl {{[0-9]+}}(%esp), %eax
; CHECK-WIN-NEXT: movl %eax, {{[0-9]+}}(%esp)
-; CHECK-WIN-NEXT: fstps (%esp)
-; CHECK-WIN-NEXT: calll _ldexpf
-; CHECK-WIN-NEXT: addl $8, %esp
+; CHECK-WIN-NEXT: flds {{[0-9]+}}(%esp)
+; CHECK-WIN-NEXT: fstpl (%esp)
+; CHECK-WIN-NEXT: calll _ldexp
+; CHECK-WIN-NEXT: fstps {{[0-9]+}}(%esp)
+; CHECK-WIN-NEXT: flds {{[0-9]+}}(%esp)
+; CHECK-WIN-NEXT: addl $16, %esp
; CHECK-WIN-NEXT: retl
- %result = call float @ldexpf(float %a, i32 %b)
+ %result = call float @llvm.ldexp.f32.i32(float %a, i32 %b)
ret float %result
}
@@ -36,40 +38,6 @@ define double @call_ldexp(double %a, i32 %b) nounwind {
; CHECK-WIN-NEXT: calll _ldexp
; CHECK-WIN-NEXT: addl $12, %esp
; CHECK-WIN-NEXT: retl
- %result = call double @ldexp(double %a, i32 %b)
+ %result = call double @llvm.ldexp.f64.i32(double %a, i32 %b)
ret double %result
}
-
-define x86_fp80 @call_ldexpl(x86_fp80 %a, i32 %b) nounwind {
-; CHECK-LABEL: call_ldexpl:
-; CHECK: # %bb.0:
-; CHECK-NEXT: subq $24, %rsp
-; CHECK-NEXT: fldt {{[0-9]+}}(%rsp)
-; CHECK-NEXT: fstpt (%rsp)
-; CHECK-NEXT: callq ldexpl at PLT
-; CHECK-NEXT: addq $24, %rsp
-; CHECK-NEXT: retq
-;
-; CHECK-WIN-LABEL: call_ldexpl:
-; CHECK-WIN: # %bb.0:
-; CHECK-WIN-NEXT: pushl %ebp
-; CHECK-WIN-NEXT: movl %esp, %ebp
-; CHECK-WIN-NEXT: andl $-16, %esp
-; CHECK-WIN-NEXT: subl $48, %esp
-; CHECK-WIN-NEXT: fldt 8(%ebp)
-; CHECK-WIN-NEXT: movl 24(%ebp), %eax
-; CHECK-WIN-NEXT: movl %eax, {{[0-9]+}}(%esp)
-; CHECK-WIN-NEXT: fstpt (%esp)
-; CHECK-WIN-NEXT: calll _ldexpl
-; CHECK-WIN-NEXT: movl %ebp, %esp
-; CHECK-WIN-NEXT: popl %ebp
-; CHECK-WIN-NEXT: retl
- %result = call x86_fp80 @ldexpl(x86_fp80 %a, i32 %b)
- ret x86_fp80 %result
-}
-
-declare float @ldexpf(float %a, i32 %b) #0
-declare double @ldexp(double %a, i32 %b) #0
-declare x86_fp80 @ldexpl(x86_fp80 %a, i32 %b) #0
-
-attributes #0 = { nounwind readonly }
diff --git a/llvm/test/CodeGen/X86/ldexp-not-readonly.ll b/llvm/test/CodeGen/X86/ldexp-not-readonly.ll
deleted file mode 100644
index 9a67cf8b317144..00000000000000
--- a/llvm/test/CodeGen/X86/ldexp-not-readonly.ll
+++ /dev/null
@@ -1,50 +0,0 @@
-; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 2
-; RUN: llc < %s -mtriple=x86_64-unknown-unknown | FileCheck %s
-; RUN: llc < %s -mtriple=i386-pc-win32 | FileCheck %s -check-prefix=CHECK-WIN
-
-define float @call_ldexpf(float %a, i32 %b) nounwind {
-; CHECK-LABEL: call_ldexpf:
-; CHECK: # %bb.0:
-; CHECK-NEXT: pushq %rax
-; CHECK-NEXT: callq ldexpf at PLT
-; CHECK-NEXT: popq %rax
-; CHECK-NEXT: retq
-;
-; CHECK-WIN-LABEL: call_ldexpf:
-; CHECK-WIN: # %bb.0:
-; CHECK-WIN-NEXT: subl $8, %esp
-; CHECK-WIN-NEXT: flds {{[0-9]+}}(%esp)
-; CHECK-WIN-NEXT: movl {{[0-9]+}}(%esp), %eax
-; CHECK-WIN-NEXT: movl %eax, {{[0-9]+}}(%esp)
-; CHECK-WIN-NEXT: fstps (%esp)
-; CHECK-WIN-NEXT: calll _ldexpf
-; CHECK-WIN-NEXT: addl $8, %esp
-; CHECK-WIN-NEXT: retl
- %result = call float @ldexpf(float %a, i32 %b)
- ret float %result
-}
-
-define double @call_ldexp(double %a, i32 %b) nounwind {
-; CHECK-LABEL: call_ldexp:
-; CHECK: # %bb.0:
-; CHECK-NEXT: pushq %rax
-; CHECK-NEXT: callq ldexp at PLT
-; CHECK-NEXT: popq %rax
-; CHECK-NEXT: retq
-;
-; CHECK-WIN-LABEL: call_ldexp:
-; CHECK-WIN: # %bb.0:
-; CHECK-WIN-NEXT: subl $12, %esp
-; CHECK-WIN-NEXT: fldl {{[0-9]+}}(%esp)
-; CHECK-WIN-NEXT: movl {{[0-9]+}}(%esp), %eax
-; CHECK-WIN-NEXT: movl %eax, {{[0-9]+}}(%esp)
-; CHECK-WIN-NEXT: fstpl (%esp)
-; CHECK-WIN-NEXT: calll _ldexp
-; CHECK-WIN-NEXT: addl $12, %esp
-; CHECK-WIN-NEXT: retl
- %result = call double @ldexp(double %a, i32 %b)
- ret double %result
-}
-
-declare float @ldexpf(float %a, i32 %b)
-declare double @ldexp(double %a, i32 %b)
diff --git a/llvm/test/CodeGen/X86/ldexp-wrong-signature.ll b/llvm/test/CodeGen/X86/ldexp-wrong-signature.ll
deleted file mode 100644
index b4ba53f80ad5bd..00000000000000
--- a/llvm/test/CodeGen/X86/ldexp-wrong-signature.ll
+++ /dev/null
@@ -1,54 +0,0 @@
-; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 2
-; RUN: llc < %s -mtriple=x86_64-unknown-unknown | FileCheck %s
-; RUN: llc < %s -mtriple=i386-pc-win32 | FileCheck %s -check-prefix=CHECK-WIN
-
-define float @ldexpf_too_many_args(float %a, i32 %b, i32 %c) nounwind {
-; CHECK-LABEL: ldexpf_too_many_args:
-; CHECK: # %bb.0:
-; CHECK-NEXT: pushq %rax
-; CHECK-NEXT: callq ldexpf at PLT
-; CHECK-NEXT: popq %rax
-; CHECK-NEXT: retq
-;
-; CHECK-WIN-LABEL: ldexpf_too_many_args:
-; CHECK-WIN: # %bb.0:
-; CHECK-WIN-NEXT: subl $12, %esp
-; CHECK-WIN-NEXT: flds {{[0-9]+}}(%esp)
-; CHECK-WIN-NEXT: movl {{[0-9]+}}(%esp), %eax
-; CHECK-WIN-NEXT: movl {{[0-9]+}}(%esp), %ecx
-; CHECK-WIN-NEXT: movl %ecx, {{[0-9]+}}(%esp)
-; CHECK-WIN-NEXT: movl %eax, {{[0-9]+}}(%esp)
-; CHECK-WIN-NEXT: fstps (%esp)
-; CHECK-WIN-NEXT: calll _ldexpf
-; CHECK-WIN-NEXT: addl $12, %esp
-; CHECK-WIN-NEXT: retl
- %result = call float @ldexpf(float %a, i32 %b, i32 %c) #0
- ret float %result
-}
-
-define float @ldexp_wrong_fp_type(float %a, i32 %b) nounwind {
-; CHECK-LABEL: ldexp_wrong_fp_type:
-; CHECK: # %bb.0:
-; CHECK-NEXT: pushq %rax
-; CHECK-NEXT: callq ldexp at PLT
-; CHECK-NEXT: popq %rax
-; CHECK-NEXT: retq
-;
-; CHECK-WIN-LABEL: ldexp_wrong_fp_type:
-; CHECK-WIN: # %bb.0:
-; CHECK-WIN-NEXT: subl $8, %esp
-; CHECK-WIN-NEXT: flds {{[0-9]+}}(%esp)
-; CHECK-WIN-NEXT: movl {{[0-9]+}}(%esp), %eax
-; CHECK-WIN-NEXT: movl %eax, {{[0-9]+}}(%esp)
-; CHECK-WIN-NEXT: fstps (%esp)
-; CHECK-WIN-NEXT: calll _ldexp
-; CHECK-WIN-NEXT: addl $8, %esp
-; CHECK-WIN-NEXT: retl
- %result = call float @ldexp(float %a, i32 %b) #0
- ret float %result
-}
-
-declare float @ldexpf(float, i32, i32) #0
-declare float @ldexp(float, i32) #0
-
-attributes #0 = { nounwind readnone }
diff --git a/llvm/test/CodeGen/X86/ldexp-wrong-signature2.ll b/llvm/test/CodeGen/X86/ldexp-wrong-signature2.ll
deleted file mode 100644
index d48c1c2e0a9a7d..00000000000000
--- a/llvm/test/CodeGen/X86/ldexp-wrong-signature2.ll
+++ /dev/null
@@ -1,49 +0,0 @@
-; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 2
-; RUN: llc < %s -mtriple=x86_64-unknown-unknown | FileCheck %s
-; RUN: llc < %s -mtriple=i386-pc-win32 | FileCheck %s -check-prefix=CHECK-WIN
-
-define i32 @ldexpf_not_fp(i32 %a, i32 %b) nounwind {
-; CHECK-LABEL: ldexpf_not_fp:
-; CHECK: # %bb.0:
-; CHECK-NEXT: pushq %rax
-; CHECK-NEXT: callq ldexpf at PLT
-; CHECK-NEXT: popq %rcx
-; CHECK-NEXT: retq
-;
-; CHECK-WIN-LABEL: ldexpf_not_fp:
-; CHECK-WIN: # %bb.0:
-; CHECK-WIN-NEXT: pushl {{[0-9]+}}(%esp)
-; CHECK-WIN-NEXT: pushl {{[0-9]+}}(%esp)
-; CHECK-WIN-NEXT: calll _ldexpf
-; CHECK-WIN-NEXT: addl $8, %esp
-; CHECK-WIN-NEXT: retl
- %result = call i32 @ldexpf(i32 %a, i32 %b) #0
- ret i32 %result
-}
-
-define float @ldexp_not_int(float %a, float %b) nounwind {
-; CHECK-LABEL: ldexp_not_int:
-; CHECK: # %bb.0:
-; CHECK-NEXT: pushq %rax
-; CHECK-NEXT: callq ldexp at PLT
-; CHECK-NEXT: popq %rax
-; CHECK-NEXT: retq
-;
-; CHECK-WIN-LABEL: ldexp_not_int:
-; CHECK-WIN: # %bb.0:
-; CHECK-WIN-NEXT: subl $8, %esp
-; CHECK-WIN-NEXT: flds {{[0-9]+}}(%esp)
-; CHECK-WIN-NEXT: flds {{[0-9]+}}(%esp)
-; CHECK-WIN-NEXT: fstps {{[0-9]+}}(%esp)
-; CHECK-WIN-NEXT: fstps (%esp)
-; CHECK-WIN-NEXT: calll _ldexp
-; CHECK-WIN-NEXT: addl $8, %esp
-; CHECK-WIN-NEXT: retl
- %result = call float @ldexp(float %a, float %b) #0
- ret float %result
-}
-
-declare i32 @ldexpf(i32, i32) #0
-declare float @ldexp(float, float) #0
-
-attributes #0 = { nounwind readnone }
More information about the llvm-branch-commits
mailing list