Skip to content

Commit 4b9c2cf

Browse files
committed
[DAG] Move INT<->FP constant folds from getNode to FoldConstantArithmetic
1 parent be4adb5 commit 4b9c2cf

File tree

1 file changed

+19
-20
lines changed

1 file changed

+19
-20
lines changed

llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5519,15 +5519,6 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
55195519
if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N1)) {
55205520
const APInt &Val = C->getAPIntValue();
55215521
switch (Opcode) {
5522-
case ISD::UINT_TO_FP:
5523-
case ISD::SINT_TO_FP: {
5524-
APFloat apf(EVTToAPFloatSemantics(VT),
5525-
APInt::getZero(VT.getSizeInBits()));
5526-
(void)apf.convertFromAPInt(Val,
5527-
Opcode==ISD::SINT_TO_FP,
5528-
APFloat::rmNearestTiesToEven);
5529-
return getConstantFP(apf, DL, VT);
5530-
}
55315522
case ISD::BITCAST:
55325523
if (VT == MVT::f16 && C->getValueType(0) == MVT::i16)
55335524
return getConstantFP(APFloat(APFloat::IEEEhalf(), Val), DL, VT);
@@ -5563,17 +5554,6 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
55635554
if (ConstantFPSDNode *C = dyn_cast<ConstantFPSDNode>(N1)) {
55645555
APFloat V = C->getValueAPF(); // make copy
55655556
switch (Opcode) {
5566-
case ISD::FP_TO_SINT:
5567-
case ISD::FP_TO_UINT: {
5568-
bool ignored;
5569-
APSInt IntVal(VT.getSizeInBits(), Opcode == ISD::FP_TO_UINT);
5570-
// FIXME need to be more flexible about rounding mode.
5571-
APFloat::opStatus s =
5572-
V.convertToInteger(IntVal, APFloat::rmTowardZero, &ignored);
5573-
if (s == APFloat::opInvalidOp) // inexact is OK, in fact usual
5574-
break;
5575-
return getConstant(IntVal, DL, VT);
5576-
}
55775557
case ISD::BITCAST:
55785558
if (VT == MVT::i16 && C->getValueType(0) == MVT::f16)
55795559
return getConstant((uint16_t)V.bitcastToAPInt().getZExtValue(), DL, VT);
@@ -6121,6 +6101,14 @@ SDValue SelectionDAG::FoldConstantArithmetic(unsigned Opcode, const SDLoc &DL,
61216101
case ISD::CTTZ_ZERO_UNDEF:
61226102
return getConstant(Val.countr_zero(), DL, VT, C->isTargetOpcode(),
61236103
C->isOpaque());
6104+
case ISD::UINT_TO_FP:
6105+
case ISD::SINT_TO_FP: {
6106+
APFloat apf(EVTToAPFloatSemantics(VT),
6107+
APInt::getZero(VT.getSizeInBits()));
6108+
(void)apf.convertFromAPInt(Val, Opcode == ISD::SINT_TO_FP,
6109+
APFloat::rmNearestTiesToEven);
6110+
return getConstantFP(apf, DL, VT);
6111+
}
61246112
}
61256113
}
61266114

@@ -6160,6 +6148,17 @@ SDValue SelectionDAG::FoldConstantArithmetic(unsigned Opcode, const SDLoc &DL,
61606148
&ignored);
61616149
return getConstantFP(V, DL, VT);
61626150
}
6151+
case ISD::FP_TO_SINT:
6152+
case ISD::FP_TO_UINT: {
6153+
bool ignored;
6154+
APSInt IntVal(VT.getSizeInBits(), Opcode == ISD::FP_TO_UINT);
6155+
// FIXME need to be more flexible about rounding mode.
6156+
APFloat::opStatus s =
6157+
V.convertToInteger(IntVal, APFloat::rmTowardZero, &ignored);
6158+
if (s == APFloat::opInvalidOp) // inexact is OK, in fact usual
6159+
break;
6160+
return getConstant(IntVal, DL, VT);
6161+
}
61636162
}
61646163
}
61656164
}

0 commit comments

Comments
 (0)