[llvm] DAG: Fix asserting in error case for frexp softening (PR #147236)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Sun Jul 6 22:24:47 PDT 2025
https://github.com/arsenm created https://github.com/llvm/llvm-project/pull/147236
None
>From e5892caf8ae5aa13116c4808fd2b527169c398c4 Mon Sep 17 00:00:00 2001
From: Matt Arsenault <Matthew.Arsenault at amd.com>
Date: Mon, 7 Jul 2025 14:23:28 +0900
Subject: [PATCH] DAG: Fix asserting in error case for frexp softening
---
llvm/lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp | 10 ++++++----
llvm/test/CodeGen/ARM/frexp-soften-libcall-error.ll | 8 ++++++++
2 files changed, 14 insertions(+), 4 deletions(-)
create mode 100644 llvm/test/CodeGen/ARM/frexp-soften-libcall-error.ll
diff --git a/llvm/lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp b/llvm/lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp
index 7dfb43164be37..45dbdc5b7fa7f 100644
--- a/llvm/lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp
@@ -760,20 +760,22 @@ SDValue DAGTypeLegalizer::SoftenFloatRes_FFREXP(SDNode *N) {
EVT VT0 = N->getValueType(0);
EVT VT1 = N->getValueType(1);
RTLIB::Libcall LC = RTLIB::getFREXP(VT0);
+ EVT NVT0 = TLI.getTypeToTransformTo(*DAG.getContext(), VT0);
+ EVT NVT1 = TLI.getTypeToTransformTo(*DAG.getContext(), VT1);
+ SDLoc DL(N);
if (DAG.getLibInfo().getIntSize() != VT1.getSizeInBits()) {
// If the exponent does not match with sizeof(int) a libcall would use the
// wrong type for the argument.
// TODO: Should be able to handle mismatches.
DAG.getContext()->emitError("ffrexp exponent does not match sizeof(int)");
- return DAG.getUNDEF(N->getValueType(0));
+ SDValue PoisonExp = DAG.getPOISON(VT1);
+ ReplaceValueWith(SDValue(N, 1), PoisonExp);
+ return DAG.getMergeValues({DAG.getPOISON(NVT0), PoisonExp}, DL);
}
- EVT NVT0 = TLI.getTypeToTransformTo(*DAG.getContext(), VT0);
SDValue StackSlot = DAG.CreateStackTemporary(VT1);
- SDLoc DL(N);
-
auto PointerTy = PointerType::getUnqual(*DAG.getContext());
TargetLowering::MakeLibCallOptions CallOptions;
SDValue Ops[2] = {GetSoftenedFloat(N->getOperand(0)), StackSlot};
diff --git a/llvm/test/CodeGen/ARM/frexp-soften-libcall-error.ll b/llvm/test/CodeGen/ARM/frexp-soften-libcall-error.ll
new file mode 100644
index 0000000000000..7a02dbd9d0d11
--- /dev/null
+++ b/llvm/test/CodeGen/ARM/frexp-soften-libcall-error.ll
@@ -0,0 +1,8 @@
+; RUN: not llc -mtriple arm-linux-gnu -float-abi=soft -filetype=null %s 2>&1 | FileCheck %s
+
+; FIXME: This should not fail but isn't implemented
+; CHECK: error: ffrexp exponent does not match sizeof(int)
+define { float, i64 } @soften_frexp_error(float %x) {
+ %frexp = call { float, i64 } @llvm.frexp.f32.i64(float %x)
+ ret { float, i64 } %frexp
+}
More information about the llvm-commits
mailing list