[llvm] DAG: Add RTLIB::getPOW helper (PR #147274)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 7 05:02:06 PDT 2025
https://github.com/arsenm updated https://github.com/llvm/llvm-project/pull/147274
>From d411fcc122eb42f854c825a3a97cfa81676683b2 Mon Sep 17 00:00:00 2001
From: Matt Arsenault <Matthew.Arsenault at amd.com>
Date: Mon, 7 Jul 2025 19:33:35 +0900
Subject: [PATCH 1/2] DAG: Add RTLIB::getPOW helper
---
llvm/include/llvm/CodeGen/RuntimeLibcallUtil.h | 4 ++++
llvm/lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp | 10 ++++------
llvm/lib/CodeGen/TargetLoweringBase.cpp | 4 ++++
3 files changed, 12 insertions(+), 6 deletions(-)
diff --git a/llvm/include/llvm/CodeGen/RuntimeLibcallUtil.h b/llvm/include/llvm/CodeGen/RuntimeLibcallUtil.h
index 7481ed5b80b3f..451459eda25e9 100644
--- a/llvm/include/llvm/CodeGen/RuntimeLibcallUtil.h
+++ b/llvm/include/llvm/CodeGen/RuntimeLibcallUtil.h
@@ -56,6 +56,10 @@ LLVM_ABI Libcall getUINTTOFP(EVT OpVT, EVT RetVT);
/// UNKNOWN_LIBCALL if there is none.
LLVM_ABI Libcall getPOWI(EVT RetVT);
+/// getPOW - Return the POW_* value for the given types, or
+/// UNKNOWN_LIBCALL if there is none.
+LLVM_ABI Libcall getPOW(EVT RetVT);
+
/// getLDEXP - Return the LDEXP_* value for the given types, or
/// UNKNOWN_LIBCALL if there is none.
LLVM_ABI Libcall getLDEXP(EVT RetVT);
diff --git a/llvm/lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp b/llvm/lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp
index 6a4f983077213..9d9fdeeb8740c 100644
--- a/llvm/lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp
@@ -704,12 +704,7 @@ SDValue DAGTypeLegalizer::SoftenFloatRes_FP_ROUND(SDNode *N) {
}
SDValue DAGTypeLegalizer::SoftenFloatRes_FPOW(SDNode *N) {
- return SoftenFloatRes_Binary(N, GetFPLibCall(N->getValueType(0),
- RTLIB::POW_F32,
- RTLIB::POW_F64,
- RTLIB::POW_F80,
- RTLIB::POW_F128,
- RTLIB::POW_PPCF128));
+ return SoftenFloatRes_Binary(N, RTLIB::getPOW(N->getValueType(0)));
}
SDValue DAGTypeLegalizer::SoftenFloatRes_ExpOp(SDNode *N) {
@@ -723,6 +718,9 @@ SDValue DAGTypeLegalizer::SoftenFloatRes_ExpOp(SDNode *N) {
: RTLIB::getLDEXP(N->getValueType(0));
assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unexpected fpowi.");
if (!TLI.getLibcallName(LC)) {
+ RTLIB::Libcall NewLC = RTLIB::getPOW(N->getValueType(0));
+ assert(NewLC != RTLIB::UNKNOWN_LIBCALL);
+
// Some targets don't have a powi libcall; use pow instead.
// FIXME: Implement this if some target needs it.
DAG.getContext()->emitError("do not know how to soften fpowi to fpow");
diff --git a/llvm/lib/CodeGen/TargetLoweringBase.cpp b/llvm/lib/CodeGen/TargetLoweringBase.cpp
index 65bbec8461a12..4f722005f4056 100644
--- a/llvm/lib/CodeGen/TargetLoweringBase.cpp
+++ b/llvm/lib/CodeGen/TargetLoweringBase.cpp
@@ -396,6 +396,10 @@ RTLIB::Libcall RTLIB::getPOWI(EVT RetVT) {
POWI_PPCF128);
}
+RTLIB::Libcall RTLIB::getPOW(EVT RetVT) {
+ return getFPLibCall(RetVT, POW_F32, POW_F64, POW_F80, POW_F128, POW_PPCF128);
+}
+
RTLIB::Libcall RTLIB::getLDEXP(EVT RetVT) {
return getFPLibCall(RetVT, LDEXP_F32, LDEXP_F64, LDEXP_F80, LDEXP_F128,
LDEXP_PPCF128);
>From 1c0ddb9d78ccc4c3c5345e8c39651993260752c8 Mon Sep 17 00:00:00 2001
From: Matt Arsenault <Matthew.Arsenault at amd.com>
Date: Mon, 7 Jul 2025 21:01:59 +0900
Subject: [PATCH 2/2] Update
llvm/lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp
Co-authored-by: Paul Walker <paul.walker at arm.com>
---
llvm/lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp b/llvm/lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp
index 9d9fdeeb8740c..2a947f3297749 100644
--- a/llvm/lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp
@@ -719,7 +719,7 @@ SDValue DAGTypeLegalizer::SoftenFloatRes_ExpOp(SDNode *N) {
assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unexpected fpowi.");
if (!TLI.getLibcallName(LC)) {
RTLIB::Libcall NewLC = RTLIB::getPOW(N->getValueType(0));
- assert(NewLC != RTLIB::UNKNOWN_LIBCALL);
+ assert(NewLC != RTLIB::UNKNOWN_LIBCALL && "Unexpected fpow type");
// Some targets don't have a powi libcall; use pow instead.
// FIXME: Implement this if some target needs it.
More information about the llvm-commits
mailing list