[llvm] 1d47d5d - [DAG] Move F16<->FP constant folds from getNode to FoldConstantArithmetic
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 1 07:47:54 PDT 2023
Author: Simon Pilgrim
Date: 2023-09-01T15:47:36+01:00
New Revision: 1d47d5d67c053d74407e97aaf9e2cf3b90e56989
URL: https://github.com/llvm/llvm-project/commit/1d47d5d67c053d74407e97aaf9e2cf3b90e56989
DIFF: https://github.com/llvm/llvm-project/commit/1d47d5d67c053d74407e97aaf9e2cf3b90e56989.diff
LOG: [DAG] Move F16<->FP constant folds from getNode to FoldConstantArithmetic
Added:
Modified:
llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index 9114f61a051fb4..b00b7a7f689627 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -5529,19 +5529,6 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
if (VT == MVT::f128 && C->getValueType(0) == MVT::i128)
return getConstantFP(APFloat(APFloat::IEEEquad(), Val), DL, VT);
break;
- case ISD::FP16_TO_FP:
- case ISD::BF16_TO_FP: {
- bool Ignored;
- APFloat FPV(Opcode == ISD::FP16_TO_FP ? APFloat::IEEEhalf()
- : APFloat::BFloat(),
- (Val.getBitWidth() == 16) ? Val : Val.trunc(16));
-
- // This can return overflow, underflow, or inexact; we don't care.
- // FIXME need to be more flexible about rounding mode.
- (void)FPV.convert(EVTToAPFloatSemantics(VT),
- APFloat::rmNearestTiesToEven, &Ignored);
- return getConstantFP(FPV, DL, VT);
- }
case ISD::STEP_VECTOR: {
if (SDValue V = FoldSTEP_VECTOR(DL, VT, N1, *this))
return V;
@@ -5564,16 +5551,6 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
if (VT == MVT::i64 && C->getValueType(0) == MVT::f64)
return getConstant(V.bitcastToAPInt().getZExtValue(), DL, VT);
break;
- case ISD::FP_TO_FP16:
- case ISD::FP_TO_BF16: {
- bool Ignored;
- // This can return overflow, underflow, or inexact; we don't care.
- // FIXME need to be more flexible about rounding mode.
- (void)V.convert(Opcode == ISD::FP_TO_FP16 ? APFloat::IEEEhalf()
- : APFloat::BFloat(),
- APFloat::rmNearestTiesToEven, &Ignored);
- return getConstant(V.bitcastToAPInt().getZExtValue(), DL, VT);
- }
}
}
@@ -5591,12 +5568,16 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
case ISD::FP_EXTEND:
case ISD::FP_TO_SINT:
case ISD::FP_TO_UINT:
+ case ISD::FP_TO_FP16:
+ case ISD::FP_TO_BF16:
case ISD::TRUNCATE:
case ISD::ANY_EXTEND:
case ISD::ZERO_EXTEND:
case ISD::SIGN_EXTEND:
case ISD::UINT_TO_FP:
case ISD::SINT_TO_FP:
+ case ISD::FP16_TO_FP:
+ case ISD::BF16_TO_FP:
case ISD::ABS:
case ISD::BITREVERSE:
case ISD::BSWAP:
@@ -6109,6 +6090,19 @@ SDValue SelectionDAG::FoldConstantArithmetic(unsigned Opcode, const SDLoc &DL,
APFloat::rmNearestTiesToEven);
return getConstantFP(apf, DL, VT);
}
+ case ISD::FP16_TO_FP:
+ case ISD::BF16_TO_FP: {
+ bool Ignored;
+ APFloat FPV(Opcode == ISD::FP16_TO_FP ? APFloat::IEEEhalf()
+ : APFloat::BFloat(),
+ (Val.getBitWidth() == 16) ? Val : Val.trunc(16));
+
+ // This can return overflow, underflow, or inexact; we don't care.
+ // FIXME need to be more flexible about rounding mode.
+ (void)FPV.convert(EVTToAPFloatSemantics(VT),
+ APFloat::rmNearestTiesToEven, &Ignored);
+ return getConstantFP(FPV, DL, VT);
+ }
}
}
@@ -6159,6 +6153,16 @@ SDValue SelectionDAG::FoldConstantArithmetic(unsigned Opcode, const SDLoc &DL,
break;
return getConstant(IntVal, DL, VT);
}
+ case ISD::FP_TO_FP16:
+ case ISD::FP_TO_BF16: {
+ bool Ignored;
+ // This can return overflow, underflow, or inexact; we don't care.
+ // FIXME need to be more flexible about rounding mode.
+ (void)V.convert(Opcode == ISD::FP_TO_FP16 ? APFloat::IEEEhalf()
+ : APFloat::BFloat(),
+ APFloat::rmNearestTiesToEven, &Ignored);
+ return getConstant(V.bitcastToAPInt().getZExtValue(), DL, VT);
+ }
}
}
}
More information about the llvm-commits
mailing list