Changeset View
Changeset View
Standalone View
Standalone View
llvm/lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp
Show First 20 Lines • Show All 2,126 Lines • ▼ Show 20 Lines | |||||
SDValue DAGTypeLegalizer::PromoteFloatOp_BITCAST(SDNode *N, unsigned OpNo) { | SDValue DAGTypeLegalizer::PromoteFloatOp_BITCAST(SDNode *N, unsigned OpNo) { | ||||
SDValue Op = N->getOperand(0); | SDValue Op = N->getOperand(0); | ||||
EVT OpVT = Op->getValueType(0); | EVT OpVT = Op->getValueType(0); | ||||
SDValue Promoted = GetPromotedFloat(N->getOperand(0)); | SDValue Promoted = GetPromotedFloat(N->getOperand(0)); | ||||
EVT PromotedVT = Promoted->getValueType(0); | EVT PromotedVT = Promoted->getValueType(0); | ||||
unsigned Opc = GetPromotionOpcode(PromotedVT, OpVT); | |||||
if (OpVT == MVT::bf16 && !isa<ConstantFPSDNode>(Op)) { | |||||
SDValue Convert = DAG.getNode(Opc, SDLoc(N), MVT::f32, Promoted); | |||||
return DAG.getNode(ISD::TRUNCATE, SDLoc(N), MVT::i16, | |||||
DAG.getBitcast(MVT::i32, Convert)); | |||||
} | |||||
// Convert the promoted float value to the desired IVT. | // Convert the promoted float value to the desired IVT. | ||||
EVT IVT = EVT::getIntegerVT(*DAG.getContext(), OpVT.getSizeInBits()); | EVT IVT = EVT::getIntegerVT(*DAG.getContext(), OpVT.getSizeInBits()); | ||||
SDValue Convert = DAG.getNode(GetPromotionOpcode(PromotedVT, OpVT), SDLoc(N), | SDValue Convert = DAG.getNode(Opc, SDLoc(N), IVT, Promoted); | ||||
IVT, Promoted); | |||||
// The final result type might not be an scalar so we need a bitcast. The | // The final result type might not be an scalar so we need a bitcast. The | ||||
// bitcast will be further legalized if needed. | // bitcast will be further legalized if needed. | ||||
return DAG.getBitcast(N->getValueType(0), Convert); | return DAG.getBitcast(N->getValueType(0), Convert); | ||||
} | } | ||||
// Promote Operand 1 of FCOPYSIGN. Operand 0 ought to be handled by | // Promote Operand 1 of FCOPYSIGN. Operand 0 ought to be handled by | ||||
// PromoteFloatRes_FCOPYSIGN. | // PromoteFloatRes_FCOPYSIGN. | ||||
SDValue DAGTypeLegalizer::PromoteFloatOp_FCOPYSIGN(SDNode *N, unsigned OpNo) { | SDValue DAGTypeLegalizer::PromoteFloatOp_FCOPYSIGN(SDNode *N, unsigned OpNo) { | ||||
▲ Show 20 Lines • Show All 57 Lines • ▼ Show 20 Lines | |||||
// a STORE of the integer value. | // a STORE of the integer value. | ||||
SDValue DAGTypeLegalizer::PromoteFloatOp_STORE(SDNode *N, unsigned OpNo) { | SDValue DAGTypeLegalizer::PromoteFloatOp_STORE(SDNode *N, unsigned OpNo) { | ||||
StoreSDNode *ST = cast<StoreSDNode>(N); | StoreSDNode *ST = cast<StoreSDNode>(N); | ||||
SDValue Val = ST->getValue(); | SDValue Val = ST->getValue(); | ||||
SDLoc DL(N); | SDLoc DL(N); | ||||
SDValue Promoted = GetPromotedFloat(Val); | SDValue Promoted = GetPromotedFloat(Val); | ||||
EVT VT = ST->getOperand(1).getValueType(); | EVT VT = ST->getOperand(1).getValueType(); | ||||
EVT IVT = EVT::getIntegerVT(*DAG.getContext(), VT.getSizeInBits()); | unsigned Opc = GetPromotionOpcode(Promoted.getValueType(), VT); | ||||
SDValue NewVal; | SDValue NewVal; | ||||
NewVal = DAG.getNode(GetPromotionOpcode(Promoted.getValueType(), VT), DL, | if (VT == MVT::bf16 && !isa<ConstantFPSDNode>(ST->getOperand(1))) { | ||||
IVT, Promoted); | NewVal = DAG.getNode(Opc, DL, MVT::f32, Promoted); | ||||
NewVal = DAG.getNode(ISD::TRUNCATE, DL, MVT::i16, | |||||
DAG.getBitcast(MVT::i32, NewVal)); | |||||
} else { | |||||
EVT IVT = EVT::getIntegerVT(*DAG.getContext(), VT.getSizeInBits()); | |||||
NewVal = DAG.getNode(Opc, DL, IVT, Promoted); | |||||
} | |||||
return DAG.getStore(ST->getChain(), DL, NewVal, ST->getBasePtr(), | return DAG.getStore(ST->getChain(), DL, NewVal, ST->getBasePtr(), | ||||
ST->getMemOperand()); | ST->getMemOperand()); | ||||
} | } | ||||
//===----------------------------------------------------------------------===// | //===----------------------------------------------------------------------===// | ||||
// Float Result Promotion | // Float Result Promotion | ||||
//===----------------------------------------------------------------------===// | //===----------------------------------------------------------------------===// | ||||
▲ Show 20 Lines • Show All 93 Lines • ▼ Show 20 Lines | |||||
// Bitcast from i16 to f16: convert the i16 to a f32 value instead. | // Bitcast from i16 to f16: convert the i16 to a f32 value instead. | ||||
// At this point, it is not possible to determine if the bitcast value is | // At this point, it is not possible to determine if the bitcast value is | ||||
// eventually stored to memory or promoted to f32 or promoted to a floating | // eventually stored to memory or promoted to f32 or promoted to a floating | ||||
// point at a higher precision. Some of these cases are handled by FP_EXTEND, | // point at a higher precision. Some of these cases are handled by FP_EXTEND, | ||||
// STORE promotion handlers. | // STORE promotion handlers. | ||||
SDValue DAGTypeLegalizer::PromoteFloatRes_BITCAST(SDNode *N) { | SDValue DAGTypeLegalizer::PromoteFloatRes_BITCAST(SDNode *N) { | ||||
EVT VT = N->getValueType(0); | EVT VT = N->getValueType(0); | ||||
EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), VT); | EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), VT); | ||||
SDValue Cast; | |||||
if (VT == MVT::bf16) { | |||||
Cast = DAG.getBitcast(MVT::f32, DAG.getNode(ISD::ANY_EXTEND, SDLoc(N), | |||||
MVT::i32, N->getOperand(0))); | |||||
} else { | |||||
// Input type isn't guaranteed to be a scalar int so bitcast if not. The | // Input type isn't guaranteed to be a scalar int so bitcast if not. The | ||||
// bitcast will be legalized further if necessary. | // bitcast will be legalized further if necessary. | ||||
EVT IVT = EVT::getIntegerVT(*DAG.getContext(), | EVT IVT = EVT::getIntegerVT( | ||||
N->getOperand(0).getValueType().getSizeInBits()); | *DAG.getContext(), N->getOperand(0).getValueType().getSizeInBits()); | ||||
SDValue Cast = DAG.getBitcast(IVT, N->getOperand(0)); | Cast = DAG.getBitcast(IVT, N->getOperand(0)); | ||||
} | |||||
return DAG.getNode(GetPromotionOpcode(VT, NVT), SDLoc(N), NVT, Cast); | return DAG.getNode(GetPromotionOpcode(VT, NVT), SDLoc(N), NVT, Cast); | ||||
} | } | ||||
SDValue DAGTypeLegalizer::PromoteFloatRes_ConstantFP(SDNode *N) { | SDValue DAGTypeLegalizer::PromoteFloatRes_ConstantFP(SDNode *N) { | ||||
ConstantFPSDNode *CFPNode = cast<ConstantFPSDNode>(N); | ConstantFPSDNode *CFPNode = cast<ConstantFPSDNode>(N); | ||||
EVT VT = N->getValueType(0); | EVT VT = N->getValueType(0); | ||||
SDLoc DL(N); | SDLoc DL(N); | ||||
▲ Show 20 Lines • Show All 131 Lines • ▼ Show 20 Lines | |||||
// and promote it back to the legal type. | // and promote it back to the legal type. | ||||
SDValue DAGTypeLegalizer::PromoteFloatRes_FP_ROUND(SDNode *N) { | SDValue DAGTypeLegalizer::PromoteFloatRes_FP_ROUND(SDNode *N) { | ||||
SDLoc DL(N); | SDLoc DL(N); | ||||
SDValue Op = N->getOperand(0); | SDValue Op = N->getOperand(0); | ||||
EVT VT = N->getValueType(0); | EVT VT = N->getValueType(0); | ||||
EVT OpVT = Op->getValueType(0); | EVT OpVT = Op->getValueType(0); | ||||
EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), N->getValueType(0)); | EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), N->getValueType(0)); | ||||
EVT IVT = EVT::getIntegerVT(*DAG.getContext(), VT.getSizeInBits()); | EVT RVT = VT == MVT::bf16 | ||||
? MVT::f32 | |||||
: EVT::getIntegerVT(*DAG.getContext(), VT.getSizeInBits()); | |||||
// Round promoted float to desired precision | // Round promoted float to desired precision | ||||
SDValue Round = DAG.getNode(GetPromotionOpcode(OpVT, VT), DL, IVT, Op); | SDValue Round = DAG.getNode(GetPromotionOpcode(OpVT, VT), DL, RVT, Op); | ||||
// Promote it back to the legal output type | // Promote it back to the legal output type | ||||
return DAG.getNode(GetPromotionOpcode(VT, NVT), DL, NVT, Round); | return DAG.getNode(GetPromotionOpcode(VT, NVT), DL, NVT, Round); | ||||
} | } | ||||
SDValue DAGTypeLegalizer::PromoteFloatRes_LOAD(SDNode *N) { | SDValue DAGTypeLegalizer::PromoteFloatRes_LOAD(SDNode *N) { | ||||
LoadSDNode *L = cast<LoadSDNode>(N); | LoadSDNode *L = cast<LoadSDNode>(N); | ||||
EVT VT = N->getValueType(0); | EVT VT = N->getValueType(0); | ||||
// Load the value as an integer value with the same number of bits. | // Load the value as an integer value with the same number of bits. | ||||
EVT IVT = EVT::getIntegerVT(*DAG.getContext(), VT.getSizeInBits()); | EVT IVT = EVT::getIntegerVT(*DAG.getContext(), VT.getSizeInBits()); | ||||
SDValue newL = DAG.getLoad( | SDValue newL = DAG.getLoad( | ||||
L->getAddressingMode(), L->getExtensionType(), IVT, SDLoc(N), | L->getAddressingMode(), L->getExtensionType(), IVT, SDLoc(N), | ||||
L->getChain(), L->getBasePtr(), L->getOffset(), L->getPointerInfo(), IVT, | L->getChain(), L->getBasePtr(), L->getOffset(), L->getPointerInfo(), IVT, | ||||
L->getOriginalAlign(), L->getMemOperand()->getFlags(), L->getAAInfo()); | L->getOriginalAlign(), L->getMemOperand()->getFlags(), L->getAAInfo()); | ||||
// Legalize the chain result by replacing uses of the old value chain with the | // Legalize the chain result by replacing uses of the old value chain with the | ||||
// new one | // new one | ||||
ReplaceValueWith(SDValue(N, 1), newL.getValue(1)); | ReplaceValueWith(SDValue(N, 1), newL.getValue(1)); | ||||
if (VT == MVT::bf16) | |||||
newL = DAG.getBitcast( | |||||
MVT::f32, DAG.getNode(ISD::ANY_EXTEND, SDLoc(N), MVT::i32, newL)); | |||||
// Convert the integer value to the desired FP type | // Convert the integer value to the desired FP type | ||||
EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), VT); | EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), VT); | ||||
return DAG.getNode(GetPromotionOpcode(VT, NVT), SDLoc(N), NVT, newL); | return DAG.getNode(GetPromotionOpcode(VT, NVT), SDLoc(N), NVT, newL); | ||||
} | } | ||||
// Construct a new SELECT node with the promoted true- and false- values. | // Construct a new SELECT node with the promoted true- and false- values. | ||||
SDValue DAGTypeLegalizer::PromoteFloatRes_SELECT(SDNode *N) { | SDValue DAGTypeLegalizer::PromoteFloatRes_SELECT(SDNode *N) { | ||||
SDValue TrueVal = GetPromotedFloat(N->getOperand(1)); | SDValue TrueVal = GetPromotedFloat(N->getOperand(1)); | ||||
▲ Show 20 Lines • Show All 554 Lines • Show Last 20 Lines |