[llvm] DAG: Fix asserting in error case for frexp softening (PR #147236)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 7 02:33:26 PDT 2025


https://github.com/arsenm updated https://github.com/llvm/llvm-project/pull/147236

>From ccca23765eef966a1f230c49d696b5e22f093f38 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 1/2] 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 d96e9a367aab7..90c9f13f5b315 100644
--- a/llvm/lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp
@@ -761,20 +761,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
+}

>From 6c10b712a2c5aad9a35cee9318517fbb7daf6fbd Mon Sep 17 00:00:00 2001
From: Matt Arsenault <Matthew.Arsenault at amd.com>
Date: Mon, 7 Jul 2025 18:28:03 +0900
Subject: [PATCH 2/2] Remove unused variable

---
 llvm/lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp | 1 -
 1 file changed, 1 deletion(-)

diff --git a/llvm/lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp b/llvm/lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp
index 90c9f13f5b315..6a4f983077213 100644
--- a/llvm/lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp
@@ -762,7 +762,6 @@ SDValue DAGTypeLegalizer::SoftenFloatRes_FFREXP(SDNode *N) {
   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()) {



More information about the llvm-commits mailing list