[llvm] 08defcb - DAG: Fix asserting in error case for powi softening (#147237)

via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 7 02:13:14 PDT 2025


Author: Matt Arsenault
Date: 2025-07-07T18:13:11+09:00
New Revision: 08defcb6d3cdfbf58cfc07e3b16b3c9bed63ec4a

URL: https://github.com/llvm/llvm-project/commit/08defcb6d3cdfbf58cfc07e3b16b3c9bed63ec4a
DIFF: https://github.com/llvm/llvm-project/commit/08defcb6d3cdfbf58cfc07e3b16b3c9bed63ec4a.diff

LOG: DAG: Fix asserting in error case for powi softening (#147237)

Added: 
    llvm/test/CodeGen/ARM/powi-soften-libcall-error.ll
    llvm/test/CodeGen/MSP430/powi-soften-libcall-error.ll

Modified: 
    llvm/lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp b/llvm/lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp
index 7dfb43164be37..d96e9a367aab7 100644
--- a/llvm/lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp
@@ -715,11 +715,9 @@ SDValue DAGTypeLegalizer::SoftenFloatRes_FPOW(SDNode *N) {
 SDValue DAGTypeLegalizer::SoftenFloatRes_ExpOp(SDNode *N) {
   bool IsStrict = N->isStrictFPOpcode();
   unsigned Offset = IsStrict ? 1 : 0;
-  assert((N->getOperand(1 + Offset).getValueType() == MVT::i16 ||
-          N->getOperand(1 + Offset).getValueType() == MVT::i32) &&
-         "Unsupported power type!");
   bool IsPowI =
       N->getOpcode() == ISD::FPOWI || N->getOpcode() == ISD::STRICT_FPOWI;
+  EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), N->getValueType(0));
 
   RTLIB::Libcall LC = IsPowI ? RTLIB::getPOWI(N->getValueType(0))
                              : RTLIB::getLDEXP(N->getValueType(0));
@@ -727,19 +725,22 @@ SDValue DAGTypeLegalizer::SoftenFloatRes_ExpOp(SDNode *N) {
   if (!TLI.getLibcallName(LC)) {
     // Some targets don't have a powi libcall; use pow instead.
     // FIXME: Implement this if some target needs it.
-    DAG.getContext()->emitError("Don't know how to soften fpowi to fpow");
-    return DAG.getUNDEF(N->getValueType(0));
+    DAG.getContext()->emitError("do not know how to soften fpowi to fpow");
+    if (IsStrict)
+      ReplaceValueWith(SDValue(N, 1), N->getOperand(0));
+    return DAG.getPOISON(NVT);
   }
 
   if (DAG.getLibInfo().getIntSize() !=
       N->getOperand(1 + Offset).getValueType().getSizeInBits()) {
     // If the exponent does not match with sizeof(int) a libcall to RTLIB::POWI
     // would use the wrong type for the argument.
-    DAG.getContext()->emitError("POWI exponent does not match sizeof(int)");
-    return DAG.getUNDEF(N->getValueType(0));
+    DAG.getContext()->emitError("powi exponent does not match sizeof(int)");
+    if (IsStrict)
+      ReplaceValueWith(SDValue(N, 1), N->getOperand(0));
+    return DAG.getPOISON(NVT);
   }
 
-  EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), N->getValueType(0));
   SDValue Ops[2] = { GetSoftenedFloat(N->getOperand(0 + Offset)),
                      N->getOperand(1 + Offset) };
   SDValue Chain = IsStrict ? N->getOperand(0) : SDValue();

diff  --git a/llvm/test/CodeGen/ARM/powi-soften-libcall-error.ll b/llvm/test/CodeGen/ARM/powi-soften-libcall-error.ll
new file mode 100644
index 0000000000000..1feb544d42e74
--- /dev/null
+++ b/llvm/test/CodeGen/ARM/powi-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: powi exponent does not match sizeof(int)
+define float @soften_powi_error(float %x, i64 %n) {
+  %powi = call float @llvm.powi.f32.i64(float %x, i64 %n)
+  ret float %powi
+}

diff  --git a/llvm/test/CodeGen/MSP430/powi-soften-libcall-error.ll b/llvm/test/CodeGen/MSP430/powi-soften-libcall-error.ll
new file mode 100644
index 0000000000000..b0fbdc6717612
--- /dev/null
+++ b/llvm/test/CodeGen/MSP430/powi-soften-libcall-error.ll
@@ -0,0 +1,16 @@
+; RUN: not llc -mtriple=msp430 -filetype=null %s 2>&1 | FileCheck %s
+
+; FIXME: This should not fail but isn't implemented
+; CHECK: error: powi exponent does not match sizeof(int)
+define float @soften_powi_error(float %x, i32 %n) {
+  %powi = call float @llvm.powi.f32.i32(float %x, i32 %n)
+  ret float %powi
+}
+
+; CHECK: error: powi exponent does not match sizeof(int)
+define float @soften_powi_error_strictfp(float %x, i32 %n) strictfp {
+ %powi = call float @llvm.experimental.constrained.powi.f32.i32(float %x, i32 %n, metadata !"round.tonearest", metadata !"fpexcept.strict")
+  ret float %powi
+}
+
+


        


More information about the llvm-commits mailing list