Skip to content

Commit 1d47d5d

Browse files
committed
[DAG] Move F16<->FP constant folds from getNode to FoldConstantArithmetic
1 parent faed70d commit 1d47d5d

File tree

1 file changed

+27
-23
lines changed

1 file changed

+27
-23
lines changed

llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5529,19 +5529,6 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
55295529
if (VT == MVT::f128 && C->getValueType(0) == MVT::i128)
55305530
return getConstantFP(APFloat(APFloat::IEEEquad(), Val), DL, VT);
55315531
break;
5532-
case ISD::FP16_TO_FP:
5533-
case ISD::BF16_TO_FP: {
5534-
bool Ignored;
5535-
APFloat FPV(Opcode == ISD::FP16_TO_FP ? APFloat::IEEEhalf()
5536-
: APFloat::BFloat(),
5537-
(Val.getBitWidth() == 16) ? Val : Val.trunc(16));
5538-
5539-
// This can return overflow, underflow, or inexact; we don't care.
5540-
// FIXME need to be more flexible about rounding mode.
5541-
(void)FPV.convert(EVTToAPFloatSemantics(VT),
5542-
APFloat::rmNearestTiesToEven, &Ignored);
5543-
return getConstantFP(FPV, DL, VT);
5544-
}
55455532
case ISD::STEP_VECTOR: {
55465533
if (SDValue V = FoldSTEP_VECTOR(DL, VT, N1, *this))
55475534
return V;
@@ -5564,16 +5551,6 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
55645551
if (VT == MVT::i64 && C->getValueType(0) == MVT::f64)
55655552
return getConstant(V.bitcastToAPInt().getZExtValue(), DL, VT);
55665553
break;
5567-
case ISD::FP_TO_FP16:
5568-
case ISD::FP_TO_BF16: {
5569-
bool Ignored;
5570-
// This can return overflow, underflow, or inexact; we don't care.
5571-
// FIXME need to be more flexible about rounding mode.
5572-
(void)V.convert(Opcode == ISD::FP_TO_FP16 ? APFloat::IEEEhalf()
5573-
: APFloat::BFloat(),
5574-
APFloat::rmNearestTiesToEven, &Ignored);
5575-
return getConstant(V.bitcastToAPInt().getZExtValue(), DL, VT);
5576-
}
55775554
}
55785555
}
55795556

@@ -5591,12 +5568,16 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
55915568
case ISD::FP_EXTEND:
55925569
case ISD::FP_TO_SINT:
55935570
case ISD::FP_TO_UINT:
5571+
case ISD::FP_TO_FP16:
5572+
case ISD::FP_TO_BF16:
55945573
case ISD::TRUNCATE:
55955574
case ISD::ANY_EXTEND:
55965575
case ISD::ZERO_EXTEND:
55975576
case ISD::SIGN_EXTEND:
55985577
case ISD::UINT_TO_FP:
55995578
case ISD::SINT_TO_FP:
5579+
case ISD::FP16_TO_FP:
5580+
case ISD::BF16_TO_FP:
56005581
case ISD::ABS:
56015582
case ISD::BITREVERSE:
56025583
case ISD::BSWAP:
@@ -6109,6 +6090,19 @@ SDValue SelectionDAG::FoldConstantArithmetic(unsigned Opcode, const SDLoc &DL,
61096090
APFloat::rmNearestTiesToEven);
61106091
return getConstantFP(apf, DL, VT);
61116092
}
6093+
case ISD::FP16_TO_FP:
6094+
case ISD::BF16_TO_FP: {
6095+
bool Ignored;
6096+
APFloat FPV(Opcode == ISD::FP16_TO_FP ? APFloat::IEEEhalf()
6097+
: APFloat::BFloat(),
6098+
(Val.getBitWidth() == 16) ? Val : Val.trunc(16));
6099+
6100+
// This can return overflow, underflow, or inexact; we don't care.
6101+
// FIXME need to be more flexible about rounding mode.
6102+
(void)FPV.convert(EVTToAPFloatSemantics(VT),
6103+
APFloat::rmNearestTiesToEven, &Ignored);
6104+
return getConstantFP(FPV, DL, VT);
6105+
}
61126106
}
61136107
}
61146108

@@ -6159,6 +6153,16 @@ SDValue SelectionDAG::FoldConstantArithmetic(unsigned Opcode, const SDLoc &DL,
61596153
break;
61606154
return getConstant(IntVal, DL, VT);
61616155
}
6156+
case ISD::FP_TO_FP16:
6157+
case ISD::FP_TO_BF16: {
6158+
bool Ignored;
6159+
// This can return overflow, underflow, or inexact; we don't care.
6160+
// FIXME need to be more flexible about rounding mode.
6161+
(void)V.convert(Opcode == ISD::FP_TO_FP16 ? APFloat::IEEEhalf()
6162+
: APFloat::BFloat(),
6163+
APFloat::rmNearestTiesToEven, &Ignored);
6164+
return getConstant(V.bitcastToAPInt().getZExtValue(), DL, VT);
6165+
}
61626166
}
61636167
}
61646168
}

0 commit comments

Comments
 (0)