58#define DEBUG_TYPE "legalizedag"
64struct FloatSignAsInt {
87class SelectionDAGLegalize {
99 EVT getSetCCResultType(
EVT VT)
const {
110 LegalizedNodes(LegalizedNodes), UpdatedNodes(UpdatedNodes) {}
165 void getSignAsIntValue(FloatSignAsInt &State,
const SDLoc &
DL,
167 SDValue modifySignAsInt(
const FloatSignAsInt &State,
const SDLoc &
DL,
214 dbgs() <<
" with: "; New->dump(&DAG));
217 "Replacing one node with another that produces a different number "
221 UpdatedNodes->
insert(New);
227 dbgs() <<
" with: "; New->dump(&DAG));
231 UpdatedNodes->
insert(New.getNode());
232 ReplacedNode(Old.getNode());
239 for (
unsigned i = 0, e = Old->
getNumValues(); i != e; ++i) {
250 dbgs() <<
" with: "; New->dump(&DAG));
254 UpdatedNodes->
insert(New.getNode());
255 ReplacedNode(Old.getNode());
265 bool isObjectScalable) {
267 int FI = cast<FrameIndexSDNode>(StackPtr)->getIndex();
273 ObjectSize, MFI.getObjectAlign(FI));
280SDValue SelectionDAGLegalize::ShuffleWithNarrowerEltType(
285 unsigned NumEltsGrowth = NumDestElts / NumMaskElts;
287 assert(NumEltsGrowth &&
"Cannot promote to vector type with fewer elts!");
289 if (NumEltsGrowth == 1)
290 return DAG.getVectorShuffle(NVT, dl, N1, N2, Mask);
293 for (
unsigned i = 0; i != NumMaskElts; ++i) {
295 for (
unsigned j = 0;
j != NumEltsGrowth; ++
j) {
302 assert(NewMask.
size() == NumDestElts &&
"Non-integer NumEltsGrowth?");
303 assert(TLI.isShuffleMaskLegal(NewMask, NVT) &&
"Shuffle not legal?");
304 return DAG.getVectorShuffle(NVT, dl, N1, N2, NewMask);
323 assert((VT == MVT::f64 || VT == MVT::f32) &&
"Invalid type expansion");
325 (VT == MVT::f64) ? MVT::i64 : MVT::i32);
335 while (SVT != MVT::f32 && SVT != MVT::f16 && SVT != MVT::bf16) {
341 TLI.ShouldShrinkFPConstant(OrigVT)) {
344 Instruction::FPTrunc, LLVMC, SType, DAG.getDataLayout()));
352 DAG.getConstantPool(LLVMC, TLI.getPointerTy(DAG.getDataLayout()));
353 Align Alignment = cast<ConstantPoolSDNode>(CPIdx)->getAlign();
362 OrigVT, dl, DAG.getEntryNode(), CPIdx,
370 EVT VT =
CP->getValueType(0);
371 SDValue CPIdx = DAG.getConstantPool(
CP->getConstantIntValue(),
372 TLI.getPointerTy(DAG.getDataLayout()));
373 Align Alignment = cast<ConstantPoolSDNode>(CPIdx)->getAlign();
375 VT, dl, DAG.getEntryNode(), CPIdx,
401 for (
unsigned i = 0; i != NumElts; ++i)
402 ShufOps.
push_back(i != InsertPos->getZExtValue() ? i : NumElts);
404 return DAG.getVectorShuffle(Vec.
getValueType(), dl, Vec, ScVec, ShufOps);
407 return ExpandInsertToVectorThroughStack(
Op);
434 TLI.isTypeLegal(MVT::i32)) {
436 bitcastToAPInt().zextOrTrunc(32),
437 SDLoc(CFP), MVT::i32);
438 return DAG.getStore(Chain, dl, Con,
Ptr,
ST->getPointerInfo(),
439 ST->getOriginalAlign(), MMOFlags, AAInfo);
445 if (TLI.isTypeLegal(MVT::i64)) {
447 zextOrTrunc(64),
SDLoc(CFP), MVT::i64);
448 return DAG.getStore(Chain, dl, Con,
Ptr,
ST->getPointerInfo(),
449 ST->getOriginalAlign(), MMOFlags, AAInfo);
452 if (TLI.isTypeLegal(MVT::i32) && !
ST->isVolatile()) {
459 if (DAG.getDataLayout().isBigEndian())
462 Lo = DAG.getStore(Chain, dl,
Lo,
Ptr,
ST->getPointerInfo(),
463 ST->getOriginalAlign(), MMOFlags, AAInfo);
465 Hi = DAG.getStore(Chain, dl,
Hi,
Ptr,
466 ST->getPointerInfo().getWithOffset(4),
467 ST->getOriginalAlign(), MMOFlags, AAInfo);
476void SelectionDAGLegalize::LegalizeStoreOps(
SDNode *
Node) {
485 if (!
ST->isTruncatingStore()) {
488 ReplaceNode(ST, OptStore);
493 MVT VT =
Value.getSimpleValueType();
494 switch (TLI.getOperationAction(
ISD::STORE, VT)) {
496 case TargetLowering::Legal: {
499 EVT MemVT =
ST->getMemoryVT();
501 if (!TLI.allowsMemoryAccessForAlignment(*DAG.getContext(),
DL, MemVT,
502 *
ST->getMemOperand())) {
505 ReplaceNode(
SDValue(ST, 0), Result);
510 case TargetLowering::Custom: {
517 case TargetLowering::Promote: {
520 "Can only promote stores to same size type");
523 ST->getOriginalAlign(), MMOFlags, AAInfo);
533 EVT StVT =
ST->getMemoryVT();
536 auto &
DL = DAG.getDataLayout();
538 if (StWidth != StSize) {
543 Value = DAG.getZeroExtendInReg(
Value, dl, StVT);
545 DAG.getTruncStore(Chain, dl,
Value,
Ptr,
ST->getPointerInfo(), NVT,
546 ST->getOriginalAlign(), MMOFlags, AAInfo);
552 unsigned LogStWidth =
Log2_32(StWidthBits);
554 unsigned RoundWidth = 1 << LogStWidth;
555 assert(RoundWidth < StWidthBits);
556 unsigned ExtraWidth = StWidthBits - RoundWidth;
557 assert(ExtraWidth < RoundWidth);
558 assert(!(RoundWidth % 8) && !(ExtraWidth % 8) &&
559 "Store size not an integral number of bytes!");
563 unsigned IncrementSize;
565 if (
DL.isLittleEndian()) {
568 Lo = DAG.getTruncStore(Chain, dl,
Value,
Ptr,
ST->getPointerInfo(),
569 RoundVT,
ST->getOriginalAlign(), MMOFlags, AAInfo);
572 IncrementSize = RoundWidth / 8;
577 DAG.getConstant(RoundWidth, dl,
578 TLI.getShiftAmountTy(
Value.getValueType(),
DL)));
579 Hi = DAG.getTruncStore(Chain, dl,
Hi,
Ptr,
580 ST->getPointerInfo().getWithOffset(IncrementSize),
581 ExtraVT,
ST->getOriginalAlign(), MMOFlags, AAInfo);
588 DAG.getConstant(ExtraWidth, dl,
589 TLI.getShiftAmountTy(
Value.getValueType(),
DL)));
590 Hi = DAG.getTruncStore(Chain, dl,
Hi,
Ptr,
ST->getPointerInfo(), RoundVT,
591 ST->getOriginalAlign(), MMOFlags, AAInfo);
594 IncrementSize = RoundWidth / 8;
596 DAG.getConstant(IncrementSize, dl,
597 Ptr.getValueType()));
599 ST->getPointerInfo().getWithOffset(IncrementSize),
600 ExtraVT,
ST->getOriginalAlign(), MMOFlags, AAInfo);
607 switch (TLI.getTruncStoreAction(
ST->getValue().getValueType(), StVT)) {
609 case TargetLowering::Legal: {
610 EVT MemVT =
ST->getMemoryVT();
613 if (!TLI.allowsMemoryAccessForAlignment(*DAG.getContext(),
DL, MemVT,
614 *
ST->getMemOperand())) {
616 ReplaceNode(
SDValue(ST, 0), Result);
620 case TargetLowering::Custom: {
626 case TargetLowering::Expand:
628 "Vector Stores are handled in LegalizeVectorOps");
633 if (TLI.isTypeLegal(StVT)) {
636 ST->getOriginalAlign(), MMOFlags, AAInfo);
641 TLI.getTypeToTransformTo(*DAG.getContext(), StVT),
644 DAG.getTruncStore(Chain, dl,
Value,
Ptr,
ST->getPointerInfo(), StVT,
645 ST->getOriginalAlign(), MMOFlags, AAInfo);
654void SelectionDAGLegalize::LegalizeLoadOps(
SDNode *
Node) {
663 LLVM_DEBUG(
dbgs() <<
"Legalizing non-extending load operation\n");
664 MVT VT =
Node->getSimpleValueType(0);
668 switch (TLI.getOperationAction(
Node->getOpcode(), VT)) {
670 case TargetLowering::Legal: {
671 EVT MemVT =
LD->getMemoryVT();
675 if (!TLI.allowsMemoryAccessForAlignment(*DAG.getContext(),
DL, MemVT,
676 *
LD->getMemOperand())) {
677 std::tie(RVal, RChain) = TLI.expandUnalignedLoad(LD, DAG);
681 case TargetLowering::Custom:
682 if (
SDValue Res = TLI.LowerOperation(RVal, DAG)) {
688 case TargetLowering::Promote: {
689 MVT NVT = TLI.getTypeToPromoteTo(
Node->getOpcode(), VT);
691 "Can only promote loads to same size type");
693 SDValue Res = DAG.getLoad(NVT, dl, Chain,
Ptr,
LD->getMemOperand());
701 DAG.ReplaceAllUsesOfValueWith(
SDValue(
Node, 0), RVal);
702 DAG.ReplaceAllUsesOfValueWith(
SDValue(
Node, 1), RChain);
704 UpdatedNodes->insert(RVal.
getNode());
705 UpdatedNodes->insert(RChain.
getNode());
713 EVT SrcVT =
LD->getMemoryVT();
727 TLI.getLoadExtAction(ExtType,
Node->getValueType(0), MVT::i1) ==
728 TargetLowering::Promote)) {
742 Chain,
Ptr,
LD->getPointerInfo(), NVT,
743 LD->getOriginalAlign(), MMOFlags, AAInfo);
751 Result, DAG.getValueType(SrcVT));
755 Result.getValueType(), Result,
756 DAG.getValueType(SrcVT));
764 unsigned LogSrcWidth =
Log2_32(SrcWidthBits);
766 unsigned RoundWidth = 1 << LogSrcWidth;
767 assert(RoundWidth < SrcWidthBits);
768 unsigned ExtraWidth = SrcWidthBits - RoundWidth;
769 assert(ExtraWidth < RoundWidth);
770 assert(!(RoundWidth % 8) && !(ExtraWidth % 8) &&
771 "Load size not an integral number of bytes!");
775 unsigned IncrementSize;
776 auto &
DL = DAG.getDataLayout();
778 if (
DL.isLittleEndian()) {
782 LD->getPointerInfo(), RoundVT,
LD->getOriginalAlign(),
786 IncrementSize = RoundWidth / 8;
789 Hi = DAG.getExtLoad(ExtType, dl,
Node->getValueType(0), Chain,
Ptr,
790 LD->getPointerInfo().getWithOffset(IncrementSize),
791 ExtraVT,
LD->getOriginalAlign(), MMOFlags, AAInfo);
801 DAG.getConstant(RoundWidth, dl,
802 TLI.getShiftAmountTy(
Hi.getValueType(),
DL)));
810 Hi = DAG.getExtLoad(ExtType, dl,
Node->getValueType(0), Chain,
Ptr,
811 LD->getPointerInfo(), RoundVT,
LD->getOriginalAlign(),
815 IncrementSize = RoundWidth / 8;
819 LD->getPointerInfo().getWithOffset(IncrementSize),
820 ExtraVT,
LD->getOriginalAlign(), MMOFlags, AAInfo);
830 DAG.getConstant(ExtraWidth, dl,
831 TLI.getShiftAmountTy(
Hi.getValueType(),
DL)));
839 bool isCustom =
false;
840 switch (TLI.getLoadExtAction(ExtType,
Node->getValueType(0),
843 case TargetLowering::Custom:
846 case TargetLowering::Legal:
858 EVT MemVT =
LD->getMemoryVT();
860 if (!TLI.allowsMemoryAccess(*DAG.getContext(),
DL, MemVT,
861 *
LD->getMemOperand())) {
862 std::tie(
Value, Chain) = TLI.expandUnalignedLoad(LD, DAG);
867 case TargetLowering::Expand: {
868 EVT DestVT =
Node->getValueType(0);
874 (TLI.isTypeLegal(SrcVT) ||
875 TLI.isLoadExtLegal(ExtType, LoadVT, SrcVT))) {
882 SrcVT,
LD->getMemOperand());
885 Value = DAG.getNode(ExtendOp, dl,
Node->getValueType(0), Load);
886 Chain =
Load.getValue(1);
895 if (SVT == MVT::f16 || SVT == MVT::bf16) {
901 Ptr, ISrcVT,
LD->getMemOperand());
905 Chain =
Result.getValue(1);
911 "Vector Loads are handled in LegalizeVectorOps");
918 "EXTLOAD should always be supported!");
922 Node->getValueType(0),
924 LD->getMemOperand());
929 Result, DAG.getValueType(SrcVT));
931 ValRes = DAG.getZeroExtendInReg(Result, dl, SrcVT);
933 Chain =
Result.getValue(1);
944 DAG.ReplaceAllUsesOfValueWith(
SDValue(
Node, 1), Chain);
946 UpdatedNodes->insert(
Value.getNode());
947 UpdatedNodes->insert(Chain.
getNode());
954void SelectionDAGLegalize::LegalizeOp(
SDNode *
Node) {
963 for (
unsigned i = 0, e =
Node->getNumValues(); i != e; ++i)
964 assert(TLI.getTypeAction(*DAG.getContext(),
Node->getValueType(i)) ==
965 TargetLowering::TypeLegal &&
966 "Unexpected illegal type!");
969 assert((TLI.getTypeAction(*DAG.getContext(),
Op.getValueType()) ==
970 TargetLowering::TypeLegal ||
973 "Unexpected illegal type!");
978 bool SimpleFinishLegalizing =
true;
979 switch (
Node->getOpcode()) {
984 Action = TLI.getOperationAction(
Node->getOpcode(), MVT::Other);
987 Action = TLI.getOperationAction(
Node->getOpcode(),
988 Node->getValueType(0));
991 Action = TLI.getOperationAction(
Node->getOpcode(),
992 Node->getValueType(0));
993 if (Action != TargetLowering::Promote)
994 Action = TLI.getOperationAction(
Node->getOpcode(), MVT::Other);
998 Action = TLI.getOperationAction(
Node->getOpcode(),
999 Node->getOperand(1).getValueType());
1010 Action = TLI.getOperationAction(
Node->getOpcode(),
1011 Node->getOperand(0).getValueType());
1024 Action = TLI.getOperationAction(
Node->getOpcode(),
1025 Node->getOperand(1).getValueType());
1028 EVT InnerType = cast<VTSDNode>(
Node->getOperand(1))->getVT();
1029 Action = TLI.getOperationAction(
Node->getOpcode(), InnerType);
1033 Action = TLI.getOperationAction(
Node->getOpcode(),
1034 Node->getOperand(1).getValueType());
1043 unsigned Opc =
Node->getOpcode();
1048 : (Opc ==
ISD::SETCC || Opc == ISD::VP_SETCC) ? 2
1050 unsigned CompareOperand = Opc ==
ISD::BR_CC ? 2
1054 MVT OpVT =
Node->getOperand(CompareOperand).getSimpleValueType();
1056 cast<CondCodeSDNode>(
Node->getOperand(CCOperand))->get();
1057 Action = TLI.getCondCodeAction(CCCode, OpVT);
1058 if (Action == TargetLowering::Legal) {
1060 Action = TLI.getOperationAction(
Node->getOpcode(),
1061 Node->getValueType(0));
1063 Action = TLI.getOperationAction(
Node->getOpcode(), OpVT);
1071 SimpleFinishLegalizing =
false;
1078 SimpleFinishLegalizing =
false;
1091 Action = TLI.getOperationAction(
Node->getOpcode(),
Node->getValueType(0));
1092 if (Action == TargetLowering::Legal)
1093 Action = TargetLowering::Expand;
1103 Action = TLI.getOperationAction(
Node->getOpcode(),
Node->getValueType(0));
1104 if (Action == TargetLowering::Legal)
1105 Action = TargetLowering::Custom;
1110 Action = TLI.getOperationAction(
Node->getOpcode(),
Node->getValueType(0));
1116 Action = TLI.getOperationAction(
Node->getOpcode(), MVT::i64);
1123 Action = TargetLowering::Legal;
1126 Action = TLI.getOperationAction(
Node->getOpcode(),
Node->getValueType(0));
1127 if (Action == TargetLowering::Expand) {
1131 Node->getOperand(0));
1138 Action = TLI.getOperationAction(
Node->getOpcode(),
Node->getValueType(0));
1139 if (Action == TargetLowering::Expand) {
1143 Node->getOperand(0));
1159 Action = TLI.getOperationAction(
Node->getOpcode(),
Node->getValueType(0));
1169 unsigned Scale =
Node->getConstantOperandVal(2);
1170 Action = TLI.getFixedPointOperationAction(
Node->getOpcode(),
1171 Node->getValueType(0), Scale);
1175 Action = TLI.getOperationAction(
Node->getOpcode(),
1176 cast<MaskedScatterSDNode>(
Node)->getValue().getValueType());
1179 Action = TLI.getOperationAction(
Node->getOpcode(),
1180 cast<MaskedStoreSDNode>(
Node)->getValue().getValueType());
1182 case ISD::VP_SCATTER:
1183 Action = TLI.getOperationAction(
1185 cast<VPScatterSDNode>(
Node)->getValue().getValueType());
1188 Action = TLI.getOperationAction(
1190 cast<VPStoreSDNode>(
Node)->getValue().getValueType());
1192 case ISD::EXPERIMENTAL_VP_STRIDED_STORE:
1193 Action = TLI.getOperationAction(
1195 cast<VPStridedStoreSDNode>(
Node)->getValue().getValueType());
1213 Action = TLI.getOperationAction(
1214 Node->getOpcode(),
Node->getOperand(0).getValueType());
1218 case ISD::VP_REDUCE_FADD:
1219 case ISD::VP_REDUCE_FMUL:
1220 case ISD::VP_REDUCE_ADD:
1221 case ISD::VP_REDUCE_MUL:
1222 case ISD::VP_REDUCE_AND:
1223 case ISD::VP_REDUCE_OR:
1224 case ISD::VP_REDUCE_XOR:
1225 case ISD::VP_REDUCE_SMAX:
1226 case ISD::VP_REDUCE_SMIN:
1227 case ISD::VP_REDUCE_UMAX:
1228 case ISD::VP_REDUCE_UMIN:
1229 case ISD::VP_REDUCE_FMAX:
1230 case ISD::VP_REDUCE_FMIN:
1231 case ISD::VP_REDUCE_FMAXIMUM:
1232 case ISD::VP_REDUCE_FMINIMUM:
1233 case ISD::VP_REDUCE_SEQ_FADD:
1234 case ISD::VP_REDUCE_SEQ_FMUL:
1235 Action = TLI.getOperationAction(
1236 Node->getOpcode(),
Node->getOperand(1).getValueType());
1238 case ISD::VP_CTTZ_ELTS:
1239 case ISD::VP_CTTZ_ELTS_ZERO_UNDEF:
1240 Action = TLI.getOperationAction(
Node->getOpcode(),
1241 Node->getOperand(0).getValueType());
1244 Action = TLI.getOperationAction(
1246 cast<MaskedHistogramSDNode>(
Node)->getIndex().getValueType());
1250 Action = TLI.getCustomOperationAction(*
Node);
1252 Action = TLI.getOperationAction(
Node->getOpcode(),
Node->getValueType(0));
1257 if (SimpleFinishLegalizing) {
1259 switch (
Node->getOpcode()) {
1278 NewNode = DAG.UpdateNodeOperands(
Node, Op0, SAO);
1298 NewNode = DAG.UpdateNodeOperands(
Node, Op0, Op1, SAO);
1304 if (NewNode !=
Node) {
1305 ReplaceNode(
Node, NewNode);
1309 case TargetLowering::Legal:
1312 case TargetLowering::Custom:
1320 if (
Node->getNumValues() == 1) {
1324 Node->getValueType(0) == MVT::Glue) &&
1325 "Type mismatch for custom legalized operation");
1333 for (
unsigned i = 0, e =
Node->getNumValues(); i != e; ++i) {
1337 Node->getValueType(i) == MVT::Glue) &&
1338 "Type mismatch for custom legalized operation");
1342 ReplaceNode(
Node, ResultVals.
data());
1347 case TargetLowering::Expand:
1348 if (ExpandNode(
Node))
1351 case TargetLowering::LibCall:
1352 ConvertNodeToLibcall(
Node);
1354 case TargetLowering::Promote:
1360 switch (
Node->getOpcode()) {
1373 return LegalizeLoadOps(
Node);
1375 return LegalizeStoreOps(
Node);
1379SDValue SelectionDAGLegalize::ExpandExtractFromVectorThroughStack(
SDValue Op) {
1399 if (
ST->isIndexed() ||
ST->isTruncatingStore() ||
1400 ST->getValue() != Vec)
1405 if (!
ST->getChain().reachesChainWithoutSideEffects(DAG.getEntryNode()))
1414 ST->hasPredecessor(
Op.getNode()))
1427 StackPtr = DAG.CreateStackTemporary(VecVT);
1430 Ch = DAG.getStore(DAG.getEntryNode(), dl, Vec, StackPtr, StoreMMO);
1434 Align ElementAlignment =
1435 std::min(cast<StoreSDNode>(Ch)->
getAlign(),
1436 DAG.getDataLayout().getPrefTypeAlign(
1437 Op.getValueType().getTypeForEVT(*DAG.getContext())));
1439 if (
Op.getValueType().isVector()) {
1440 StackPtr = TLI.getVectorSubVecPointer(DAG, StackPtr, VecVT,
1441 Op.getValueType(),
Idx);
1442 NewLoad = DAG.getLoad(
Op.getValueType(), dl, Ch, StackPtr,
1445 StackPtr = TLI.getVectorElementPointer(DAG, StackPtr, VecVT,
Idx);
1446 NewLoad = DAG.getExtLoad(
ISD::EXTLOAD, dl,
Op.getValueType(), Ch, StackPtr,
1452 DAG.ReplaceAllUsesOfValueWith(Ch,
SDValue(NewLoad.
getNode(), 1));
1457 NewLoadOperands[0] = Ch;
1459 SDValue(DAG.UpdateNodeOperands(NewLoad.
getNode(), NewLoadOperands), 0);
1463SDValue SelectionDAGLegalize::ExpandInsertToVectorThroughStack(
SDValue Op) {
1464 assert(
Op.getValueType().isVector() &&
"Non-vector insert subvector!");
1475 int FI = cast<FrameIndexSDNode>(
StackPtr.getNode())->getIndex();
1480 Align BaseVecAlignment =
1481 DAG.getMachineFunction().getFrameInfo().getObjectAlign(FI);
1482 SDValue Ch = DAG.getStore(DAG.getEntryNode(), dl, Vec, StackPtr, PtrInfo,
1486 Idx = DAG.getFreeze(
Idx);
1489 Align PartAlignment = DAG.getDataLayout().getPrefTypeAlign(PartTy);
1494 TLI.getVectorSubVecPointer(DAG, StackPtr, VecVT, PartVT,
Idx);
1498 Ch, dl, Part, SubStackPtr,
1503 TLI.getVectorElementPointer(DAG, StackPtr, VecVT,
Idx);
1506 Ch = DAG.getTruncStore(
1507 Ch, dl, Part, SubStackPtr,
1513 "ElementAlignment does not match!");
1516 return DAG.getLoad(
Op.getValueType(), dl, Ch, StackPtr, PtrInfo,
1523 "Unexpected opcode!");
1529 EVT VT =
Node->getValueType(0);
1531 :
Node->getOperand(0).getValueType();
1533 SDValue FIPtr = DAG.CreateStackTemporary(VT);
1534 int FI = cast<FrameIndexSDNode>(FIPtr.
getNode())->getIndex();
1541 assert(TypeByteSize > 0 &&
"Vector element type too small for stack store!");
1545 bool Truncate = isa<BuildVectorSDNode>(
Node) &&
1546 MemVT.
bitsLT(
Node->getOperand(0).getValueType());
1549 for (
unsigned i = 0, e =
Node->getNumOperands(); i != e; ++i) {
1551 if (
Node->getOperand(i).isUndef())
continue;
1553 unsigned Offset = TypeByteSize*i;
1559 Stores.
push_back(DAG.getTruncStore(DAG.getEntryNode(), dl,
1563 Stores.
push_back(DAG.getStore(DAG.getEntryNode(), dl,
Node->getOperand(i),
1568 if (!Stores.
empty())
1571 StoreChain = DAG.getEntryNode();
1574 return DAG.getLoad(VT, dl, StoreChain, FIPtr, PtrInfo);
1580void SelectionDAGLegalize::getSignAsIntValue(FloatSignAsInt &State,
1583 EVT FloatVT =
Value.getValueType();
1585 State.FloatVT = FloatVT;
1588 if (TLI.isTypeLegal(IVT)) {
1591 State.SignBit = NumBits - 1;
1597 MVT LoadTy = TLI.getRegisterType(MVT::i8);
1600 int FI = cast<FrameIndexSDNode>(
StackPtr.getNode())->getIndex();
1605 State.Chain = DAG.getStore(DAG.getEntryNode(),
DL,
Value, State.FloatPtr,
1606 State.FloatPointerInfo);
1613 State.IntPointerInfo = State.FloatPointerInfo;
1616 unsigned ByteOffset = (NumBits / 8) - 1;
1623 State.IntPtr = IntPtr;
1624 State.IntValue = DAG.getExtLoad(
ISD::EXTLOAD,
DL, LoadTy, State.Chain, IntPtr,
1625 State.IntPointerInfo, MVT::i8);
1632SDValue SelectionDAGLegalize::modifySignAsInt(
const FloatSignAsInt &State,
1639 SDValue Chain = DAG.getTruncStore(State.Chain,
DL, NewIntValue, State.IntPtr,
1640 State.IntPointerInfo, MVT::i8);
1641 return DAG.getLoad(State.FloatVT,
DL, Chain, State.FloatPtr,
1642 State.FloatPointerInfo);
1651 FloatSignAsInt SignAsInt;
1652 getSignAsIntValue(SignAsInt,
DL, Sign);
1654 EVT IntVT = SignAsInt.IntValue.getValueType();
1655 SDValue SignMask = DAG.getConstant(SignAsInt.SignMask,
DL, IntVT);
1662 if (TLI.isOperationLegalOrCustom(
ISD::FABS, FloatVT) &&
1663 TLI.isOperationLegalOrCustom(
ISD::FNEG, FloatVT)) {
1666 SDValue Cond = DAG.getSetCC(
DL, getSetCCResultType(IntVT), SignBit,
1668 return DAG.getSelect(
DL, FloatVT,
Cond, NegValue, AbsValue);
1672 FloatSignAsInt MagAsInt;
1673 getSignAsIntValue(MagAsInt,
DL, Mag);
1674 EVT MagVT = MagAsInt.IntValue.getValueType();
1675 SDValue ClearSignMask = DAG.getConstant(~MagAsInt.SignMask,
DL, MagVT);
1680 int ShiftAmount = SignAsInt.SignBit - MagAsInt.SignBit;
1681 EVT ShiftVT = IntVT;
1687 if (ShiftAmount > 0) {
1688 SDValue ShiftCnst = DAG.getConstant(ShiftAmount,
DL, ShiftVT);
1690 }
else if (ShiftAmount < 0) {
1691 SDValue ShiftCnst = DAG.getConstant(-ShiftAmount,
DL, ShiftVT);
1703 return modifySignAsInt(MagAsInt,
DL, CopiedSign);
1709 FloatSignAsInt SignAsInt;
1710 getSignAsIntValue(SignAsInt,
DL,
Node->getOperand(0));
1711 EVT IntVT = SignAsInt.IntValue.getValueType();
1714 SDValue SignMask = DAG.getConstant(SignAsInt.SignMask,
DL, IntVT);
1719 return modifySignAsInt(SignAsInt,
DL, SignFlip);
1727 EVT FloatVT =
Value.getValueType();
1734 FloatSignAsInt ValueAsInt;
1735 getSignAsIntValue(ValueAsInt,
DL,
Value);
1736 EVT IntVT = ValueAsInt.IntValue.getValueType();
1737 SDValue ClearSignMask = DAG.getConstant(~ValueAsInt.SignMask,
DL, IntVT);
1740 return modifySignAsInt(ValueAsInt,
DL, ClearedSign);
1743void SelectionDAGLegalize::ExpandDYNAMIC_STACKALLOC(
SDNode*
Node,
1745 Register SPReg = TLI.getStackPointerRegisterToSaveRestore();
1746 assert(
SPReg &&
"Target cannot require DYNAMIC_STACKALLOC expansion and"
1747 " not tell us which reg is the stack pointer!");
1749 EVT VT =
Node->getValueType(0);
1757 Chain = DAG.getCALLSEQ_START(Chain, 0, 0, dl);
1762 Align Alignment = cast<ConstantSDNode>(Tmp3)->getAlignValue();
1770 if (Alignment > StackAlign)
1772 DAG.getSignedConstant(-Alignment.
value(), dl, VT));
1773 Chain = DAG.getCopyToReg(Chain, dl,
SPReg, Tmp1);
1775 Tmp2 = DAG.getCALLSEQ_END(Chain, 0, 0,
SDValue(), dl);
1787 return EmitStackConvert(
SrcOp, SlotVT, DestVT, dl, DAG.getEntryNode());
1795 Align DestAlign = DAG.getDataLayout().getPrefTypeAlign(DestType);
1798 if ((SrcVT.
bitsGT(SlotVT) &&
1799 !TLI.isTruncStoreLegalOrCustom(
SrcOp.getValueType(), SlotVT)) ||
1800 (SlotVT.
bitsLT(DestVT) &&
1801 !TLI.isLoadExtLegalOrCustom(
ISD::EXTLOAD, DestVT, SlotVT)))
1805 Align SrcAlign = DAG.getDataLayout().getPrefTypeAlign(
1806 SrcOp.getValueType().getTypeForEVT(*DAG.getContext()));
1818 if (SrcVT.
bitsGT(SlotVT))
1819 Store = DAG.getTruncStore(Chain, dl,
SrcOp, FIPtr, PtrInfo,
1823 Store = DAG.getStore(Chain, dl,
SrcOp, FIPtr, PtrInfo, SrcAlign);
1827 if (SlotVT.
bitsEq(DestVT))
1828 return DAG.getLoad(DestVT, dl, Store, FIPtr, PtrInfo, DestAlign);
1831 return DAG.getExtLoad(
ISD::EXTLOAD, dl, DestVT, Store, FIPtr, PtrInfo, SlotVT,
1844 SDValue Ch = DAG.getTruncStore(
1845 DAG.getEntryNode(), dl,
Node->getOperand(0), StackPtr,
1847 Node->getValueType(0).getVectorElementType());
1849 Node->getValueType(0), dl, Ch, StackPtr,
1856 unsigned NumElems =
Node->getNumOperands();
1858 EVT VT =
Node->getValueType(0);
1870 for (
unsigned i = 0; i < NumElems; ++i) {
1881 while (IntermedVals.
size() > 2) {
1882 NewIntermedVals.
clear();
1883 for (
unsigned i = 0, e = (IntermedVals.
size() & ~1u); i < e; i += 2) {
1889 FinalIndices.
reserve(IntermedVals[i].second.
size() +
1890 IntermedVals[i+1].second.
size());
1893 for (
unsigned j = 0, f = IntermedVals[i].second.
size(); j != f;
1896 FinalIndices.
push_back(IntermedVals[i].second[j]);
1898 for (
unsigned j = 0, f = IntermedVals[i+1].second.
size(); j != f;
1900 ShuffleVec[k] = NumElems + j;
1901 FinalIndices.
push_back(IntermedVals[i+1].second[j]);
1907 IntermedVals[i+1].first,
1912 std::make_pair(Shuffle, std::move(FinalIndices)));
1917 if ((IntermedVals.
size() & 1) != 0)
1920 IntermedVals.
swap(NewIntermedVals);
1924 "Invalid number of intermediate vectors");
1925 SDValue Vec1 = IntermedVals[0].first;
1927 if (IntermedVals.
size() > 1)
1928 Vec2 = IntermedVals[1].first;
1933 for (
unsigned i = 0, e = IntermedVals[0].second.
size(); i != e; ++i)
1934 ShuffleVec[IntermedVals[0].second[i]] = i;
1935 for (
unsigned i = 0, e = IntermedVals[1].second.
size(); i != e; ++i)
1936 ShuffleVec[IntermedVals[1].second[i]] = NumElems + i;
1950 unsigned NumElems =
Node->getNumOperands();
1953 EVT VT =
Node->getValueType(0);
1954 EVT OpVT =
Node->getOperand(0).getValueType();
1959 bool isOnlyLowElement =
true;
1960 bool MoreThanTwoValues =
false;
1962 for (
unsigned i = 0; i < NumElems; ++i) {
1967 isOnlyLowElement =
false;
1968 if (!isa<ConstantFPSDNode>(V) && !isa<ConstantSDNode>(V))
1973 }
else if (!Value2.
getNode()) {
1976 }
else if (V != Value1 && V != Value2) {
1977 MoreThanTwoValues =
true;
1982 return DAG.getUNDEF(VT);
1984 if (isOnlyLowElement)
1990 for (
unsigned i = 0, e = NumElems; i !=
e; ++i) {
1992 dyn_cast<ConstantFPSDNode>(
Node->getOperand(i))) {
1995 dyn_cast<ConstantSDNode>(
Node->getOperand(i))) {
2014 DAG.getConstantPool(CP, TLI.getPointerTy(DAG.getDataLayout()));
2015 Align Alignment = cast<ConstantPoolSDNode>(CPIdx)->getAlign();
2017 VT, dl, DAG.getEntryNode(), CPIdx,
2023 for (
unsigned i = 0; i < NumElems; ++i) {
2024 if (
Node->getOperand(i).isUndef())
2029 if (TLI.shouldExpandBuildVectorWithShuffles(VT, DefinedValues.
size())) {
2030 if (!MoreThanTwoValues) {
2032 for (
unsigned i = 0; i < NumElems; ++i) {
2036 ShuffleVec[i] =
V == Value1 ? 0 : NumElems;
2038 if (TLI.isShuffleMaskLegal(ShuffleVec,
Node->getValueType(0))) {
2045 Vec2 = DAG.getUNDEF(VT);
2048 return DAG.getVectorShuffle(VT, dl, Vec1, Vec2, ShuffleVec);
2058 return ExpandVectorBuildThroughStack(
Node);
2063 EVT VT =
Node->getValueType(0);
2066 return DAG.getSplatBuildVector(VT,
DL, SplatVal);
2077 EVT CodePtrTy = TLI.getPointerTy(DAG.getDataLayout());
2079 if (
const char *LibcallName = TLI.getLibcallName(LC))
2080 Callee = DAG.getExternalSymbol(LibcallName, CodePtrTy);
2082 Callee = DAG.getUNDEF(CodePtrTy);
2083 DAG.getContext()->emitError(
Twine(
"no libcall available for ") +
2084 Node->getOperationName(&DAG));
2087 EVT RetVT =
Node->getValueType(0);
2094 SDValue InChain = DAG.getEntryNode();
2099 const Function &
F = DAG.getMachineFunction().getFunction();
2101 TLI.isInTailCallPosition(DAG,
Node, TCChain) &&
2102 (
RetTy ==
F.getReturnType() ||
F.getReturnType()->isVoidTy());
2107 bool signExtend = TLI.shouldSignExtendTypeInLibCall(
RetTy,
isSigned);
2110 .setLibCallee(TLI.getLibcallCallingConv(LC),
RetTy, Callee,
2112 .setTailCall(isTailCall)
2113 .setSExtResult(signExtend)
2114 .setZExtResult(!signExtend)
2115 .setIsPostTypeLegalization(
true);
2117 std::pair<SDValue, SDValue>
CallInfo = TLI.LowerCallTo(CLI);
2122 return {DAG.getRoot(), DAG.getRoot()};
2134 EVT ArgVT =
Op.getValueType();
2138 Entry.IsSExt = TLI.shouldSignExtendTypeInLibCall(ArgTy,
isSigned);
2140 Args.push_back(Entry);
2143 return ExpandLibCall(LC,
Node, std::move(Args),
isSigned);
2146void SelectionDAGLegalize::ExpandFPLibCall(
SDNode*
Node,
2149 if (LC == RTLIB::UNKNOWN_LIBCALL)
2152 if (
Node->isStrictFPOpcode()) {
2153 EVT RetVT =
Node->getValueType(0);
2157 std::pair<SDValue, SDValue> Tmp = TLI.makeLibCall(DAG, LC, RetVT,
2160 Node->getOperand(0));
2162 Results.push_back(Tmp.second);
2165 SDValue Tmp = ExpandLibCall(LC,
Node, IsSignedArgument).first;
2171void SelectionDAGLegalize::ExpandFPLibCall(
SDNode*
Node,
2179 Call_F32, Call_F64, Call_F80,
2180 Call_F128, Call_PPCF128);
2191 switch (
Node->getSimpleValueType(0).SimpleTy) {
2193 case MVT::i8: LC = Call_I8;
break;
2194 case MVT::i16: LC = Call_I16;
break;
2195 case MVT::i32: LC = Call_I32;
break;
2196 case MVT::i64: LC = Call_I64;
break;
2197 case MVT::i128: LC = Call_I128;
break;
2204void SelectionDAGLegalize::ExpandArgFPLibCall(
SDNode*
Node,
2211 EVT InVT =
Node->getOperand(
Node->isStrictFPOpcode() ? 1 : 0).getValueType();
2213 Call_F32, Call_F64, Call_F80,
2214 Call_F128, Call_PPCF128);
2220SelectionDAGLegalize::ExpandDivRemLibCall(
SDNode *
Node,
2222 unsigned Opcode =
Node->getOpcode();
2226 switch (
Node->getSimpleValueType(0).SimpleTy) {
2228 case MVT::i8: LC=
isSigned ? RTLIB::SDIVREM_I8 : RTLIB::UDIVREM_I8;
break;
2229 case MVT::i16: LC=
isSigned ? RTLIB::SDIVREM_I16 : RTLIB::UDIVREM_I16;
break;
2230 case MVT::i32: LC=
isSigned ? RTLIB::SDIVREM_I32 : RTLIB::UDIVREM_I32;
break;
2231 case MVT::i64: LC=
isSigned ? RTLIB::SDIVREM_I64 : RTLIB::UDIVREM_I64;
break;
2232 case MVT::i128: LC=
isSigned ? RTLIB::SDIVREM_I128:RTLIB::UDIVREM_I128;
break;
2238 SDValue InChain = DAG.getEntryNode();
2240 EVT RetVT =
Node->getValueType(0);
2246 EVT ArgVT =
Op.getValueType();
2252 Args.push_back(Entry);
2256 SDValue FIPtr = DAG.CreateStackTemporary(RetVT);
2258 Entry.Ty = PointerType::getUnqual(
RetTy->getContext());
2261 Args.push_back(Entry);
2263 SDValue Callee = DAG.getExternalSymbol(TLI.getLibcallName(LC),
2264 TLI.getPointerTy(DAG.getDataLayout()));
2270 .setLibCallee(TLI.getLibcallCallingConv(LC),
RetTy, Callee,
2275 std::pair<SDValue, SDValue>
CallInfo = TLI.LowerCallTo(CLI);
2308 EVT VT =
Node->getValueType(0);
2311 EVT ExpVT =
N.getValueType();
2313 if (AsIntVT ==
EVT())
2326 TLI.getSetCCResultType(DAG.getDataLayout(), *DAG.getContext(), ExpVT);
2331 const int Precision = APFloat::semanticsPrecision(FltSem);
2333 const SDValue MaxExp = DAG.getSignedConstant(MaxExpVal, dl, ExpVT);
2334 const SDValue MinExp = DAG.getSignedConstant(MinExpVal, dl, ExpVT);
2336 const SDValue DoubleMaxExp = DAG.getSignedConstant(2 * MaxExpVal, dl, ExpVT);
2338 const APFloat One(FltSem,
"1.0");
2339 APFloat ScaleUpK =
scalbn(One, MaxExpVal, APFloat::rmNearestTiesToEven);
2343 scalbn(One, MinExpVal + Precision, APFloat::rmNearestTiesToEven);
2352 SDValue ClampMaxVal = DAG.getConstant(3 * MaxExpVal, dl, ExpVT);
2358 DAG.getSetCC(dl, SetCCVT,
N, DoubleMaxExp,
ISD::SETUGT);
2360 const SDValue ScaleUpVal = DAG.getConstantFP(ScaleUpK, dl, VT);
2372 SDValue Increment0 = DAG.getConstant(-(MinExpVal + Precision), dl, ExpVT);
2373 SDValue Increment1 = DAG.getConstant(-2 * (MinExpVal + Precision), dl, ExpVT);
2378 DAG.getSignedConstant(3 * MinExpVal + 2 * Precision, dl, ExpVT);
2383 const SDValue ScaleDownVal = DAG.getConstantFP(ScaleDownK, dl, VT);
2387 SDValue ScaleDownTwice = DAG.getSetCC(
2389 DAG.getSignedConstant(2 * MinExpVal + Precision, dl, ExpVT),
ISD::SETULT);
2400 DAG.getNode(
ISD::SELECT, dl, VT, NLtMinExp, SelectX_Small,
X));
2404 DAG.getNode(
ISD::SELECT, dl, ExpVT, NLtMinExp, SelectN_Small,
N));
2409 DAG.getShiftAmountConstant(Precision - 1, ExpVT, dl);
2410 SDValue CastExpToValTy = DAG.getZExtOrTrunc(BiasedN, dl, AsIntVT);
2413 ExponentShiftAmt, NUW_NSW);
2415 return DAG.getNode(
ISD::FMUL, dl, VT, NewX, AsFP);
2422 EVT ExpVT =
Node->getValueType(1);
2424 if (AsIntVT ==
EVT())
2429 const unsigned Precision = APFloat::semanticsPrecision(FltSem);
2446 SDValue NegSmallestNormalizedInt = DAG.getConstant(
2450 SDValue SmallestNormalizedInt = DAG.getConstant(
2456 DAG.getConstant(
APFloat::getInf(FltSem).bitcastToAPInt(), dl, AsIntVT);
2462 FractSignMaskVal.
setBit(BitSize - 1);
2465 SDValue SignMask = DAG.getConstant(SignMaskVal, dl, AsIntVT);
2467 SDValue FractSignMask = DAG.getConstant(FractSignMaskVal, dl, AsIntVT);
2469 const APFloat One(FltSem,
"1.0");
2473 scalbn(One, Precision + 1, APFloat::rmNearestTiesToEven);
2475 SDValue ScaleUpK = DAG.getConstantFP(ScaleUpKVal, dl, VT);
2479 TLI.getSetCCResultType(DAG.getDataLayout(), *DAG.getContext(), VT);
2485 SDValue AddNegSmallestNormal =
2487 SDValue DenormOrZero = DAG.getSetCC(dl, SetCCVT, AddNegSmallestNormal,
2491 DAG.getSetCC(dl, SetCCVT, Abs, SmallestNormalizedInt,
ISD::SETULT);
2493 SDValue MinExp = DAG.getSignedConstant(MinExpVal, dl, ExpVT);
2508 DAG.getShiftAmountConstant(Precision - 1, AsIntVT, dl);
2511 SDValue Exp = DAG.getSExtOrTrunc(ShiftedExp, dl, ExpVT);
2514 SDValue DenormalOffset = DAG.getConstant(-Precision - 1, dl, ExpVT);
2520 const APFloat Half(FltSem,
"0.5");
2521 SDValue FPHalf = DAG.getConstant(Half.bitcastToAPInt(), dl, AsIntVT);
2534 return DAG.getMergeValues({Result0, Result1}, dl);
2545 EVT DestVT =
Node->getValueType(0);
2547 unsigned OpNo =
Node->isStrictFPOpcode() ? 1 : 0;
2553 if (SrcVT == MVT::i32 && TLI.isTypeLegal(MVT::f64) &&
2554 (DestVT.
bitsLE(MVT::f64) ||
2558 LLVM_DEBUG(
dbgs() <<
"32-bit [signed|unsigned] integer to float/double "
2562 SDValue StackSlot = DAG.CreateStackTemporary(MVT::f64);
2569 DAG.getConstant(0x80000000u, dl, MVT::i32));
2572 SDValue Hi = DAG.getConstant(0x43300000u, dl, MVT::i32);
2575 if (DAG.getDataLayout().isBigEndian())
2578 SDValue MemChain = DAG.getEntryNode();
2581 SDValue Store1 = DAG.getStore(MemChain, dl,
Lo, StackSlot,
2594 SDValue Bias = DAG.getConstantFP(
2595 isSigned ? llvm::bit_cast<double>(0x4330000080000000ULL)
2596 : llvm::bit_cast<double>(0x4330000000000000ULL),
2601 if (
Node->isStrictFPOpcode()) {
2603 {
Node->getOperand(0), Load, Bias});
2606 std::pair<SDValue, SDValue> ResultPair;
2608 DAG.getStrictFPExtendOrRound(Sub, Chain, dl, DestVT);
2609 Result = ResultPair.first;
2610 Chain = ResultPair.second;
2616 Result = DAG.getFPExtendOrRound(Sub, dl, DestVT);
2625 if (((SrcVT == MVT::i32 || SrcVT == MVT::i64) && DestVT == MVT::f32) ||
2626 (SrcVT == MVT::i64 && DestVT == MVT::f64)) {
2627 LLVM_DEBUG(
dbgs() <<
"Converting unsigned i32/i64 to f32/f64\n");
2642 EVT SetCCVT = getSetCCResultType(SrcVT);
2644 SDValue SignBitTest = DAG.getSetCC(
2645 dl, SetCCVT, Op0, DAG.getConstant(0, dl, SrcVT),
ISD::SETLT);
2647 EVT ShiftVT = TLI.getShiftAmountTy(SrcVT, DAG.getDataLayout());
2648 SDValue ShiftConst = DAG.getConstant(1, dl, ShiftVT);
2650 SDValue AndConst = DAG.getConstant(1, dl, SrcVT);
2655 if (
Node->isStrictFPOpcode()) {
2658 SDValue InCvt = DAG.getSelect(dl, SrcVT, SignBitTest,
Or, Op0);
2660 {
Node->getOperand(0), InCvt });
2668 Flags.setNoFPExcept(
Node->getFlags().hasNoFPExcept());
2669 Fast->setFlags(Flags);
2670 Flags.setNoFPExcept(
true);
2678 return DAG.getSelect(dl, DestVT, SignBitTest, Slow,
Fast);
2682 if (!TLI.isOperationLegalOrCustom(
2691 "Cannot perform lossless SINT_TO_FP!");
2694 if (
Node->isStrictFPOpcode()) {
2696 {
Node->getOperand(0), Op0 });
2700 SDValue SignSet = DAG.getSetCC(dl, getSetCCResultType(SrcVT), Op0,
2703 Four = DAG.getIntPtrConstant(4, dl);
2704 SDValue CstOffset = DAG.getSelect(dl,
Zero.getValueType(),
2705 SignSet, Four, Zero);
2714 case MVT::i8 : FF = 0x43800000ULL;
break;
2715 case MVT::i16: FF = 0x47800000ULL;
break;
2716 case MVT::i32: FF = 0x4F800000ULL;
break;
2717 case MVT::i64: FF = 0x5F800000ULL;
break;
2719 if (DAG.getDataLayout().isLittleEndian())
2721 Constant *FudgeFactor = ConstantInt::get(
2725 DAG.getConstantPool(FudgeFactor, TLI.getPointerTy(DAG.getDataLayout()));
2726 Align Alignment = cast<ConstantPoolSDNode>(CPIdx)->getAlign();
2730 if (DestVT == MVT::f32)
2731 FudgeInReg = DAG.getLoad(
2732 MVT::f32, dl, DAG.getEntryNode(), CPIdx,
2741 LegalizeOp(
Load.getNode());
2745 if (
Node->isStrictFPOpcode()) {
2747 { Tmp1.
getValue(1), Tmp1, FudgeInReg });
2748 Chain =
Result.getValue(1);
2752 return DAG.getNode(
ISD::FADD, dl, DestVT, Tmp1, FudgeInReg);
2760void SelectionDAGLegalize::PromoteLegalINT_TO_FP(
2762 bool IsStrict =
N->isStrictFPOpcode();
2765 EVT DestVT =
N->getValueType(0);
2766 SDValue LegalOp =
N->getOperand(IsStrict ? 1 : 0);
2773 unsigned OpToUse = 0;
2781 if (TLI.isOperationLegalOrCustom(SIntOp, NewInTy)) {
2789 if (TLI.isOperationLegalOrCustom(UIntOp, NewInTy)) {
2801 DAG.
getNode(OpToUse, dl, {DestVT, MVT::Other},
2804 dl, NewInTy, LegalOp)});
2811 DAG.getNode(OpToUse, dl, DestVT,
2813 dl, NewInTy, LegalOp)));
2821void SelectionDAGLegalize::PromoteLegalFP_TO_INT(
SDNode *
N,
const SDLoc &dl,
2823 bool IsStrict =
N->isStrictFPOpcode();
2826 EVT DestVT =
N->getValueType(0);
2827 SDValue LegalOp =
N->getOperand(IsStrict ? 1 : 0);
2829 EVT NewOutTy = DestVT;
2831 unsigned OpToUse = 0;
2841 if (TLI.isOperationLegalOrCustom(OpToUse, NewOutTy))
2846 if (!IsSigned && TLI.isOperationLegalOrCustom(OpToUse, NewOutTy))
2855 SDVTList VTs = DAG.getVTList(NewOutTy, MVT::Other);
2856 Operation = DAG.getNode(OpToUse, dl, VTs,
N->getOperand(0), LegalOp);
2858 Operation = DAG.getNode(OpToUse, dl, NewOutTy, LegalOp);
2873 unsigned Opcode =
Node->getOpcode();
2876 EVT NewOutTy =
Node->getValueType(0);
2881 if (TLI.isOperationLegalOrCustom(Opcode, NewOutTy))
2888 Node->getOperand(1));
2894 EVT VT =
Op.getValueType();
2895 EVT ShVT = TLI.getShiftAmountTy(VT, DAG.getDataLayout());
2900 if (TLI.isOperationLegalOrPromote(
ISD::CTPOP, VT)) {
2906 DAG.getConstant(1ULL << (--i), dl, ShVT));
2911 return DAG.getNode(
ISD::AND, dl, VT, Result, DAG.getConstant(1, dl, VT));
2915 MVT VecVT =
Node->getOperand(1).getSimpleValueType();
2916 MVT NewVecVT = TLI.getTypeToPromoteTo(
Node->getOpcode(), VecVT);
2917 MVT ScalarVT =
Node->getSimpleValueType(0);
2925 assert(
Node->getOperand(0).getValueType().isFloatingPoint() &&
2926 "Only FP promotion is supported");
2930 for (
unsigned j = 1;
j !=
Node->getNumOperands(); ++
j)
2931 if (
Node->getOperand(j).getValueType().isVector() &&
2936 assert(
Node->getOperand(j).getValueType().isFloatingPoint() &&
2937 "Only FP promotion is supported");
2949 DAG.getIntPtrConstant(0,
DL,
true));
2952bool SelectionDAGLegalize::ExpandNode(
SDNode *
Node) {
2956 SDValue Tmp1, Tmp2, Tmp3, Tmp4;
2958 switch (
Node->getOpcode()) {
2960 if ((Tmp1 = TLI.expandABS(
Node, DAG)))
2965 if ((Tmp1 = TLI.expandABD(
Node, DAG)))
2972 if ((Tmp1 = TLI.expandAVG(
Node, DAG)))
2976 if ((Tmp1 = TLI.expandCTPOP(
Node, DAG)))
2981 if ((Tmp1 = TLI.expandCTLZ(
Node, DAG)))
2986 if ((Tmp1 = TLI.expandCTTZ(
Node, DAG)))
2990 if ((Tmp1 = TLI.expandBITREVERSE(
Node, DAG)))
2994 if ((Tmp1 = TLI.expandBSWAP(
Node, DAG)))
2998 Results.push_back(ExpandPARITY(
Node->getOperand(0), dl));
3003 Results.push_back(DAG.getConstant(0, dl,
Node->getValueType(0)));
3006 SDValue CfaArg = DAG.getSExtOrTrunc(
Node->getOperand(0), dl,
3007 TLI.getPointerTy(DAG.getDataLayout()));
3015 DAG.getConstant(0, dl, TLI.getPointerTy(DAG.getDataLayout())));
3021 Results.push_back(DAG.getConstant(1, dl,
Node->getValueType(0)));
3038 DAG.getConstant(0, dl,
Node->getValueType(0)));
3044 Results.push_back(DAG.getConstant(0, dl, MVT::i32));
3050 SDVTList VTs = DAG.getVTList(
Node->getValueType(0), MVT::Other);
3051 SDValue Swap = DAG.getAtomicCmpSwap(
3053 Node->getOperand(0),
Node->getOperand(1), Zero, Zero,
3054 cast<AtomicSDNode>(
Node)->getMemOperand());
3063 Node->getOperand(0),
Node->getOperand(2),
Node->getOperand(1),
3064 cast<AtomicSDNode>(
Node)->getMemOperand());
3072 SDVTList VTs = DAG.getVTList(
Node->getValueType(0), MVT::Other);
3073 SDValue Res = DAG.getAtomicCmpSwap(
3075 Node->getOperand(0),
Node->getOperand(1),
Node->getOperand(2),
3076 Node->getOperand(3), cast<MemSDNode>(
Node)->getMemOperand());
3082 EVT AtomicType = cast<AtomicSDNode>(
Node)->getMemoryVT();
3083 EVT OuterType =
Node->getValueType(0);
3084 switch (TLI.getExtendForAtomicOps()) {
3087 DAG.getValueType(AtomicType));
3089 Node->getOperand(2), DAG.getValueType(AtomicType));
3094 DAG.getValueType(AtomicType));
3095 RHS = DAG.getZeroExtendInReg(
Node->getOperand(2), dl, AtomicType);
3099 LHS = DAG.getZeroExtendInReg(Res, dl, AtomicType);
3100 RHS = DAG.getZeroExtendInReg(
Node->getOperand(2), dl, AtomicType);
3116 EVT VT =
Node->getValueType(0);
3120 cast<VTSDNode>(
RHS->getOperand(1))->getVT() == AN->
getMemoryVT())
3121 RHS =
RHS->getOperand(0);
3125 Node->getOperand(0),
Node->getOperand(1),
3135 for (
unsigned i = 0; i <
Node->getNumValues(); i++)
3139 EVT VT =
Node->getValueType(0);
3141 Results.push_back(DAG.getConstant(0, dl, VT));
3144 Results.push_back(DAG.getConstantFP(0, dl, VT));
3151 if (TLI.isStrictFPEnabled())
3155 if (TLI.getStrictFPOperationAction(
Node->getOpcode(),
3156 Node->getValueType(0))
3157 == TargetLowering::Legal)
3161 if ((Tmp1 = EmitStackConvert(
Node->getOperand(1),
Node->getValueType(0),
3162 Node->getValueType(0), dl,
3163 Node->getOperand(0)))) {
3165 LLVM_DEBUG(
dbgs() <<
"Successfully expanded STRICT_FP_ROUND node\n");
3170 if ((Tmp1 = TLI.expandFP_ROUND(
Node, DAG))) {
3178 if ((Tmp1 = EmitStackConvert(
Node->getOperand(0),
Node->getValueType(0),
3179 Node->getValueType(0), dl)))
3185 if (TLI.isStrictFPEnabled())
3189 if (TLI.getStrictFPOperationAction(
Node->getOpcode(),
3190 Node->getValueType(0))
3191 == TargetLowering::Legal)
3195 if ((Tmp1 = EmitStackConvert(
3196 Node->getOperand(1),
Node->getOperand(1).getValueType(),
3197 Node->getValueType(0), dl,
Node->getOperand(0)))) {
3199 LLVM_DEBUG(
dbgs() <<
"Successfully expanded STRICT_FP_EXTEND node\n");
3205 EVT SrcVT =
Op.getValueType();
3206 EVT DstVT =
Node->getValueType(0);
3212 if ((Tmp1 = EmitStackConvert(
Op, SrcVT, DstVT, dl)))
3222 if (
Op.getValueType() == MVT::bf16) {
3226 Op = DAG.getAnyExtOrTrunc(
Op, dl, MVT::i32);
3230 DAG.getConstant(16, dl,
3231 TLI.getShiftAmountTy(MVT::i32, DAG.getDataLayout())));
3234 if (
Node->getValueType(0) != MVT::f32)
3241 if (
Op.getValueType() != MVT::f32)
3243 DAG.getIntPtrConstant(0, dl,
true));
3245 if (!DAG.isKnownNeverSNaN(
Op)) {
3250 DAG.getConstant(16, dl,
3251 TLI.getShiftAmountTy(MVT::i32, DAG.getDataLayout())));
3254 if (
Node->getValueType(0) == MVT::bf16) {
3258 Op = DAG.getAnyExtOrTrunc(
Op, dl,
Node->getValueType(0));
3264 EVT ExtraVT = cast<VTSDNode>(
Node->getOperand(1))->getVT();
3265 EVT VT =
Node->getValueType(0);
3275 SDValue One = DAG.getConstant(1, dl, VT);
3285 EVT ShiftAmountTy = TLI.getShiftAmountTy(VT, DAG.getDataLayout());
3288 SDValue ShiftCst = DAG.getConstant(BitsDiff, dl, ShiftAmountTy);
3290 Node->getOperand(0), ShiftCst);
3297 if (TLI.expandUINT_TO_FP(
Node, Tmp1, Tmp2, DAG)) {
3299 if (
Node->isStrictFPOpcode())
3306 if ((Tmp1 = ExpandLegalINT_TO_FP(
Node, Tmp2))) {
3308 if (
Node->isStrictFPOpcode())
3313 if (TLI.expandFP_TO_SINT(
Node, Tmp1, DAG))
3317 if (TLI.expandFP_TO_SINT(
Node, Tmp1, DAG)) {
3319 LLVM_DEBUG(
dbgs() <<
"Successfully expanded STRICT_FP_TO_SINT node\n");
3324 if (TLI.expandFP_TO_UINT(
Node, Tmp1, Tmp2, DAG))
3328 if (TLI.expandFP_TO_UINT(
Node, Tmp1, Tmp2, DAG)) {
3330 DAG.ReplaceAllUsesOfValueWith(
SDValue(
Node,1), Tmp2);
3333 LLVM_DEBUG(
dbgs() <<
"Successfully expanded STRICT_FP_TO_UINT node\n");
3339 Results.push_back(TLI.expandFP_TO_INT_SAT(
Node, DAG));
3345 EVT ResVT =
Node->getValueType(0);
3359 if (
Node->getOperand(0).getValueType().getVectorElementCount().isScalar())
3362 Node->getOperand(0));
3364 Tmp1 = ExpandExtractFromVectorThroughStack(
SDValue(
Node, 0));
3374 Results.push_back(ExpandVectorBuildThroughStack(
Node));
3386 EVT VT =
Node->getValueType(0);
3390 if (!TLI.isTypeLegal(EltVT)) {
3391 EVT NewEltVT = TLI.getTypeToTransformTo(*DAG.getContext(), EltVT);
3396 if (NewEltVT.
bitsLT(EltVT)) {
3412 unsigned int factor =
3420 for (
unsigned fi = 0; fi < factor; ++fi)
3424 for (
unsigned fi = 0; fi < factor; ++fi)
3435 for (
unsigned i = 0; i != NumElems; ++i) {
3443 DAG.getVectorIdxConstant(
Idx, dl)));
3447 DAG.getVectorIdxConstant(
Idx - NumElems, dl)));
3450 Tmp1 = DAG.getBuildVector(VT, dl, Ops);
3457 Results.push_back(TLI.expandVectorSplice(
Node, DAG));
3461 EVT OpTy =
Node->getOperand(0).getValueType();
3462 if (
Node->getConstantOperandVal(1)) {
3466 TLI.getShiftAmountTy(
3467 Node->getOperand(0).getValueType(),
3468 DAG.getDataLayout())));
3473 Node->getOperand(0));
3481 if (
Register SP = TLI.getStackPointerRegisterToSaveRestore()) {
3482 Results.push_back(DAG.getCopyFromReg(
Node->getOperand(0), dl, SP,
3483 Node->getValueType(0)));
3486 Results.push_back(DAG.getUNDEF(
Node->getValueType(0)));
3493 if (
Register SP = TLI.getStackPointerRegisterToSaveRestore()) {
3494 Results.push_back(DAG.getCopyToReg(
Node->getOperand(0), dl, SP,
3495 Node->getOperand(1)));
3501 Results.push_back(DAG.getConstant(0, dl,
Node->getValueType(0)));
3516 TLI.expandIS_FPCLASS(
Node->getValueType(0),
Node->getOperand(0),
3527 switch (
Node->getOpcode()) {
3534 Tmp1 =
Node->getOperand(0);
3535 Tmp2 =
Node->getOperand(1);
3536 Tmp1 = DAG.getSelectCC(dl, Tmp1, Tmp2, Tmp1, Tmp2, Pred);
3542 if (
SDValue Expanded = TLI.expandFMINNUM_FMAXNUM(
Node, DAG))
3548 if (
SDValue Expanded = TLI.expandFMINIMUM_FMAXIMUM(
Node, DAG))
3554 Results.push_back(TLI.expandFMINIMUMNUM_FMAXIMUMNUM(
Node, DAG));
3559 EVT VT =
Node->getValueType(0);
3565 SDVTList VTs = DAG.getVTList(VT, VT);
3575 EVT VT =
Node->getValueType(0);
3579 if (TLI.getLibcallName(LC))
3585 Results.push_back(Expanded.getValue(1));
3594 if (TLI.getLibcallName(LC))
3599 Results.push_back(Expanded.getValue(1));
3606 EVT VT =
Node->getValueType(0);
3618 if (
Node->getValueType(0) != MVT::f32) {
3630 if (
Node->getValueType(0) != MVT::f32) {
3635 {Node->getOperand(0), Node->getOperand(1)});
3637 {
Node->getValueType(0), MVT::Other},
3645 if (!TLI.useSoftFloat() &&
TM.Options.UnsafeFPMath) {
3647 MVT SVT =
Op.getSimpleValueType();
3648 if ((SVT == MVT::f64 || SVT == MVT::f80) &&
3654 DAG.getIntPtrConstant(0, dl,
true));
3665 DAG.shouldOptForSize()))
3666 Results.push_back(ExpandConstantFP(CFP,
true));
3671 Results.push_back(ExpandConstant(CP));
3675 EVT VT =
Node->getValueType(0);
3676 if (TLI.isOperationLegalOrCustom(
ISD::FADD, VT) &&
3677 TLI.isOperationLegalOrCustom(
ISD::FNEG, VT)) {
3686 EVT VT =
Node->getValueType(0);
3688 TLI.isOperationLegalOrCustom(
ISD::XOR, VT) &&
3689 "Don't know how to expand this subtraction!");
3690 Tmp1 = DAG.getNOT(dl,
Node->getOperand(1), VT);
3691 Tmp1 = DAG.
getNode(
ISD::ADD, dl, VT, Tmp1, DAG.getConstant(1, dl, VT));
3697 if (TLI.expandREM(
Node, Tmp1, DAG))
3704 EVT VT =
Node->getValueType(0);
3705 if (TLI.isOperationLegalOrCustom(DivRemOpc, VT)) {
3706 SDVTList VTs = DAG.getVTList(VT, VT);
3707 Tmp1 = DAG.
getNode(DivRemOpc, dl, VTs,
Node->getOperand(0),
3708 Node->getOperand(1));
3715 unsigned ExpandOpcode =
3717 EVT VT =
Node->getValueType(0);
3718 SDVTList VTs = DAG.getVTList(VT, VT);
3720 Tmp1 = DAG.
getNode(ExpandOpcode, dl, VTs,
Node->getOperand(0),
3721 Node->getOperand(1));
3729 MVT VT =
LHS.getSimpleValueType();
3730 unsigned MULHOpcode =
3733 if (TLI.isOperationLegalOrCustom(MULHOpcode, VT)) {
3735 Results.push_back(DAG.getNode(MULHOpcode, dl, VT, LHS, RHS));
3741 assert(TLI.isTypeLegal(HalfType));
3742 if (TLI.expandMUL_LOHI(
Node->getOpcode(), VT, dl, LHS, RHS, Halves,
3744 TargetLowering::MulExpansionKind::Always)) {
3745 for (
unsigned i = 0; i < 2; ++i) {
3748 SDValue Shift = DAG.getConstant(
3750 TLI.getShiftAmountTy(HalfType, DAG.getDataLayout()));
3759 EVT VT =
Node->getValueType(0);
3760 SDVTList VTs = DAG.getVTList(VT, VT);
3766 bool HasSMUL_LOHI = TLI.isOperationLegalOrCustom(
ISD::SMUL_LOHI, VT);
3767 bool HasUMUL_LOHI = TLI.isOperationLegalOrCustom(
ISD::UMUL_LOHI, VT);
3768 bool HasMULHS = TLI.isOperationLegalOrCustom(
ISD::MULHS, VT);
3769 bool HasMULHU = TLI.isOperationLegalOrCustom(
ISD::MULHU, VT);
3770 unsigned OpToUse = 0;
3771 if (HasSMUL_LOHI && !HasMULHS) {
3773 }
else if (HasUMUL_LOHI && !HasMULHU) {
3775 }
else if (HasSMUL_LOHI) {
3777 }
else if (HasUMUL_LOHI) {
3781 Results.push_back(DAG.getNode(OpToUse, dl, VTs,
Node->getOperand(0),
3782 Node->getOperand(1)));
3790 TLI.isOperationLegalOrCustom(
ISD::SHL, VT) &&
3791 TLI.isOperationLegalOrCustom(
ISD::OR, VT) &&
3792 TLI.expandMUL(
Node,
Lo,
Hi, HalfType, DAG,
3793 TargetLowering::MulExpansionKind::OnlyLegalOrCustom)) {
3798 TLI.getShiftAmountTy(HalfType, DAG.getDataLayout()));
3806 if (
SDValue Expanded = TLI.expandFunnelShift(
Node, DAG))
3811 if (
SDValue Expanded = TLI.expandROT(
Node,
true , DAG))
3818 Results.push_back(TLI.expandAddSubSat(
Node, DAG));
3832 Results.push_back(TLI.expandFixedPointMul(
Node, DAG));
3839 Node->getOperand(0),
3840 Node->getOperand(1),
3841 Node->getConstantOperandVal(2),
3864 EVT VT =
LHS.getValueType();
3868 EVT CarryType =
Node->getValueType(1);
3869 EVT SetCCType = getSetCCResultType(
Node->getValueType(0));
3871 SDValue Overflow = DAG.getSetCC(dl, SetCCType, Sum, LHS,
CC);
3874 SDValue One = DAG.getConstant(1, dl, VT);
3876 DAG.
getNode(
ISD::AND, dl, VT, DAG.getZExtOrTrunc(Carry, dl, VT), One);
3885 IsAdd ? DAG.getSetCC(dl, SetCCType, Sum2, Zero,
ISD::SETEQ)
3886 : DAG.getSetCC(dl, SetCCType, Sum, Zero,
ISD::SETEQ);
3888 DAG.getZExtOrTrunc(Carry, dl, SetCCType));
3894 Results.push_back(DAG.getBoolExtOrTrunc(ResultCarry, dl, CarryType, VT));
3900 TLI.expandSADDSUBO(
Node, Result, Overflow, DAG);
3908 TLI.expandUADDSUBO(
Node, Result, Overflow, DAG);
3916 if (TLI.expandMULO(
Node, Result, Overflow, DAG)) {
3928 DAG.getConstant(
PairTy.getSizeInBits() / 2, dl,
3929 TLI.getShiftAmountTy(
PairTy, DAG.getDataLayout())));
3934 Tmp1 =
Node->getOperand(0);
3935 Tmp2 =
Node->getOperand(1);
3936 Tmp3 =
Node->getOperand(2);
3940 cast<CondCodeSDNode>(Tmp1.
getOperand(2))->get());
3942 Tmp1 = DAG.getSelectCC(dl, Tmp1,
3953 int JTI = cast<JumpTableSDNode>(Table.
getNode())->getIndex();
3956 EVT PTy = TLI.getPointerTy(TD);
3958 unsigned EntrySize =
3959 DAG.getMachineFunction().getJumpTableInfo()->getEntrySize(TD);
3966 Index = DAG.getNode(
3971 DAG.getConstant(EntrySize, dl,
Index.getValueType()));
3980 if (TLI.isJumpTableRelative()) {
3985 TLI.getPICJumpTableRelocBase(Table, DAG));
3988 Tmp1 = TLI.expandIndirectJTBranch(dl,
LD.getValue(1),
Addr, JTI, DAG);
3995 Tmp1 =
Node->getOperand(0);
3996 Tmp2 =
Node->getOperand(1);
4002 Node->getOperand(2));
4014 Node->getOperand(2));
4022 bool IsVP =
Node->getOpcode() == ISD::VP_SETCC;
4027 unsigned Offset = IsStrict ? 1 : 0;
4036 bool Legalized = TLI.LegalizeSetCCCondCode(
4037 DAG,
Node->getValueType(0), Tmp1, Tmp2, Tmp3, Mask, EVL, NeedInvert, dl,
4038 Chain, IsSignaling);
4046 {Chain, Tmp1, Tmp2, Tmp3},
Node->getFlags());
4050 {Tmp1, Tmp2, Tmp3, Mask, EVL},
Node->getFlags());
4052 Tmp1 = DAG.
getNode(
Node->getOpcode(), dl,
Node->getValueType(0), Tmp1,
4053 Tmp2, Tmp3,
Node->getFlags());
4061 Tmp1 = DAG.getLogicalNOT(dl, Tmp1, Tmp1->
getValueType(0));
4064 DAG.getVPLogicalNOT(dl, Tmp1, Mask, EVL, Tmp1->
getValueType(0));
4076 assert(!IsStrict &&
"Don't know how to expand for strict nodes.");
4081 EVT VT =
Node->getValueType(0);
4084 DAG.getBoolConstant(
true, dl, VT, Tmp1VT),
4085 DAG.getBoolConstant(
false, dl, VT, Tmp1VT), Tmp3);
4092 Tmp1 =
Node->getOperand(0);
4093 Tmp2 =
Node->getOperand(1);
4094 Tmp3 =
Node->getOperand(2);
4095 Tmp4 =
Node->getOperand(3);
4096 EVT VT =
Node->getValueType(0);
4106 "Cannot expand ISD::SELECT_CC when ISD::SELECT also needs to be "
4108 EVT CCVT = getSetCCResultType(CmpVT);
4111 DAG.getSelect(dl, VT,
Cond, Tmp3, Tmp4,
Node->getFlags()));
4116 bool Legalized =
false;
4124 Tmp1 = DAG.getSelectCC(dl, Tmp1, Tmp2, Tmp4, Tmp3, InvCC);
4134 Tmp1 = DAG.getSelectCC(dl, Tmp2, Tmp1, Tmp4, Tmp3, SwapInvCC);
4140 Legalized = TLI.LegalizeSetCCCondCode(
4144 assert(Legalized &&
"Can't legalize SELECT_CC with legal condition!");
4155 Tmp1, Tmp2, Tmp3, Tmp4,
CC);
4160 Tmp2, Tmp3, Tmp4,
CC);
4170 Tmp1 =
Node->getOperand(0);
4171 Tmp2 =
Node->getOperand(2);
4172 Tmp3 =
Node->getOperand(3);
4173 Tmp4 =
Node->getOperand(1);
4175 bool Legalized = TLI.LegalizeSetCCCondCode(
4176 DAG, getSetCCResultType(Tmp2.
getValueType()), Tmp2, Tmp3, Tmp4,
4179 assert(Legalized &&
"Can't legalize BR_CC with legal condition!");
4184 assert(!NeedInvert &&
"Don't know how to invert BR_CC!");
4187 Tmp4, Tmp2, Tmp3,
Node->getOperand(4));
4192 Tmp2, Tmp3,
Node->getOperand(4));
4207 EVT VT =
Node->getValueType(0);
4213 for (
unsigned Idx = 0;
Idx < NumElem;
Idx++) {
4216 Node->getOperand(0), DAG.getVectorIdxConstant(
Idx, dl));
4219 Node->getOperand(1), DAG.getVectorIdxConstant(
Idx, dl));
4243 Results.push_back(TLI.expandVecReduce(
Node, DAG));
4245 case ISD::VP_CTTZ_ELTS:
4246 case ISD::VP_CTTZ_ELTS_ZERO_UNDEF:
4247 Results.push_back(TLI.expandVPCTTZElements(
Node, DAG));
4258 EVT ResVT =
Node->getValueType(0);
4282 if (!TLI.isStrictFPEnabled() &&
Results.
empty() &&
Node->isStrictFPOpcode()) {
4288 switch (
Node->getOpcode()) {
4290 if (TLI.getStrictFPOperationAction(
Node->getOpcode(),
4291 Node->getValueType(0))
4292 == TargetLowering::Legal)
4296 if (TLI.getStrictFPOperationAction(
4299 if (TLI.getStrictFPOperationAction(
4303 EVT VT =
Node->getValueType(0);
4307 {Node->getOperand(0), Node->getOperand(1), Neg},
4322 if (TLI.getStrictFPOperationAction(
Node->getOpcode(),
4323 Node->getOperand(1).getValueType())
4324 == TargetLowering::Legal)
4341void SelectionDAGLegalize::ConvertNodeToLibcall(
SDNode *
Node) {
4346 unsigned Opc =
Node->getOpcode();
4355 .setChain(
Node->getOperand(0))
4358 DAG.getExternalSymbol(
"__sync_synchronize",
4359 TLI.getPointerTy(DAG.getDataLayout())),
4362 std::pair<SDValue, SDValue> CallResult = TLI.LowerCallTo(CLI);
4364 Results.push_back(CallResult.second);
4386 EVT RetVT =
Node->getValueType(0);
4389 if (TLI.getLibcallName(LC)) {
4396 assert(LC != RTLIB::UNKNOWN_LIBCALL &&
4397 "Unexpected atomic op or value type!");
4401 std::pair<SDValue, SDValue> Tmp = TLI.makeLibCall(DAG, LC, RetVT,
4404 Node->getOperand(0));
4406 Results.push_back(Tmp.second);
4414 .setChain(
Node->getOperand(0))
4416 DAG.getExternalSymbol(
4417 "abort", TLI.getPointerTy(DAG.getDataLayout())),
4419 std::pair<SDValue, SDValue> CallResult = TLI.LowerCallTo(CLI);
4421 Results.push_back(CallResult.second);
4429 std::pair<SDValue, SDValue> Tmp = TLI.makeLibCall(
4430 DAG, RTLIB::CLEAR_CACHE, MVT::isVoid, {StartVal, EndVal}, CallOptions,
4432 Results.push_back(Tmp.second);
4437 ExpandFPLibCall(
Node, RTLIB::FMIN_F32, RTLIB::FMIN_F64,
4438 RTLIB::FMIN_F80, RTLIB::FMIN_F128,
4439 RTLIB::FMIN_PPCF128,
Results);
4446 ExpandFPLibCall(
Node, RTLIB::FMAX_F32, RTLIB::FMAX_F64,
4447 RTLIB::FMAX_F80, RTLIB::FMAX_F128,
4448 RTLIB::FMAX_PPCF128,
Results);
4451 ExpandFPLibCall(
Node, RTLIB::FMINIMUMNUM_F32, RTLIB::FMINIMUMNUM_F64,
4452 RTLIB::FMINIMUMNUM_F80, RTLIB::FMINIMUMNUM_F128,
4453 RTLIB::FMINIMUMNUM_PPCF128,
Results);
4456 ExpandFPLibCall(
Node, RTLIB::FMAXIMUMNUM_F32, RTLIB::FMAXIMUMNUM_F64,
4457 RTLIB::FMAXIMUMNUM_F80, RTLIB::FMAXIMUMNUM_F128,
4458 RTLIB::FMAXIMUMNUM_PPCF128,
Results);
4462 ExpandFPLibCall(
Node, RTLIB::SQRT_F32, RTLIB::SQRT_F64,
4463 RTLIB::SQRT_F80, RTLIB::SQRT_F128,
4464 RTLIB::SQRT_PPCF128,
Results);
4467 ExpandFPLibCall(
Node, RTLIB::CBRT_F32, RTLIB::CBRT_F64,
4468 RTLIB::CBRT_F80, RTLIB::CBRT_F128,
4469 RTLIB::CBRT_PPCF128,
Results);
4473 ExpandFPLibCall(
Node, RTLIB::SIN_F32, RTLIB::SIN_F64,
4474 RTLIB::SIN_F80, RTLIB::SIN_F128,
4479 ExpandFPLibCall(
Node, RTLIB::COS_F32, RTLIB::COS_F64,
4480 RTLIB::COS_F80, RTLIB::COS_F128,
4485 ExpandFPLibCall(
Node, RTLIB::TAN_F32, RTLIB::TAN_F64, RTLIB::TAN_F80,
4486 RTLIB::TAN_F128, RTLIB::TAN_PPCF128,
Results);
4490 ExpandFPLibCall(
Node, RTLIB::ASIN_F32, RTLIB::ASIN_F64, RTLIB::ASIN_F80,
4491 RTLIB::ASIN_F128, RTLIB::ASIN_PPCF128,
Results);
4495 ExpandFPLibCall(
Node, RTLIB::ACOS_F32, RTLIB::ACOS_F64, RTLIB::ACOS_F80,
4496 RTLIB::ACOS_F128, RTLIB::ACOS_PPCF128,
Results);
4500 ExpandFPLibCall(
Node, RTLIB::ATAN_F32, RTLIB::ATAN_F64, RTLIB::ATAN_F80,
4501 RTLIB::ATAN_F128, RTLIB::ATAN_PPCF128,
Results);
4505 ExpandFPLibCall(
Node, RTLIB::ATAN2_F32, RTLIB::ATAN2_F64, RTLIB::ATAN2_F80,
4506 RTLIB::ATAN2_F128, RTLIB::ATAN2_PPCF128,
Results);
4510 ExpandFPLibCall(
Node, RTLIB::SINH_F32, RTLIB::SINH_F64, RTLIB::SINH_F80,
4511 RTLIB::SINH_F128, RTLIB::SINH_PPCF128,
Results);
4515 ExpandFPLibCall(
Node, RTLIB::COSH_F32, RTLIB::COSH_F64, RTLIB::COSH_F80,
4516 RTLIB::COSH_F128, RTLIB::COSH_PPCF128,
Results);
4520 ExpandFPLibCall(
Node, RTLIB::TANH_F32, RTLIB::TANH_F64, RTLIB::TANH_F80,
4521 RTLIB::TANH_F128, RTLIB::TANH_PPCF128,
Results);
4525 bool Expanded = DAG.expandMultipleResultFPLibCall(LC,
Node,
Results);
4532 ExpandFPLibCall(
Node, RTLIB::LOG_F32, RTLIB::LOG_F64, RTLIB::LOG_F80,
4533 RTLIB::LOG_F128, RTLIB::LOG_PPCF128,
Results);
4537 ExpandFPLibCall(
Node, RTLIB::LOG2_F32, RTLIB::LOG2_F64, RTLIB::LOG2_F80,
4538 RTLIB::LOG2_F128, RTLIB::LOG2_PPCF128,
Results);
4542 ExpandFPLibCall(
Node, RTLIB::LOG10_F32, RTLIB::LOG10_F64, RTLIB::LOG10_F80,
4543 RTLIB::LOG10_F128, RTLIB::LOG10_PPCF128,
Results);
4547 ExpandFPLibCall(
Node, RTLIB::EXP_F32, RTLIB::EXP_F64, RTLIB::EXP_F80,
4548 RTLIB::EXP_F128, RTLIB::EXP_PPCF128,
Results);
4552 ExpandFPLibCall(
Node, RTLIB::EXP2_F32, RTLIB::EXP2_F64, RTLIB::EXP2_F80,
4553 RTLIB::EXP2_F128, RTLIB::EXP2_PPCF128,
Results);
4556 ExpandFPLibCall(
Node, RTLIB::EXP10_F32, RTLIB::EXP10_F64, RTLIB::EXP10_F80,
4557 RTLIB::EXP10_F128, RTLIB::EXP10_PPCF128,
Results);
4561 ExpandFPLibCall(
Node, RTLIB::TRUNC_F32, RTLIB::TRUNC_F64,
4562 RTLIB::TRUNC_F80, RTLIB::TRUNC_F128,
4563 RTLIB::TRUNC_PPCF128,
Results);
4567 ExpandFPLibCall(
Node, RTLIB::FLOOR_F32, RTLIB::FLOOR_F64,
4568 RTLIB::FLOOR_F80, RTLIB::FLOOR_F128,
4569 RTLIB::FLOOR_PPCF128,
Results);
4573 ExpandFPLibCall(
Node, RTLIB::CEIL_F32, RTLIB::CEIL_F64,
4574 RTLIB::CEIL_F80, RTLIB::CEIL_F128,
4575 RTLIB::CEIL_PPCF128,
Results);
4579 ExpandFPLibCall(
Node, RTLIB::RINT_F32, RTLIB::RINT_F64,
4580 RTLIB::RINT_F80, RTLIB::RINT_F128,
4581 RTLIB::RINT_PPCF128,
Results);
4585 ExpandFPLibCall(
Node, RTLIB::NEARBYINT_F32,
4586 RTLIB::NEARBYINT_F64,
4587 RTLIB::NEARBYINT_F80,
4588 RTLIB::NEARBYINT_F128,
4589 RTLIB::NEARBYINT_PPCF128,
Results);
4593 ExpandFPLibCall(
Node, RTLIB::ROUND_F32,
4597 RTLIB::ROUND_PPCF128,
Results);
4601 ExpandFPLibCall(
Node, RTLIB::ROUNDEVEN_F32,
4602 RTLIB::ROUNDEVEN_F64,
4603 RTLIB::ROUNDEVEN_F80,
4604 RTLIB::ROUNDEVEN_F128,
4605 RTLIB::ROUNDEVEN_PPCF128,
Results);
4609 ExpandFPLibCall(
Node, RTLIB::LDEXP_F32, RTLIB::LDEXP_F64, RTLIB::LDEXP_F80,
4610 RTLIB::LDEXP_F128, RTLIB::LDEXP_PPCF128,
Results);
4614 bool Expanded = DAG.expandMultipleResultFPLibCall(LC,
Node,
Results,
4623 assert(LC != RTLIB::UNKNOWN_LIBCALL &&
"Unexpected fpowi.");
4624 if (!TLI.getLibcallName(LC)) {
4626 if (
Node->isStrictFPOpcode()) {
4629 {
Node->getValueType(0),
Node->getValueType(1)},