Skip to content

Commit 08defcb

Browse files
authored
DAG: Fix asserting in error case for powi softening (#147237)
1 parent 074ccde commit 08defcb

File tree

3 files changed

+33
-8
lines changed

3 files changed

+33
-8
lines changed

llvm/lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -715,31 +715,32 @@ SDValue DAGTypeLegalizer::SoftenFloatRes_FPOW(SDNode *N) {
715715
SDValue DAGTypeLegalizer::SoftenFloatRes_ExpOp(SDNode *N) {
716716
bool IsStrict = N->isStrictFPOpcode();
717717
unsigned Offset = IsStrict ? 1 : 0;
718-
assert((N->getOperand(1 + Offset).getValueType() == MVT::i16 ||
719-
N->getOperand(1 + Offset).getValueType() == MVT::i32) &&
720-
"Unsupported power type!");
721718
bool IsPowI =
722719
N->getOpcode() == ISD::FPOWI || N->getOpcode() == ISD::STRICT_FPOWI;
720+
EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), N->getValueType(0));
723721

724722
RTLIB::Libcall LC = IsPowI ? RTLIB::getPOWI(N->getValueType(0))
725723
: RTLIB::getLDEXP(N->getValueType(0));
726724
assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unexpected fpowi.");
727725
if (!TLI.getLibcallName(LC)) {
728726
// Some targets don't have a powi libcall; use pow instead.
729727
// FIXME: Implement this if some target needs it.
730-
DAG.getContext()->emitError("Don't know how to soften fpowi to fpow");
731-
return DAG.getUNDEF(N->getValueType(0));
728+
DAG.getContext()->emitError("do not know how to soften fpowi to fpow");
729+
if (IsStrict)
730+
ReplaceValueWith(SDValue(N, 1), N->getOperand(0));
731+
return DAG.getPOISON(NVT);
732732
}
733733

734734
if (DAG.getLibInfo().getIntSize() !=
735735
N->getOperand(1 + Offset).getValueType().getSizeInBits()) {
736736
// If the exponent does not match with sizeof(int) a libcall to RTLIB::POWI
737737
// would use the wrong type for the argument.
738-
DAG.getContext()->emitError("POWI exponent does not match sizeof(int)");
739-
return DAG.getUNDEF(N->getValueType(0));
738+
DAG.getContext()->emitError("powi exponent does not match sizeof(int)");
739+
if (IsStrict)
740+
ReplaceValueWith(SDValue(N, 1), N->getOperand(0));
741+
return DAG.getPOISON(NVT);
740742
}
741743

742-
EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), N->getValueType(0));
743744
SDValue Ops[2] = { GetSoftenedFloat(N->getOperand(0 + Offset)),
744745
N->getOperand(1 + Offset) };
745746
SDValue Chain = IsStrict ? N->getOperand(0) : SDValue();
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
; RUN: not llc -mtriple=arm-linux-gnu -float-abi=soft -filetype=null %s 2>&1 | FileCheck %s
2+
3+
; FIXME: This should not fail but isn't implemented
4+
; CHECK: error: powi exponent does not match sizeof(int)
5+
define float @soften_powi_error(float %x, i64 %n) {
6+
%powi = call float @llvm.powi.f32.i64(float %x, i64 %n)
7+
ret float %powi
8+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
; RUN: not llc -mtriple=msp430 -filetype=null %s 2>&1 | FileCheck %s
2+
3+
; FIXME: This should not fail but isn't implemented
4+
; CHECK: error: powi exponent does not match sizeof(int)
5+
define float @soften_powi_error(float %x, i32 %n) {
6+
%powi = call float @llvm.powi.f32.i32(float %x, i32 %n)
7+
ret float %powi
8+
}
9+
10+
; CHECK: error: powi exponent does not match sizeof(int)
11+
define float @soften_powi_error_strictfp(float %x, i32 %n) strictfp {
12+
%powi = call float @llvm.experimental.constrained.powi.f32.i32(float %x, i32 %n, metadata !"round.tonearest", metadata !"fpexcept.strict")
13+
ret float %powi
14+
}
15+
16+

0 commit comments

Comments
 (0)