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

via llvm-commits llvm-commits at lists.llvm.org
Sun Jul 6 22:25:22 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-selectiondag

Author: Matt Arsenault (arsenm)

<details>
<summary>Changes</summary>



---
Full diff: https://github.com/llvm/llvm-project/pull/147236.diff


2 Files Affected:

- (modified) llvm/lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp (+6-4) 
- (added) llvm/test/CodeGen/ARM/frexp-soften-libcall-error.ll (+8) 


``````````diff
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
+}

``````````

</details>


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


More information about the llvm-commits mailing list