56#define DEBUG_TYPE "legalizedag"
62struct FloatSignAsInt {
85class SelectionDAGLegalize {
97 EVT getSetCCResultType(
EVT VT)
const {
108 LegalizedNodes(LegalizedNodes), UpdatedNodes(UpdatedNodes) {}
168 void getSignAsIntValue(FloatSignAsInt &State,
const SDLoc &
DL,
170 SDValue modifySignAsInt(
const FloatSignAsInt &State,
const SDLoc &
DL,
209 dbgs() <<
" with: "; New->dump(&DAG));
212 "Replacing one node with another that produces a different number "
216 UpdatedNodes->
insert(New);
222 dbgs() <<
" with: "; New->dump(&DAG));
226 UpdatedNodes->
insert(New.getNode());
227 ReplacedNode(Old.getNode());
234 for (
unsigned i = 0, e = Old->
getNumValues(); i != e; ++i) {
238 UpdatedNodes->
insert(New[i].getNode());
245 dbgs() <<
" with: "; New->dump(&DAG));
249 UpdatedNodes->
insert(New.getNode());
250 ReplacedNode(Old.getNode());
260SDValue SelectionDAGLegalize::ShuffleWithNarrowerEltType(
265 unsigned NumEltsGrowth = NumDestElts / NumMaskElts;
267 assert(NumEltsGrowth &&
"Cannot promote to vector type with fewer elts!");
269 if (NumEltsGrowth == 1)
270 return DAG.getVectorShuffle(NVT, dl, N1, N2, Mask);
273 for (
unsigned i = 0; i != NumMaskElts; ++i) {
275 for (
unsigned j = 0;
j != NumEltsGrowth; ++
j) {
282 assert(NewMask.
size() == NumDestElts &&
"Non-integer NumEltsGrowth?");
283 assert(TLI.isShuffleMaskLegal(NewMask, NVT) &&
"Shuffle not legal?");
284 return DAG.getVectorShuffle(NVT, dl, N1, N2, NewMask);
303 assert((VT == MVT::f64 || VT == MVT::f32) &&
"Invalid type expansion");
305 (VT == MVT::f64) ? MVT::i64 : MVT::i32);
315 while (SVT != MVT::f32 && SVT != MVT::f16 && SVT != MVT::bf16) {
321 TLI.ShouldShrinkFPConstant(OrigVT)) {
331 DAG.getConstantPool(LLVMC, TLI.getPointerTy(DAG.getDataLayout()));
332 Align Alignment = cast<ConstantPoolSDNode>(CPIdx)->getAlign();
341 OrigVT, dl, DAG.getEntryNode(), CPIdx,
349 EVT VT =
CP->getValueType(0);
350 SDValue CPIdx = DAG.getConstantPool(
CP->getConstantIntValue(),
351 TLI.getPointerTy(DAG.getDataLayout()));
352 Align Alignment = cast<ConstantPoolSDNode>(CPIdx)->getAlign();
354 VT, dl, DAG.getEntryNode(), CPIdx,
363SDValue SelectionDAGLegalize::PerformInsertVectorEltInMemory(
SDValue Vec,
381 int SPFI = cast<FrameIndexSDNode>(
StackPtr.getNode())->getIndex();
385 DAG.getEntryNode(), dl, Tmp1, StackPtr,
388 SDValue StackPtr2 = TLI.getVectorElementPointer(DAG, StackPtr, VT, Tmp3);
391 Ch = DAG.getTruncStore(
392 Ch, dl, Tmp2, StackPtr2,
396 DAG.getMachineFunction(), SPFI));
417 for (
unsigned i = 0; i != NumElts; ++i)
418 ShufOps.
push_back(i != InsertPos->getZExtValue() ? i : NumElts);
420 return DAG.getVectorShuffle(Vec.
getValueType(), dl, Vec, ScVec, ShufOps);
423 return PerformInsertVectorEltInMemory(Vec, Val,
Idx, dl);
450 TLI.isTypeLegal(MVT::i32)) {
452 bitcastToAPInt().zextOrTrunc(32),
453 SDLoc(CFP), MVT::i32);
454 return DAG.getStore(Chain, dl, Con,
Ptr,
ST->getPointerInfo(),
455 ST->getOriginalAlign(), MMOFlags, AAInfo);
460 if (TLI.isTypeLegal(MVT::i64)) {
462 zextOrTrunc(64),
SDLoc(CFP), MVT::i64);
463 return DAG.getStore(Chain, dl, Con,
Ptr,
ST->getPointerInfo(),
464 ST->getOriginalAlign(), MMOFlags, AAInfo);
467 if (TLI.isTypeLegal(MVT::i32) && !
ST->isVolatile()) {
474 if (DAG.getDataLayout().isBigEndian())
477 Lo = DAG.getStore(Chain, dl,
Lo,
Ptr,
ST->getPointerInfo(),
478 ST->getOriginalAlign(), MMOFlags, AAInfo);
480 Hi = DAG.getStore(Chain, dl,
Hi,
Ptr,
481 ST->getPointerInfo().getWithOffset(4),
482 ST->getOriginalAlign(), MMOFlags, AAInfo);
491void SelectionDAGLegalize::LegalizeStoreOps(
SDNode *
Node) {
500 if (!
ST->isTruncatingStore()) {
502 if (
SDNode *OptStore = OptimizeFloatStore(ST).getNode()) {
503 ReplaceNode(ST, OptStore);
508 MVT VT =
Value.getSimpleValueType();
509 switch (TLI.getOperationAction(
ISD::STORE, VT)) {
511 case TargetLowering::Legal: {
514 EVT MemVT =
ST->getMemoryVT();
516 if (!TLI.allowsMemoryAccessForAlignment(*DAG.getContext(),
DL, MemVT,
517 *
ST->getMemOperand())) {
520 ReplaceNode(
SDValue(ST, 0), Result);
525 case TargetLowering::Custom: {
532 case TargetLowering::Promote: {
535 "Can only promote stores to same size type");
538 ST->getOriginalAlign(), MMOFlags, AAInfo);
548 EVT StVT =
ST->getMemoryVT();
551 auto &
DL = DAG.getDataLayout();
553 if (StWidth != StSize) {
558 Value = DAG.getZeroExtendInReg(
Value, dl, StVT);
560 DAG.getTruncStore(Chain, dl,
Value,
Ptr,
ST->getPointerInfo(), NVT,
561 ST->getOriginalAlign(), MMOFlags, AAInfo);
567 unsigned LogStWidth =
Log2_32(StWidthBits);
569 unsigned RoundWidth = 1 << LogStWidth;
570 assert(RoundWidth < StWidthBits);
571 unsigned ExtraWidth = StWidthBits - RoundWidth;
572 assert(ExtraWidth < RoundWidth);
573 assert(!(RoundWidth % 8) && !(ExtraWidth % 8) &&
574 "Store size not an integral number of bytes!");
578 unsigned IncrementSize;
580 if (
DL.isLittleEndian()) {
583 Lo = DAG.getTruncStore(Chain, dl,
Value,
Ptr,
ST->getPointerInfo(),
584 RoundVT,
ST->getOriginalAlign(), MMOFlags, AAInfo);
587 IncrementSize = RoundWidth / 8;
591 DAG.getConstant(RoundWidth, dl,
592 TLI.getShiftAmountTy(
Value.getValueType(),
DL)));
593 Hi = DAG.getTruncStore(Chain, dl,
Hi,
Ptr,
594 ST->getPointerInfo().getWithOffset(IncrementSize),
595 ExtraVT,
ST->getOriginalAlign(), MMOFlags, AAInfo);
602 DAG.getConstant(ExtraWidth, dl,
603 TLI.getShiftAmountTy(
Value.getValueType(),
DL)));
604 Hi = DAG.getTruncStore(Chain, dl,
Hi,
Ptr,
ST->getPointerInfo(), RoundVT,
605 ST->getOriginalAlign(), MMOFlags, AAInfo);
608 IncrementSize = RoundWidth / 8;
610 DAG.getConstant(IncrementSize, dl,
611 Ptr.getValueType()));
613 ST->getPointerInfo().getWithOffset(IncrementSize),
614 ExtraVT,
ST->getOriginalAlign(), MMOFlags, AAInfo);
621 switch (TLI.getTruncStoreAction(
ST->getValue().getValueType(), StVT)) {
623 case TargetLowering::Legal: {
624 EVT MemVT =
ST->getMemoryVT();
627 if (!TLI.allowsMemoryAccessForAlignment(*DAG.getContext(),
DL, MemVT,
628 *
ST->getMemOperand())) {
630 ReplaceNode(
SDValue(ST, 0), Result);
634 case TargetLowering::Custom: {
640 case TargetLowering::Expand:
642 "Vector Stores are handled in LegalizeVectorOps");
647 if (TLI.isTypeLegal(StVT)) {
650 ST->getOriginalAlign(), MMOFlags, AAInfo);
655 TLI.getTypeToTransformTo(*DAG.getContext(), StVT),
658 DAG.getTruncStore(Chain, dl,
Value,
Ptr,
ST->getPointerInfo(), StVT,
659 ST->getOriginalAlign(), MMOFlags, AAInfo);
668void SelectionDAGLegalize::LegalizeLoadOps(
SDNode *
Node) {
677 LLVM_DEBUG(
dbgs() <<
"Legalizing non-extending load operation\n");
678 MVT VT =
Node->getSimpleValueType(0);
682 switch (TLI.getOperationAction(
Node->getOpcode(), VT)) {
684 case TargetLowering::Legal: {
685 EVT MemVT =
LD->getMemoryVT();
689 if (!TLI.allowsMemoryAccessForAlignment(*DAG.getContext(),
DL, MemVT,
690 *
LD->getMemOperand())) {
691 std::tie(RVal, RChain) = TLI.expandUnalignedLoad(LD, DAG);
695 case TargetLowering::Custom:
696 if (
SDValue Res = TLI.LowerOperation(RVal, DAG)) {
702 case TargetLowering::Promote: {
703 MVT NVT = TLI.getTypeToPromoteTo(
Node->getOpcode(), VT);
705 "Can only promote loads to same size type");
707 SDValue Res = DAG.getLoad(NVT, dl, Chain,
Ptr,
LD->getMemOperand());
715 DAG.ReplaceAllUsesOfValueWith(
SDValue(
Node, 0), RVal);
716 DAG.ReplaceAllUsesOfValueWith(
SDValue(
Node, 1), RChain);
718 UpdatedNodes->insert(RVal.
getNode());
719 UpdatedNodes->insert(RChain.
getNode());
727 EVT SrcVT =
LD->getMemoryVT();
741 TLI.getLoadExtAction(ExtType,
Node->getValueType(0), MVT::i1) ==
742 TargetLowering::Promote)) {
756 Chain,
Ptr,
LD->getPointerInfo(), NVT,
757 LD->getOriginalAlign(), MMOFlags, AAInfo);
765 Result, DAG.getValueType(SrcVT));
769 Result.getValueType(), Result,
770 DAG.getValueType(SrcVT));
778 unsigned LogSrcWidth =
Log2_32(SrcWidthBits);
780 unsigned RoundWidth = 1 << LogSrcWidth;
781 assert(RoundWidth < SrcWidthBits);
782 unsigned ExtraWidth = SrcWidthBits - RoundWidth;
783 assert(ExtraWidth < RoundWidth);
784 assert(!(RoundWidth % 8) && !(ExtraWidth % 8) &&
785 "Load size not an integral number of bytes!");
789 unsigned IncrementSize;
790 auto &
DL = DAG.getDataLayout();
792 if (
DL.isLittleEndian()) {
796 LD->getPointerInfo(), RoundVT,
LD->getOriginalAlign(),
800 IncrementSize = RoundWidth / 8;
802 Hi = DAG.getExtLoad(ExtType, dl,
Node->getValueType(0), Chain,
Ptr,
803 LD->getPointerInfo().getWithOffset(IncrementSize),
804 ExtraVT,
LD->getOriginalAlign(), MMOFlags, AAInfo);
814 DAG.getConstant(RoundWidth, dl,
815 TLI.getShiftAmountTy(
Hi.getValueType(),
DL)));
823 Hi = DAG.getExtLoad(ExtType, dl,
Node->getValueType(0), Chain,
Ptr,
824 LD->getPointerInfo(), RoundVT,
LD->getOriginalAlign(),
828 IncrementSize = RoundWidth / 8;
831 LD->getPointerInfo().getWithOffset(IncrementSize),
832 ExtraVT,
LD->getOriginalAlign(), MMOFlags, AAInfo);
842 DAG.getConstant(ExtraWidth, dl,
843 TLI.getShiftAmountTy(
Hi.getValueType(),
DL)));
851 bool isCustom =
false;
852 switch (TLI.getLoadExtAction(ExtType,
Node->getValueType(0),
855 case TargetLowering::Custom:
858 case TargetLowering::Legal:
870 EVT MemVT =
LD->getMemoryVT();
872 if (!TLI.allowsMemoryAccess(*DAG.getContext(),
DL, MemVT,
873 *
LD->getMemOperand())) {
874 std::tie(
Value, Chain) = TLI.expandUnalignedLoad(LD, DAG);
879 case TargetLowering::Expand: {
880 EVT DestVT =
Node->getValueType(0);
885 if (TLI.isTypeLegal(SrcVT) ||
886 TLI.isLoadExtLegal(ExtType, LoadVT, SrcVT)) {
893 SrcVT,
LD->getMemOperand());
896 Value = DAG.getNode(ExtendOp, dl,
Node->getValueType(0), Load);
897 Chain =
Load.getValue(1);
911 Ptr, ISrcVT,
LD->getMemOperand());
913 Chain =
Result.getValue(1);
919 "Vector Loads are handled in LegalizeVectorOps");
926 "EXTLOAD should always be supported!");
930 Node->getValueType(0),
932 LD->getMemOperand());
937 Result, DAG.getValueType(SrcVT));
939 ValRes = DAG.getZeroExtendInReg(Result, dl, SrcVT);
941 Chain =
Result.getValue(1);
952 DAG.ReplaceAllUsesOfValueWith(
SDValue(
Node, 1), Chain);
954 UpdatedNodes->insert(
Value.getNode());
955 UpdatedNodes->insert(Chain.
getNode());
962void SelectionDAGLegalize::LegalizeOp(
SDNode *
Node) {
971 for (
unsigned i = 0, e =
Node->getNumValues(); i != e; ++i)
972 assert(TLI.getTypeAction(*DAG.getContext(),
Node->getValueType(i)) ==
973 TargetLowering::TypeLegal &&
974 "Unexpected illegal type!");
977 assert((TLI.getTypeAction(*DAG.getContext(),
Op.getValueType()) ==
978 TargetLowering::TypeLegal ||
981 "Unexpected illegal type!");
986 bool SimpleFinishLegalizing =
true;
987 switch (
Node->getOpcode()) {
992 Action = TLI.getOperationAction(
Node->getOpcode(), MVT::Other);
995 Action = TLI.getOperationAction(
Node->getOpcode(),
996 Node->getValueType(0));
999 Action = TLI.getOperationAction(
Node->getOpcode(),
1000 Node->getValueType(0));
1001 if (Action != TargetLowering::Promote)
1002 Action = TLI.getOperationAction(
Node->getOpcode(), MVT::Other);
1005 Action = TLI.getOperationAction(
Node->getOpcode(),
1006 Node->getOperand(1).getValueType());
1017 Action = TLI.getOperationAction(
Node->getOpcode(),
1018 Node->getOperand(0).getValueType());
1030 Action = TLI.getOperationAction(
Node->getOpcode(),
1031 Node->getOperand(1).getValueType());
1034 EVT InnerType = cast<VTSDNode>(
Node->getOperand(1))->getVT();
1035 Action = TLI.getOperationAction(
Node->getOpcode(), InnerType);
1039 Action = TLI.getOperationAction(
Node->getOpcode(),
1040 Node->getOperand(2).getValueType());
1049 unsigned Opc =
Node->getOpcode();
1054 : (Opc ==
ISD::SETCC || Opc == ISD::VP_SETCC) ? 2
1056 unsigned CompareOperand = Opc ==
ISD::BR_CC ? 2
1060 MVT OpVT =
Node->getOperand(CompareOperand).getSimpleValueType();
1062 cast<CondCodeSDNode>(
Node->getOperand(CCOperand))->get();
1063 Action = TLI.getCondCodeAction(CCCode, OpVT);
1064 if (Action == TargetLowering::Legal) {
1066 Action = TLI.getOperationAction(
Node->getOpcode(),
1067 Node->getValueType(0));
1069 Action = TLI.getOperationAction(
Node->getOpcode(), OpVT);
1077 SimpleFinishLegalizing =
false;
1084 SimpleFinishLegalizing =
false;
1097 Action = TLI.getOperationAction(
Node->getOpcode(),
Node->getValueType(0));
1098 if (Action == TargetLowering::Legal)
1099 Action = TargetLowering::Expand;
1109 Action = TLI.getOperationAction(
Node->getOpcode(),
Node->getValueType(0));
1110 if (Action == TargetLowering::Legal)
1111 Action = TargetLowering::Custom;
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));
1157 Action = TLI.getOperationAction(
Node->getOpcode(),
Node->getValueType(0));
1167 unsigned Scale =
Node->getConstantOperandVal(2);
1168 Action = TLI.getFixedPointOperationAction(
Node->getOpcode(),
1169 Node->getValueType(0), Scale);
1173 Action = TLI.getOperationAction(
Node->getOpcode(),
1174 cast<MaskedScatterSDNode>(
Node)->getValue().getValueType());
1177 Action = TLI.getOperationAction(
Node->getOpcode(),
1178 cast<MaskedStoreSDNode>(
Node)->getValue().getValueType());
1180 case ISD::VP_SCATTER:
1181 Action = TLI.getOperationAction(
1183 cast<VPScatterSDNode>(
Node)->getValue().getValueType());
1186 Action = TLI.getOperationAction(
1188 cast<VPStoreSDNode>(
Node)->getValue().getValueType());
1190 case ISD::EXPERIMENTAL_VP_STRIDED_STORE:
1191 Action = TLI.getOperationAction(
1193 cast<VPStridedStoreSDNode>(
Node)->getValue().getValueType());
1209 Action = TLI.getOperationAction(
1210 Node->getOpcode(),
Node->getOperand(0).getValueType());
1214 case ISD::VP_REDUCE_FADD:
1215 case ISD::VP_REDUCE_FMUL:
1216 case ISD::VP_REDUCE_ADD:
1217 case ISD::VP_REDUCE_MUL:
1218 case ISD::VP_REDUCE_AND:
1219 case ISD::VP_REDUCE_OR:
1220 case ISD::VP_REDUCE_XOR:
1221 case ISD::VP_REDUCE_SMAX:
1222 case ISD::VP_REDUCE_SMIN:
1223 case ISD::VP_REDUCE_UMAX:
1224 case ISD::VP_REDUCE_UMIN:
1225 case ISD::VP_REDUCE_FMAX:
1226 case ISD::VP_REDUCE_FMIN:
1227 case ISD::VP_REDUCE_SEQ_FADD:
1228 case ISD::VP_REDUCE_SEQ_FMUL:
1229 Action = TLI.getOperationAction(
1230 Node->getOpcode(),
Node->getOperand(1).getValueType());
1234 Action = TLI.getCustomOperationAction(*
Node);
1236 Action = TLI.getOperationAction(
Node->getOpcode(),
Node->getValueType(0));
1241 if (SimpleFinishLegalizing) {
1243 switch (
Node->getOpcode()) {
1262 NewNode = DAG.UpdateNodeOperands(
Node, Op0, SAO);
1282 NewNode = DAG.UpdateNodeOperands(
Node, Op0, Op1, SAO);
1288 if (NewNode !=
Node) {
1289 ReplaceNode(
Node, NewNode);
1293 case TargetLowering::Legal:
1296 case TargetLowering::Custom:
1304 if (
Node->getNumValues() == 1) {
1308 Node->getValueType(0) == MVT::Glue) &&
1309 "Type mismatch for custom legalized operation");
1317 for (
unsigned i = 0, e =
Node->getNumValues(); i != e; ++i) {
1321 Node->getValueType(i) == MVT::Glue) &&
1322 "Type mismatch for custom legalized operation");
1326 ReplaceNode(
Node, ResultVals.
data());
1331 case TargetLowering::Expand:
1332 if (ExpandNode(
Node))
1335 case TargetLowering::LibCall:
1336 ConvertNodeToLibcall(
Node);
1338 case TargetLowering::Promote:
1344 switch (
Node->getOpcode()) {
1357 return LegalizeLoadOps(
Node);
1359 return LegalizeStoreOps(
Node);
1363SDValue SelectionDAGLegalize::ExpandExtractFromVectorThroughStack(
SDValue Op) {
1383 if (
ST->isIndexed() ||
ST->isTruncatingStore() ||
1384 ST->getValue() != Vec)
1389 if (!
ST->getChain().reachesChainWithoutSideEffects(DAG.getEntryNode()))
1398 ST->hasPredecessor(
Op.getNode()))
1411 StackPtr = DAG.CreateStackTemporary(VecVT);
1412 Ch = DAG.getStore(DAG.getEntryNode(), dl, Vec, StackPtr,
1417 Align ElementAlignment =
1418 std::min(cast<StoreSDNode>(Ch)->
getAlign(),
1419 DAG.getDataLayout().getPrefTypeAlign(
1420 Op.getValueType().getTypeForEVT(*DAG.getContext())));
1422 if (
Op.getValueType().isVector()) {
1423 StackPtr = TLI.getVectorSubVecPointer(DAG, StackPtr, VecVT,
1424 Op.getValueType(),
Idx);
1425 NewLoad = DAG.getLoad(
Op.getValueType(), dl, Ch, StackPtr,
1428 StackPtr = TLI.getVectorElementPointer(DAG, StackPtr, VecVT,
Idx);
1429 NewLoad = DAG.getExtLoad(
ISD::EXTLOAD, dl,
Op.getValueType(), Ch, StackPtr,
1435 DAG.ReplaceAllUsesOfValueWith(Ch,
SDValue(NewLoad.
getNode(), 1));
1441 NewLoadOperands[0] = Ch;
1443 SDValue(DAG.UpdateNodeOperands(NewLoad.
getNode(), NewLoadOperands), 0);
1447SDValue SelectionDAGLegalize::ExpandInsertToVectorThroughStack(
SDValue Op) {
1448 assert(
Op.getValueType().isVector() &&
"Non-vector insert subvector!");
1459 int FI = cast<FrameIndexSDNode>(
StackPtr.getNode())->getIndex();
1464 SDValue Ch = DAG.getStore(DAG.getEntryNode(), dl, Vec, StackPtr, PtrInfo);
1468 TLI.getVectorSubVecPointer(DAG, StackPtr, VecVT, SubVecVT,
Idx);
1472 Ch, dl, Part, SubStackPtr,
1476 return DAG.getLoad(
Op.getValueType(), dl, Ch, StackPtr, PtrInfo);
1482 "Unexpected opcode!");
1488 EVT VT =
Node->getValueType(0);
1490 :
Node->getOperand(0).getValueType();
1492 SDValue FIPtr = DAG.CreateStackTemporary(VT);
1493 int FI = cast<FrameIndexSDNode>(FIPtr.
getNode())->getIndex();
1500 assert(TypeByteSize > 0 &&
"Vector element type too small for stack store!");
1504 bool Truncate = isa<BuildVectorSDNode>(
Node) &&
1505 MemVT.
bitsLT(
Node->getOperand(0).getValueType());
1508 for (
unsigned i = 0, e =
Node->getNumOperands(); i != e; ++i) {
1510 if (
Node->getOperand(i).isUndef())
continue;
1512 unsigned Offset = TypeByteSize*i;
1517 Stores.
push_back(DAG.getTruncStore(DAG.getEntryNode(), dl,
1521 Stores.
push_back(DAG.getStore(DAG.getEntryNode(), dl,
Node->getOperand(i),
1526 if (!Stores.
empty())
1529 StoreChain = DAG.getEntryNode();
1532 return DAG.getLoad(VT, dl, StoreChain, FIPtr, PtrInfo);
1538void SelectionDAGLegalize::getSignAsIntValue(FloatSignAsInt &State,
1541 EVT FloatVT =
Value.getValueType();
1543 State.FloatVT = FloatVT;
1546 if (TLI.isTypeLegal(IVT)) {
1549 State.SignBit = NumBits - 1;
1555 MVT LoadTy = TLI.getRegisterType(MVT::i8);
1558 int FI = cast<FrameIndexSDNode>(
StackPtr.getNode())->getIndex();
1563 State.Chain = DAG.getStore(DAG.getEntryNode(),
DL,
Value, State.FloatPtr,
1564 State.FloatPointerInfo);
1571 State.IntPointerInfo = State.FloatPointerInfo;
1574 unsigned ByteOffset = (NumBits / 8) - 1;
1581 State.IntPtr = IntPtr;
1582 State.IntValue = DAG.getExtLoad(
ISD::EXTLOAD,
DL, LoadTy, State.Chain, IntPtr,
1583 State.IntPointerInfo, MVT::i8);
1590SDValue SelectionDAGLegalize::modifySignAsInt(
const FloatSignAsInt &State,
1597 SDValue Chain = DAG.getTruncStore(State.Chain,
DL, NewIntValue, State.IntPtr,
1598 State.IntPointerInfo, MVT::i8);
1599 return DAG.getLoad(State.FloatVT,
DL, Chain, State.FloatPtr,
1600 State.FloatPointerInfo);
1609 FloatSignAsInt SignAsInt;
1610 getSignAsIntValue(SignAsInt,
DL, Sign);
1612 EVT IntVT = SignAsInt.IntValue.getValueType();
1613 SDValue SignMask = DAG.getConstant(SignAsInt.SignMask,
DL, IntVT);
1619 if (TLI.isOperationLegalOrCustom(
ISD::FABS, FloatVT) &&
1620 TLI.isOperationLegalOrCustom(
ISD::FNEG, FloatVT)) {
1623 SDValue Cond = DAG.getSetCC(
DL, getSetCCResultType(IntVT), SignBit,
1625 return DAG.getSelect(
DL, FloatVT,
Cond, NegValue, AbsValue);
1629 FloatSignAsInt MagAsInt;
1630 getSignAsIntValue(MagAsInt,
DL, Mag);
1631 EVT MagVT = MagAsInt.IntValue.getValueType();
1632 SDValue ClearSignMask = DAG.getConstant(~MagAsInt.SignMask,
DL, MagVT);
1637 int ShiftAmount = SignAsInt.SignBit - MagAsInt.SignBit;
1638 EVT ShiftVT = IntVT;
1644 if (ShiftAmount > 0) {
1645 SDValue ShiftCnst = DAG.getConstant(ShiftAmount,
DL, ShiftVT);
1647 }
else if (ShiftAmount < 0) {
1648 SDValue ShiftCnst = DAG.getConstant(-ShiftAmount,
DL, ShiftVT);
1658 return modifySignAsInt(MagAsInt,
DL, CopiedSign);
1664 FloatSignAsInt SignAsInt;
1665 getSignAsIntValue(SignAsInt,
DL,
Node->getOperand(0));
1666 EVT IntVT = SignAsInt.IntValue.getValueType();
1669 SDValue SignMask = DAG.getConstant(SignAsInt.SignMask,
DL, IntVT);
1674 return modifySignAsInt(SignAsInt,
DL, SignFlip);
1682 EVT FloatVT =
Value.getValueType();
1689 FloatSignAsInt ValueAsInt;
1690 getSignAsIntValue(ValueAsInt,
DL,
Value);
1691 EVT IntVT = ValueAsInt.IntValue.getValueType();
1692 SDValue ClearSignMask = DAG.getConstant(~ValueAsInt.SignMask,
DL, IntVT);
1695 return modifySignAsInt(ValueAsInt,
DL, ClearedSign);
1698void SelectionDAGLegalize::ExpandDYNAMIC_STACKALLOC(
SDNode*
Node,
1700 Register SPReg = TLI.getStackPointerRegisterToSaveRestore();
1701 assert(SPReg &&
"Target cannot require DYNAMIC_STACKALLOC expansion and"
1702 " not tell us which reg is the stack pointer!");
1704 EVT VT =
Node->getValueType(0);
1712 Chain = DAG.getCALLSEQ_START(Chain, 0, 0, dl);
1715 SDValue SP = DAG.getCopyFromReg(Chain, dl, SPReg, VT);
1717 Align Alignment = cast<ConstantSDNode>(Tmp3)->getAlignValue();
1725 if (Alignment > StackAlign)
1727 DAG.getConstant(-Alignment.
value(), dl, VT));
1728 Chain = DAG.getCopyToReg(Chain, dl, SPReg, Tmp1);
1730 Tmp2 = DAG.getCALLSEQ_END(Chain, 0, 0,
SDValue(), dl);
1742 return EmitStackConvert(
SrcOp, SlotVT, DestVT, dl, DAG.getEntryNode());
1750 Align DestAlign = DAG.getDataLayout().getPrefTypeAlign(DestType);
1753 if ((SrcVT.
bitsGT(SlotVT) &&
1754 !TLI.isTruncStoreLegalOrCustom(
SrcOp.getValueType(), SlotVT)) ||
1755 (SlotVT.
bitsLT(DestVT) &&
1756 !TLI.isLoadExtLegalOrCustom(
ISD::EXTLOAD, DestVT, SlotVT)))
1760 Align SrcAlign = DAG.getDataLayout().getPrefTypeAlign(
1761 SrcOp.getValueType().getTypeForEVT(*DAG.getContext()));
1773 if (SrcVT.
bitsGT(SlotVT))
1774 Store = DAG.getTruncStore(Chain, dl,
SrcOp, FIPtr, PtrInfo,
1778 Store = DAG.getStore(Chain, dl,
SrcOp, FIPtr, PtrInfo, SrcAlign);
1782 if (SlotVT.
bitsEq(DestVT))
1783 return DAG.getLoad(DestVT, dl, Store, FIPtr, PtrInfo, DestAlign);
1786 return DAG.getExtLoad(
ISD::EXTLOAD, dl, DestVT, Store, FIPtr, PtrInfo, SlotVT,
1799 SDValue Ch = DAG.getTruncStore(
1800 DAG.getEntryNode(), dl,
Node->getOperand(0), StackPtr,
1802 Node->getValueType(0).getVectorElementType());
1804 Node->getValueType(0), dl, Ch, StackPtr,
1811 unsigned NumElems =
Node->getNumOperands();
1813 EVT VT =
Node->getValueType(0);
1825 for (
unsigned i = 0; i < NumElems; ++i) {
1836 while (IntermedVals.
size() > 2) {
1837 NewIntermedVals.
clear();
1838 for (
unsigned i = 0, e = (IntermedVals.
size() & ~1u); i < e; i += 2) {
1844 FinalIndices.
reserve(IntermedVals[i].second.
size() +
1845 IntermedVals[i+1].second.
size());
1848 for (
unsigned j = 0, f = IntermedVals[i].second.
size(); j != f;
1851 FinalIndices.
push_back(IntermedVals[i].second[j]);
1853 for (
unsigned j = 0, f = IntermedVals[i+1].second.
size(); j != f;
1855 ShuffleVec[k] = NumElems + j;
1856 FinalIndices.
push_back(IntermedVals[i+1].second[j]);
1862 IntermedVals[i+1].first,
1867 std::make_pair(Shuffle, std::move(FinalIndices)));
1872 if ((IntermedVals.
size() & 1) != 0)
1875 IntermedVals.
swap(NewIntermedVals);
1879 "Invalid number of intermediate vectors");
1880 SDValue Vec1 = IntermedVals[0].first;
1882 if (IntermedVals.
size() > 1)
1883 Vec2 = IntermedVals[1].first;
1888 for (
unsigned i = 0, e = IntermedVals[0].second.
size(); i != e; ++i)
1889 ShuffleVec[IntermedVals[0].second[i]] = i;
1890 for (
unsigned i = 0, e = IntermedVals[1].second.
size(); i != e; ++i)
1891 ShuffleVec[IntermedVals[1].second[i]] = NumElems + i;
1905 unsigned NumElems =
Node->getNumOperands();
1908 EVT VT =
Node->getValueType(0);
1909 EVT OpVT =
Node->getOperand(0).getValueType();
1914 bool isOnlyLowElement =
true;
1915 bool MoreThanTwoValues =
false;
1917 for (
unsigned i = 0; i < NumElems; ++i) {
1922 isOnlyLowElement =
false;
1923 if (!isa<ConstantFPSDNode>(V) && !isa<ConstantSDNode>(V))
1928 }
else if (!Value2.
getNode()) {
1931 }
else if (V != Value1 && V != Value2) {
1932 MoreThanTwoValues =
true;
1937 return DAG.getUNDEF(VT);
1939 if (isOnlyLowElement)
1945 for (
unsigned i = 0, e = NumElems; i !=
e; ++i) {
1947 dyn_cast<ConstantFPSDNode>(
Node->getOperand(i))) {
1950 dyn_cast<ConstantSDNode>(
Node->getOperand(i))) {
1969 DAG.getConstantPool(CP, TLI.getPointerTy(DAG.getDataLayout()));
1970 Align Alignment = cast<ConstantPoolSDNode>(CPIdx)->getAlign();
1972 VT, dl, DAG.getEntryNode(), CPIdx,
1978 for (
unsigned i = 0; i < NumElems; ++i) {
1979 if (
Node->getOperand(i).isUndef())
1984 if (TLI.shouldExpandBuildVectorWithShuffles(VT, DefinedValues.
size())) {
1985 if (!MoreThanTwoValues) {
1987 for (
unsigned i = 0; i < NumElems; ++i) {
1991 ShuffleVec[i] =
V == Value1 ? 0 : NumElems;
1993 if (TLI.isShuffleMaskLegal(ShuffleVec,
Node->getValueType(0))) {
2000 Vec2 = DAG.getUNDEF(VT);
2003 return DAG.getVectorShuffle(VT, dl, Vec1, Vec2, ShuffleVec);
2013 return ExpandVectorBuildThroughStack(
Node);
2018 EVT VT =
Node->getValueType(0);
2021 return DAG.getSplatBuildVector(VT,
DL, SplatVal);
2033 EVT ArgVT =
Op.getValueType();
2037 Entry.IsSExt = TLI.shouldSignExtendTypeInLibCall(ArgVT,
isSigned);
2038 Entry.IsZExt = !TLI.shouldSignExtendTypeInLibCall(ArgVT,
isSigned);
2039 Args.push_back(Entry);
2041 SDValue Callee = DAG.getExternalSymbol(TLI.getLibcallName(LC),
2042 TLI.getPointerTy(DAG.getDataLayout()));
2044 EVT RetVT =
Node->getValueType(0);
2051 SDValue InChain = DAG.getEntryNode();
2056 const Function &
F = DAG.getMachineFunction().getFunction();
2058 TLI.isInTailCallPosition(DAG,
Node, TCChain) &&
2059 (
RetTy ==
F.getReturnType() ||
F.getReturnType()->isVoidTy());
2064 bool signExtend = TLI.shouldSignExtendTypeInLibCall(RetVT,
isSigned);
2067 .setLibCallee(TLI.getLibcallCallingConv(LC),
RetTy,
Callee,
2069 .setTailCall(isTailCall)
2070 .setSExtResult(signExtend)
2071 .setZExtResult(!signExtend)
2072 .setIsPostTypeLegalization(
true);
2074 std::pair<SDValue, SDValue>
CallInfo = TLI.LowerCallTo(CLI);
2079 return DAG.getRoot();
2086void SelectionDAGLegalize::ExpandFPLibCall(
SDNode*
Node,
2089 if (LC == RTLIB::UNKNOWN_LIBCALL)
2092 if (
Node->isStrictFPOpcode()) {
2093 EVT RetVT =
Node->getValueType(0);
2097 std::pair<SDValue, SDValue> Tmp = TLI.makeLibCall(DAG, LC, RetVT,
2100 Node->getOperand(0));
2102 Results.push_back(Tmp.second);
2110void SelectionDAGLegalize::ExpandFPLibCall(
SDNode*
Node,
2118 Call_F32, Call_F64, Call_F80,
2119 Call_F128, Call_PPCF128);
2130 switch (
Node->getSimpleValueType(0).SimpleTy) {
2132 case MVT::i8: LC = Call_I8;
break;
2133 case MVT::i16: LC = Call_I16;
break;
2134 case MVT::i32: LC = Call_I32;
break;
2135 case MVT::i64: LC = Call_I64;
break;
2136 case MVT::i128: LC = Call_I128;
break;
2143void SelectionDAGLegalize::ExpandArgFPLibCall(
SDNode*
Node,
2150 EVT InVT =
Node->getOperand(
Node->isStrictFPOpcode() ? 1 : 0).getValueType();
2152 Call_F32, Call_F64, Call_F80,
2153 Call_F128, Call_PPCF128);
2159SelectionDAGLegalize::ExpandDivRemLibCall(
SDNode *
Node,
2161 unsigned Opcode =
Node->getOpcode();
2165 switch (
Node->getSimpleValueType(0).SimpleTy) {
2167 case MVT::i8: LC=
isSigned ? RTLIB::SDIVREM_I8 : RTLIB::UDIVREM_I8;
break;
2168 case MVT::i16: LC=
isSigned ? RTLIB::SDIVREM_I16 : RTLIB::UDIVREM_I16;
break;
2169 case MVT::i32: LC=
isSigned ? RTLIB::SDIVREM_I32 : RTLIB::UDIVREM_I32;
break;
2170 case MVT::i64: LC=
isSigned ? RTLIB::SDIVREM_I64 : RTLIB::UDIVREM_I64;
break;
2171 case MVT::i128: LC=
isSigned ? RTLIB::SDIVREM_I128:RTLIB::UDIVREM_I128;
break;
2177 SDValue InChain = DAG.getEntryNode();
2179 EVT RetVT =
Node->getValueType(0);
2185 EVT ArgVT =
Op.getValueType();
2191 Args.push_back(Entry);
2195 SDValue FIPtr = DAG.CreateStackTemporary(RetVT);
2197 Entry.Ty =
RetTy->getPointerTo();
2200 Args.push_back(Entry);
2202 SDValue Callee = DAG.getExternalSymbol(TLI.getLibcallName(LC),
2203 TLI.getPointerTy(DAG.getDataLayout()));
2209 .setLibCallee(TLI.getLibcallCallingConv(LC),
RetTy,
Callee,
2214 std::pair<SDValue, SDValue>
CallInfo = TLI.LowerCallTo(CLI);
2226 switch (
Node->getSimpleValueType(0).SimpleTy) {
2228 case MVT::f32: LC = RTLIB::SINCOS_F32;
break;
2229 case MVT::f64: LC = RTLIB::SINCOS_F64;
break;
2230 case MVT::f80: LC = RTLIB::SINCOS_F80;
break;
2231 case MVT::f128: LC = RTLIB::SINCOS_F128;
break;
2232 case MVT::ppcf128: LC = RTLIB::SINCOS_PPCF128;
break;
2255SelectionDAGLegalize::ExpandSinCosLibCall(
SDNode *
Node,
2258 switch (
Node->getSimpleValueType(0).SimpleTy) {
2260 case MVT::f32: LC = RTLIB::SINCOS_F32;
break;
2261 case MVT::f64: LC = RTLIB::SINCOS_F64;
break;
2262 case MVT::f80: LC = RTLIB::SINCOS_F80;
break;
2263 case MVT::f128: LC = RTLIB::SINCOS_F128;
break;
2264 case MVT::ppcf128: LC = RTLIB::SINCOS_PPCF128;
break;
2270 SDValue InChain = DAG.getEntryNode();
2272 EVT RetVT =
Node->getValueType(0);
2279 Entry.Node =
Node->getOperand(0);
2281 Entry.IsSExt =
false;
2282 Entry.IsZExt =
false;
2283 Args.push_back(Entry);
2286 SDValue SinPtr = DAG.CreateStackTemporary(RetVT);
2287 Entry.Node = SinPtr;
2288 Entry.Ty =
RetTy->getPointerTo();
2289 Entry.IsSExt =
false;
2290 Entry.IsZExt =
false;
2291 Args.push_back(Entry);
2294 SDValue CosPtr = DAG.CreateStackTemporary(RetVT);
2295 Entry.Node = CosPtr;
2296 Entry.Ty =
RetTy->getPointerTo();
2297 Entry.IsSExt =
false;
2298 Entry.IsZExt =
false;
2299 Args.push_back(Entry);
2301 SDValue Callee = DAG.getExternalSymbol(TLI.getLibcallName(LC),
2302 TLI.getPointerTy(DAG.getDataLayout()));
2306 CLI.setDebugLoc(dl).setChain(InChain).setLibCallee(
2310 std::pair<SDValue, SDValue>
CallInfo = TLI.LowerCallTo(CLI);
2320 EVT VT =
Node->getValueType(0);
2323 EVT ExpVT =
N.getValueType();
2325 if (AsIntVT ==
EVT())
2338 TLI.getSetCCResultType(DAG.getDataLayout(), *DAG.getContext(), ExpVT);
2343 const int Precision = APFloat::semanticsPrecision(FltSem);
2345 const SDValue MaxExp = DAG.getConstant(MaxExpVal, dl, ExpVT);
2346 const SDValue MinExp = DAG.getConstant(MinExpVal, dl, ExpVT);
2348 const SDValue DoubleMaxExp = DAG.getConstant(2 * MaxExpVal, dl, ExpVT);
2350 const APFloat One(FltSem,
"1.0");
2351 APFloat ScaleUpK =
scalbn(One, MaxExpVal, APFloat::rmNearestTiesToEven);
2355 scalbn(One, MinExpVal + Precision, APFloat::rmNearestTiesToEven);
2364 SDValue ClampMaxVal = DAG.getConstant(3 * MaxExpVal, dl, ExpVT);
2370 DAG.getSetCC(dl, SetCCVT,
N, DoubleMaxExp,
ISD::SETUGT);
2372 const SDValue ScaleUpVal = DAG.getConstantFP(ScaleUpK, dl, VT);
2384 SDValue Increment0 = DAG.getConstant(-(MinExpVal + Precision), dl, ExpVT);
2385 SDValue Increment1 = DAG.getConstant(-2 * (MinExpVal + Precision), dl, ExpVT);
2390 DAG.getConstant(3 * MinExpVal + 2 * Precision, dl, ExpVT);
2395 const SDValue ScaleDownVal = DAG.getConstantFP(ScaleDownK, dl, VT);
2399 SDValue ScaleDownTwice = DAG.getSetCC(
2400 dl, SetCCVT,
N, DAG.getConstant(2 * MinExpVal + Precision, dl, ExpVT),
2412 DAG.getNode(
ISD::SELECT, dl, VT, NLtMinExp, SelectX_Small,
X));
2416 DAG.getNode(
ISD::SELECT, dl, ExpVT, NLtMinExp, SelectN_Small,
N));
2421 DAG.getShiftAmountConstant(Precision - 1, ExpVT, dl);
2422 SDValue CastExpToValTy = DAG.getZExtOrTrunc(BiasedN, dl, AsIntVT);
2425 ExponentShiftAmt, NUW_NSW);
2427 return DAG.getNode(
ISD::FMUL, dl, VT, NewX, AsFP);
2438 EVT DestVT =
Node->getValueType(0);
2440 unsigned OpNo =
Node->isStrictFPOpcode() ? 1 : 0;
2446 if (SrcVT == MVT::i32 && TLI.isTypeLegal(MVT::f64) &&
2447 (DestVT.
bitsLE(MVT::f64) ||
2451 LLVM_DEBUG(
dbgs() <<
"32-bit [signed|unsigned] integer to float/double "
2455 SDValue StackSlot = DAG.CreateStackTemporary(MVT::f64);
2462 DAG.getConstant(0x80000000u, dl, MVT::i32));
2465 SDValue Hi = DAG.getConstant(0x43300000u, dl, MVT::i32);
2468 if (DAG.getDataLayout().isBigEndian())
2471 SDValue MemChain = DAG.getEntryNode();
2474 SDValue Store1 = DAG.getStore(MemChain, dl,
Lo, StackSlot,
2486 SDValue Bias = DAG.getConstantFP(
2487 isSigned ? llvm::bit_cast<double>(0x4330000080000000ULL)
2488 : llvm::bit_cast<double>(0x4330000000000000ULL),
2493 if (
Node->isStrictFPOpcode()) {
2495 {
Node->getOperand(0), Load, Bias});
2498 std::pair<SDValue, SDValue> ResultPair;
2500 DAG.getStrictFPExtendOrRound(Sub, Chain, dl, DestVT);
2501 Result = ResultPair.first;
2502 Chain = ResultPair.second;
2508 Result = DAG.getFPExtendOrRound(Sub, dl, DestVT);
2517 if (((SrcVT == MVT::i32 || SrcVT == MVT::i64) && DestVT == MVT::f32) ||
2518 (SrcVT == MVT::i64 && DestVT == MVT::f64)) {
2519 LLVM_DEBUG(
dbgs() <<
"Converting unsigned i32/i64 to f32/f64\n");
2534 EVT SetCCVT = getSetCCResultType(SrcVT);
2536 SDValue SignBitTest = DAG.getSetCC(
2537 dl, SetCCVT, Op0, DAG.getConstant(0, dl, SrcVT),
ISD::SETLT);
2539 EVT ShiftVT = TLI.getShiftAmountTy(SrcVT, DAG.getDataLayout());
2540 SDValue ShiftConst = DAG.getConstant(1, dl, ShiftVT);
2542 SDValue AndConst = DAG.getConstant(1, dl, SrcVT);
2547 if (
Node->isStrictFPOpcode()) {
2550 SDValue InCvt = DAG.getSelect(dl, SrcVT, SignBitTest,
Or, Op0);
2552 {
Node->getOperand(0), InCvt });
2560 Flags.setNoFPExcept(
Node->getFlags().hasNoFPExcept());
2561 Fast->setFlags(Flags);
2562 Flags.setNoFPExcept(
true);
2570 return DAG.getSelect(dl, DestVT, SignBitTest, Slow,
Fast);
2574 if (!TLI.isOperationLegalOrCustom(
2581 assert(APFloat::semanticsPrecision(DAG.EVTToAPFloatSemantics(DestVT)) >=
2583 "Cannot perform lossless SINT_TO_FP!");
2586 if (
Node->isStrictFPOpcode()) {
2588 {
Node->getOperand(0), Op0 });
2592 SDValue SignSet = DAG.getSetCC(dl, getSetCCResultType(SrcVT), Op0,
2595 Four = DAG.getIntPtrConstant(4, dl);
2596 SDValue CstOffset = DAG.getSelect(dl,
Zero.getValueType(),
2597 SignSet, Four, Zero);
2606 case MVT::i8 : FF = 0x43800000ULL;
break;
2607 case MVT::i16: FF = 0x47800000ULL;
break;
2608 case MVT::i32: FF = 0x4F800000ULL;
break;
2609 case MVT::i64: FF = 0x5F800000ULL;
break;
2611 if (DAG.getDataLayout().isLittleEndian())
2617 DAG.getConstantPool(FudgeFactor, TLI.getPointerTy(DAG.getDataLayout()));
2618 Align Alignment = cast<ConstantPoolSDNode>(CPIdx)->getAlign();
2622 if (DestVT == MVT::f32)
2623 FudgeInReg = DAG.getLoad(
2624 MVT::f32, dl, DAG.getEntryNode(), CPIdx,
2633 LegalizeOp(
Load.getNode());
2637 if (
Node->isStrictFPOpcode()) {
2639 { Tmp1.
getValue(1), Tmp1, FudgeInReg });
2640 Chain =
Result.getValue(1);
2644 return DAG.getNode(
ISD::FADD, dl, DestVT, Tmp1, FudgeInReg);
2652void SelectionDAGLegalize::PromoteLegalINT_TO_FP(
2654 bool IsStrict =
N->isStrictFPOpcode();
2657 EVT DestVT =
N->getValueType(0);
2658 SDValue LegalOp =
N->getOperand(IsStrict ? 1 : 0);
2665 unsigned OpToUse = 0;
2673 if (TLI.isOperationLegalOrCustom(SIntOp, NewInTy)) {
2681 if (TLI.isOperationLegalOrCustom(UIntOp, NewInTy)) {
2693 DAG.
getNode(OpToUse, dl, {DestVT, MVT::Other},
2696 dl, NewInTy, LegalOp)});
2703 DAG.getNode(OpToUse, dl, DestVT,
2705 dl, NewInTy, LegalOp)));
2713void SelectionDAGLegalize::PromoteLegalFP_TO_INT(
SDNode *
N,
const SDLoc &dl,
2715 bool IsStrict =
N->isStrictFPOpcode();
2718 EVT DestVT =
N->getValueType(0);
2719 SDValue LegalOp =
N->getOperand(IsStrict ? 1 : 0);
2721 EVT NewOutTy = DestVT;
2723 unsigned OpToUse = 0;
2733 if (TLI.isOperationLegalOrCustom(OpToUse, NewOutTy))
2738 if (!IsSigned && TLI.isOperationLegalOrCustom(OpToUse, NewOutTy))
2747 SDVTList VTs = DAG.getVTList(NewOutTy, MVT::Other);
2748 Operation = DAG.getNode(OpToUse, dl, VTs,
N->getOperand(0), LegalOp);
2750 Operation = DAG.getNode(OpToUse, dl, NewOutTy, LegalOp);
2765 unsigned Opcode =
Node->getOpcode();
2768 EVT NewOutTy =
Node->getValueType(0);
2773 if (TLI.isOperationLegalOrCustom(Opcode, NewOutTy))
2780 Node->getOperand(1));
2786 EVT VT =
Op.getValueType();
2787 EVT ShVT = TLI.getShiftAmountTy(VT, DAG.getDataLayout());
2792 if (TLI.isOperationLegalOrPromote(
ISD::CTPOP, VT)) {
2798 DAG.getConstant(1ULL << (--i), dl, ShVT));
2803 return DAG.getNode(
ISD::AND, dl, VT, Result, DAG.getConstant(1, dl, VT));
2806bool SelectionDAGLegalize::ExpandNode(
SDNode *
Node) {
2810 SDValue Tmp1, Tmp2, Tmp3, Tmp4;
2812 switch (
Node->getOpcode()) {
2814 if ((Tmp1 = TLI.expandABS(
Node, DAG)))
2819 if ((Tmp1 = TLI.expandABD(
Node, DAG)))
2823 if ((Tmp1 = TLI.expandCTPOP(
Node, DAG)))
2828 if ((Tmp1 = TLI.expandCTLZ(
Node, DAG)))
2833 if ((Tmp1 = TLI.expandCTTZ(
Node, DAG)))
2837 if ((Tmp1 = TLI.expandBITREVERSE(
Node, DAG)))
2841 if ((Tmp1 = TLI.expandBSWAP(
Node, DAG)))
2845 Results.push_back(ExpandPARITY(
Node->getOperand(0), dl));
2850 Results.push_back(DAG.getConstant(0, dl,
Node->getValueType(0)));
2853 SDValue CfaArg = DAG.getSExtOrTrunc(
Node->getOperand(0), dl,
2854 TLI.getPointerTy(DAG.getDataLayout()));
2862 DAG.getConstant(0, dl, TLI.getPointerTy(DAG.getDataLayout())));
2868 Results.push_back(DAG.getConstant(1, dl,
Node->getValueType(0)));
2884 DAG.getConstant(0, dl,
Node->getValueType(0)));
2890 Results.push_back(DAG.getConstant(0, dl, MVT::i32));
2896 SDVTList VTs = DAG.getVTList(
Node->getValueType(0), MVT::Other);
2897 SDValue Swap = DAG.getAtomicCmpSwap(
2899 Node->getOperand(0),
Node->getOperand(1), Zero, Zero,
2900 cast<AtomicSDNode>(
Node)->getMemOperand());
2908 cast<AtomicSDNode>(
Node)->getMemoryVT(),
2909 Node->getOperand(0),
2910 Node->getOperand(1),
Node->getOperand(2),
2911 cast<AtomicSDNode>(
Node)->getMemOperand());
2919 SDVTList VTs = DAG.getVTList(
Node->getValueType(0), MVT::Other);
2920 SDValue Res = DAG.getAtomicCmpSwap(
2922 Node->getOperand(0),
Node->getOperand(1),
Node->getOperand(2),
2923 Node->getOperand(3), cast<MemSDNode>(
Node)->getMemOperand());
2929 EVT AtomicType = cast<AtomicSDNode>(
Node)->getMemoryVT();
2930 EVT OuterType =
Node->getValueType(0);
2931 switch (TLI.getExtendForAtomicOps()) {
2934 DAG.getValueType(AtomicType));
2936 Node->getOperand(2), DAG.getValueType(AtomicType));
2941 DAG.getValueType(AtomicType));
2942 RHS = DAG.getZeroExtendInReg(
Node->getOperand(2), dl, AtomicType);
2946 LHS = DAG.getZeroExtendInReg(Res, dl, AtomicType);
2947 RHS = DAG.getZeroExtendInReg(
Node->getOperand(2), dl, AtomicType);
2965 for (
unsigned i = 0; i <
Node->getNumValues(); i++)
2969 EVT VT =
Node->getValueType(0);
2971 Results.push_back(DAG.getConstant(0, dl, VT));
2974 Results.push_back(DAG.getConstantFP(0, dl, VT));
2981 if (TLI.isStrictFPEnabled())
2985 if (TLI.getStrictFPOperationAction(
Node->getOpcode(),
2986 Node->getValueType(0))
2987 == TargetLowering::Legal)
2991 if ((Tmp1 = EmitStackConvert(
Node->getOperand(1),
Node->getValueType(0),
2992 Node->getValueType(0), dl,
2993 Node->getOperand(0)))) {
2995 LLVM_DEBUG(
dbgs() <<
"Successfully expanded STRICT_FP_ROUND node\n");
3001 if ((Tmp1 = EmitStackConvert(
Node->getOperand(0),
Node->getValueType(0),
3002 Node->getValueType(0), dl)))
3008 if (TLI.isStrictFPEnabled())
3012 if (TLI.getStrictFPOperationAction(
Node->getOpcode(),
3013 Node->getValueType(0))
3014 == TargetLowering::Legal)
3018 if ((Tmp1 = EmitStackConvert(
3019 Node->getOperand(1),
Node->getOperand(1).getValueType(),
3020 Node->getValueType(0), dl,
Node->getOperand(0)))) {
3022 LLVM_DEBUG(
dbgs() <<
"Successfully expanded STRICT_FP_EXTEND node\n");
3027 if ((Tmp1 = EmitStackConvert(
Node->getOperand(0),
3028 Node->getOperand(0).getValueType(),
3029 Node->getValueType(0), dl)))
3038 if (
Op.getValueType() == MVT::bf16) {
3042 Op = DAG.getAnyExtOrTrunc(Op, dl, MVT::i32);
3046 DAG.getConstant(16, dl,
3047 TLI.getShiftAmountTy(MVT::i32, DAG.getDataLayout())));
3050 if (
Node->getValueType(0) != MVT::f32)
3057 if (
Op.getValueType() != MVT::f32)
3059 DAG.getIntPtrConstant(0, dl,
true));
3062 DAG.getConstant(16, dl,
3063 TLI.getShiftAmountTy(MVT::i32, DAG.getDataLayout())));
3066 if (
Node->getValueType(0) == MVT::bf16) {
3070 Op = DAG.getAnyExtOrTrunc(Op, dl,
Node->getValueType(0));
3076 EVT ExtraVT = cast<VTSDNode>(
Node->getOperand(1))->getVT();
3077 EVT VT =
Node->getValueType(0);
3087 SDValue One = DAG.getConstant(1, dl, VT);
3097 EVT ShiftAmountTy = TLI.getShiftAmountTy(VT, DAG.getDataLayout());
3100 SDValue ShiftCst = DAG.getConstant(BitsDiff, dl, ShiftAmountTy);
3102 Node->getOperand(0), ShiftCst);
3109 if (TLI.expandUINT_TO_FP(
Node, Tmp1, Tmp2, DAG)) {
3111 if (
Node->isStrictFPOpcode())
3118 if ((Tmp1 = ExpandLegalINT_TO_FP(
Node, Tmp2))) {
3120 if (
Node->isStrictFPOpcode())
3125 if (TLI.expandFP_TO_SINT(
Node, Tmp1, DAG))
3129 if (TLI.expandFP_TO_SINT(
Node, Tmp1, DAG)) {
3131 LLVM_DEBUG(
dbgs() <<
"Successfully expanded STRICT_FP_TO_SINT node\n");
3136 if (TLI.expandFP_TO_UINT(
Node, Tmp1, Tmp2, DAG))
3140 if (TLI.expandFP_TO_UINT(
Node, Tmp1, Tmp2, DAG)) {
3142 DAG.ReplaceAllUsesOfValueWith(
SDValue(
Node,1), Tmp2);
3145 LLVM_DEBUG(
dbgs() <<
"Successfully expanded STRICT_FP_TO_UINT node\n");
3151 Results.push_back(TLI.expandFP_TO_INT_SAT(
Node, DAG));
3161 if (
Node->getOperand(0).getValueType().getVectorNumElements() == 1)
3164 Node->getOperand(0));
3166 Tmp1 = ExpandExtractFromVectorThroughStack(
SDValue(
Node, 0));
3176 Results.push_back(ExpandVectorBuildThroughStack(
Node));
3182 Results.push_back(ExpandINSERT_VECTOR_ELT(
Node->getOperand(0),
3183 Node->getOperand(1),
3184 Node->getOperand(2), dl));
3190 EVT VT =
Node->getValueType(0);
3194 if (!TLI.isTypeLegal(EltVT)) {
3195 EVT NewEltVT = TLI.getTypeToTransformTo(*DAG.getContext(), EltVT);
3200 if (NewEltVT.
bitsLT(EltVT)) {
3216 unsigned int factor =
3224 for (
unsigned fi = 0; fi < factor; ++fi)
3228 for (
unsigned fi = 0; fi < factor; ++fi)
3239 for (
unsigned i = 0; i != NumElems; ++i) {
3247 DAG.getVectorIdxConstant(
Idx, dl)));
3251 DAG.getVectorIdxConstant(
Idx - NumElems, dl)));
3254 Tmp1 = DAG.getBuildVector(VT, dl, Ops);
3261 Results.push_back(TLI.expandVectorSplice(
Node, DAG));
3265 EVT OpTy =
Node->getOperand(0).getValueType();
3266 if (
Node->getConstantOperandVal(1)) {
3270 TLI.getShiftAmountTy(
3271 Node->getOperand(0).getValueType(),
3272 DAG.getDataLayout())));
3277 Node->getOperand(0));
3285 if (
Register SP = TLI.getStackPointerRegisterToSaveRestore()) {
3286 Results.push_back(DAG.getCopyFromReg(
Node->getOperand(0), dl, SP,
3287 Node->getValueType(0)));
3290 Results.push_back(DAG.getUNDEF(
Node->getValueType(0)));
3297 if (
Register SP = TLI.getStackPointerRegisterToSaveRestore()) {
3298 Results.push_back(DAG.getCopyToReg(
Node->getOperand(0), dl, SP,
3299 Node->getOperand(1)));
3305 Results.push_back(DAG.getConstant(0, dl,
Node->getValueType(0)));
3318 auto CNode = cast<ConstantSDNode>(
Node->getOperand(1));
3321 TLI.expandIS_FPCLASS(
Node->getValueType(0),
Node->getOperand(0),
3332 switch (
Node->getOpcode()) {
3339 Tmp1 =
Node->getOperand(0);
3340 Tmp2 =
Node->getOperand(1);
3341 Tmp1 = DAG.getSelectCC(dl, Tmp1, Tmp2, Tmp1, Tmp2, Pred);
3347 if (
SDValue Expanded = TLI.expandFMINNUM_FMAXNUM(
Node, DAG))
3353 EVT VT =
Node->getValueType(0);
3359 SDVTList VTs = DAG.getVTList(VT, VT);
3369 EVT VT =
Node->getValueType(0);
3373 if (TLI.getLibcallName(LC))
3379 Results.push_back(Expanded.getValue(1));
3388 if (
Node->getValueType(0) != MVT::f32) {
3399 if (
Node->getValueType(0) != MVT::f32) {
3405 {
Node->getOperand(0),
Node->getOperand(1)});
3407 {
Node->getValueType(0), MVT::Other},
3415 if (!TLI.useSoftFloat() &&
TM.Options.UnsafeFPMath) {
3417 MVT SVT =
Op.getSimpleValueType();
3418 if ((SVT == MVT::f64 || SVT == MVT::f80) &&
3424 DAG.getIntPtrConstant(0, dl,
true));
3435 DAG.shouldOptForSize()))
3436 Results.push_back(ExpandConstantFP(CFP,
true));
3441 Results.push_back(ExpandConstant(CP));
3445 EVT VT =
Node->getValueType(0);
3446 if (TLI.isOperationLegalOrCustom(
ISD::FADD, VT) &&
3447 TLI.isOperationLegalOrCustom(
ISD::FNEG, VT)) {
3456 EVT VT =
Node->getValueType(0);
3458 TLI.isOperationLegalOrCustom(
ISD::XOR, VT) &&
3459 "Don't know how to expand this subtraction!");
3460 Tmp1 = DAG.getNOT(dl,
Node->getOperand(1), VT);
3461 Tmp1 = DAG.
getNode(
ISD::ADD, dl, VT, Tmp1, DAG.getConstant(1, dl, VT));
3467 if (TLI.expandREM(
Node, Tmp1, DAG))
3474 EVT VT =
Node->getValueType(0);
3475 if (TLI.isOperationLegalOrCustom(DivRemOpc, VT)) {
3476 SDVTList VTs = DAG.getVTList(VT, VT);
3477 Tmp1 = DAG.
getNode(DivRemOpc, dl, VTs,
Node->getOperand(0),
3478 Node->getOperand(1));
3485 unsigned ExpandOpcode =
3487 EVT VT =
Node->getValueType(0);
3488 SDVTList VTs = DAG.getVTList(VT, VT);
3490 Tmp1 = DAG.
getNode(ExpandOpcode, dl, VTs,
Node->getOperand(0),
3491 Node->getOperand(1));
3499 MVT VT =
LHS.getSimpleValueType();
3500 unsigned MULHOpcode =
3503 if (TLI.isOperationLegalOrCustom(MULHOpcode, VT)) {
3505 Results.push_back(DAG.getNode(MULHOpcode, dl, VT, LHS, RHS));
3511 assert(TLI.isTypeLegal(HalfType));
3512 if (TLI.expandMUL_LOHI(
Node->getOpcode(), VT, dl, LHS, RHS, Halves,
3514 TargetLowering::MulExpansionKind::Always)) {
3515 for (
unsigned i = 0; i < 2; ++i) {
3518 SDValue Shift = DAG.getConstant(
3520 TLI.getShiftAmountTy(HalfType, DAG.getDataLayout()));
3529 EVT VT =
Node->getValueType(0);
3530 SDVTList VTs = DAG.getVTList(VT, VT);
3536 bool HasSMUL_LOHI = TLI.isOperationLegalOrCustom(
ISD::SMUL_LOHI, VT);
3537 bool HasUMUL_LOHI = TLI.isOperationLegalOrCustom(
ISD::UMUL_LOHI, VT);
3538 bool HasMULHS = TLI.isOperationLegalOrCustom(
ISD::MULHS, VT);
3539 bool HasMULHU = TLI.isOperationLegalOrCustom(
ISD::MULHU, VT);
3540 unsigned OpToUse = 0;
3541 if (HasSMUL_LOHI && !HasMULHS) {
3543 }
else if (HasUMUL_LOHI && !HasMULHU) {
3545 }
else if (HasSMUL_LOHI) {
3547 }
else if (HasUMUL_LOHI) {
3551 Results.push_back(DAG.getNode(OpToUse, dl, VTs,
Node->getOperand(0),
3552 Node->getOperand(1)));
3560 TLI.isOperationLegalOrCustom(
ISD::SHL, VT) &&
3561 TLI.isOperationLegalOrCustom(
ISD::OR, VT) &&
3562 TLI.expandMUL(
Node,
Lo,
Hi, HalfType, DAG,
3563 TargetLowering::MulExpansionKind::OnlyLegalOrCustom)) {
3568 TLI.getShiftAmountTy(HalfType, DAG.getDataLayout()));
3576 if (
SDValue Expanded = TLI.expandFunnelShift(
Node, DAG))
3581 if (
SDValue Expanded = TLI.expandROT(
Node,
true , DAG))
3588 Results.push_back(TLI.expandAddSubSat(
Node, DAG));
3598 Results.push_back(TLI.expandFixedPointMul(
Node, DAG));
3605 Node->getOperand(0),
3606 Node->getOperand(1),
3607 Node->getConstantOperandVal(2),
3630 EVT VT =
LHS.getValueType();
3634 EVT CarryType =
Node->getValueType(1);
3635 EVT SetCCType = getSetCCResultType(
Node->getValueType(0));
3637 SDValue Overflow = DAG.getSetCC(dl, SetCCType, Sum, LHS,
CC);
3640 SDValue One = DAG.getConstant(1, dl, VT);
3642 DAG.
getNode(
ISD::AND, dl, VT, DAG.getZExtOrTrunc(Carry, dl, VT), One);
3651 IsAdd ? DAG.getSetCC(dl, SetCCType, Sum2, Zero,
ISD::SETEQ)
3652 : DAG.getSetCC(dl, SetCCType, Sum, Zero,
ISD::SETEQ);
3654 DAG.getZExtOrTrunc(Carry, dl, SetCCType));
3660 Results.push_back(DAG.getBoolExtOrTrunc(ResultCarry, dl, CarryType, VT));
3666 TLI.expandSADDSUBO(
Node, Result, Overflow, DAG);
3674 TLI.expandUADDSUBO(
Node, Result, Overflow, DAG);
3682 if (TLI.expandMULO(
Node, Result, Overflow, DAG)) {
3694 DAG.getConstant(
PairTy.getSizeInBits() / 2, dl,
3695 TLI.getShiftAmountTy(
PairTy, DAG.getDataLayout())));
3700 Tmp1 =
Node->getOperand(0);
3701 Tmp2 =
Node->getOperand(1);
3702 Tmp3 =
Node->getOperand(2);
3706 cast<CondCodeSDNode>(Tmp1.
getOperand(2))->get());
3708 Tmp1 = DAG.getSelectCC(dl, Tmp1,
3721 EVT PTy = TLI.getPointerTy(TD);
3723 unsigned EntrySize =
3724 DAG.getMachineFunction().getJumpTableInfo()->getEntrySize(TD);
3731 Index = DAG.getNode(
3736 DAG.getConstant(EntrySize, dl,
Index.getValueType()));
3745 if (TLI.isJumpTableRelative()) {
3750 TLI.getPICJumpTableRelocBase(Table, DAG));
3753 Tmp1 = TLI.expandIndirectJTBranch(dl,
LD.getValue(1),
Addr, DAG);
3760 Tmp1 =
Node->getOperand(0);
3761 Tmp2 =
Node->getOperand(1);
3767 Node->getOperand(2));
3779 Node->getOperand(2));
3787 bool IsVP =
Node->getOpcode() == ISD::VP_SETCC;
3792 unsigned Offset = IsStrict ? 1 : 0;
3801 bool Legalized = TLI.LegalizeSetCCCondCode(
3802 DAG,
Node->getValueType(0), Tmp1, Tmp2, Tmp3, Mask, EVL, NeedInvert, dl,
3803 Chain, IsSignaling);
3811 {Chain, Tmp1, Tmp2, Tmp3},
Node->getFlags());
3815 {Tmp1, Tmp2, Tmp3, Mask, EVL},
Node->getFlags());
3817 Tmp1 = DAG.
getNode(
Node->getOpcode(), dl,
Node->getValueType(0), Tmp1,
3818 Tmp2, Tmp3,
Node->getFlags());
3826 Tmp1 = DAG.getLogicalNOT(dl, Tmp1, Tmp1->
getValueType(0));
3829 DAG.getVPLogicalNOT(dl, Tmp1, Mask, EVL, Tmp1->
getValueType(0));
3841 assert(!IsStrict &&
"Don't know how to expand for strict nodes.");
3846 EVT VT =
Node->getValueType(0);
3849 DAG.getBoolConstant(
true, dl, VT, Tmp1VT),
3850 DAG.getBoolConstant(
false, dl, VT, Tmp1VT), Tmp3);
3857 Tmp1 =
Node->getOperand(0);
3858 Tmp2 =
Node->getOperand(1);
3859 Tmp3 =
Node->getOperand(2);
3860 Tmp4 =
Node->getOperand(3);
3861 EVT VT =
Node->getValueType(0);
3871 "Cannot expand ISD::SELECT_CC when ISD::SELECT also needs to be "
3873 EVT CCVT = getSetCCResultType(CmpVT);
3875 Results.push_back(DAG.getSelect(dl, VT,
Cond, Tmp3, Tmp4));
3880 bool Legalized =
false;
3888 Tmp1 = DAG.getSelectCC(dl, Tmp1, Tmp2, Tmp4, Tmp3, InvCC);
3898 Tmp1 = DAG.getSelectCC(dl, Tmp2, Tmp1, Tmp4, Tmp3, SwapInvCC);
3904 Legalized = TLI.LegalizeSetCCCondCode(
3908 assert(Legalized &&
"Can't legalize SELECT_CC with legal condition!");
3919 Tmp1, Tmp2, Tmp3, Tmp4,
CC);
3924 Tmp2, Tmp3, Tmp4,
CC);
3934 Tmp1 =
Node->getOperand(0);
3935 Tmp2 =
Node->getOperand(2);
3936 Tmp3 =
Node->getOperand(3);
3937 Tmp4 =
Node->getOperand(1);
3939 bool Legalized = TLI.LegalizeSetCCCondCode(
3940 DAG, getSetCCResultType(Tmp2.
getValueType()), Tmp2, Tmp3, Tmp4,
3943 assert(Legalized &&
"Can't legalize BR_CC with legal condition!");
3948 assert(!NeedInvert &&
"Don't know how to invert BR_CC!");
3951 Tmp4, Tmp2, Tmp3,
Node->getOperand(4));
3956 Tmp2, Tmp3,
Node->getOperand(4));
3971 EVT VT =
Node->getValueType(0);
3977 for (
unsigned Idx = 0;
Idx < NumElem;
Idx++) {
3980 Node->getOperand(0), DAG.getVectorIdxConstant(
Idx, dl));
3983 Node->getOperand(1), DAG.getVectorIdxConstant(
Idx, dl));
4005 Results.push_back(TLI.expandVecReduce(
Node, DAG));
4022 if (!TLI.isStrictFPEnabled() &&
Results.
empty() &&
Node->isStrictFPOpcode()) {
4028 switch (
Node->getOpcode()) {
4030 if (TLI.getStrictFPOperationAction(
Node->getOpcode(),
4031 Node->getValueType(0))
4032 == TargetLowering::Legal)
4036 if (TLI.getStrictFPOperationAction(
4039 if (TLI.getStrictFPOperationAction(
4043 EVT VT =
Node->getValueType(0);
4047 {Node->getOperand(0), Node->getOperand(1), Neg},
4062 if (TLI.getStrictFPOperationAction(
Node->getOpcode(),
4063 Node->getOperand(1).getValueType())
4064 == TargetLowering::Legal)
4081void SelectionDAGLegalize::ConvertNodeToLibcall(
SDNode *
Node) {
4086 unsigned Opc =
Node->getOpcode();
4095 .setChain(
Node->getOperand(0))
4098 DAG.getExternalSymbol(
"__sync_synchronize",
4099 TLI.getPointerTy(DAG.getDataLayout())),
4102 std::pair<SDValue, SDValue> CallResult = TLI.LowerCallTo(CLI);
4104 Results.push_back(CallResult.second);
4126 EVT RetVT =
Node->getValueType(0);
4129 if (TLI.getLibcallName(LC)) {
4136 assert(LC != RTLIB::UNKNOWN_LIBCALL &&
4137 "Unexpected atomic op or value type!");
4141 std::pair<SDValue, SDValue> Tmp = TLI.makeLibCall(DAG, LC, RetVT,
4144 Node->getOperand(0));
4146 Results.push_back(Tmp.second);
4154 .setChain(
Node->getOperand(0))
4156 DAG.getExternalSymbol(
4157 "abort", TLI.getPointerTy(DAG.getDataLayout())),
4159 std::pair<SDValue, SDValue> CallResult = TLI.LowerCallTo(CLI);
4161 Results.push_back(CallResult.second);
4166 ExpandFPLibCall(
Node, RTLIB::FMIN_F32, RTLIB::FMIN_F64,
4167 RTLIB::FMIN_F80, RTLIB::FMIN_F128,
4168 RTLIB::FMIN_PPCF128,
Results);
4172 ExpandFPLibCall(
Node, RTLIB::FMAX_F32, RTLIB::FMAX_F64,
4173 RTLIB::FMAX_F80, RTLIB::FMAX_F128,
4174 RTLIB::FMAX_PPCF128,
Results);
4178 ExpandFPLibCall(
Node, RTLIB::SQRT_F32, RTLIB::SQRT_F64,
4179 RTLIB::SQRT_F80, RTLIB::SQRT_F128,
4180 RTLIB::SQRT_PPCF128,
Results);
4183 ExpandFPLibCall(
Node, RTLIB::CBRT_F32, RTLIB::CBRT_F64,
4184 RTLIB::CBRT_F80, RTLIB::CBRT_F128,
4185 RTLIB::CBRT_PPCF128,
Results);
4189 ExpandFPLibCall(
Node, RTLIB::SIN_F32, RTLIB::SIN_F64,
4190 RTLIB::SIN_F80, RTLIB::SIN_F128,
4195 ExpandFPLibCall(
Node, RTLIB::COS_F32, RTLIB::COS_F64,
4196 RTLIB::COS_F80, RTLIB::COS_F128,
4205 ExpandFPLibCall(
Node, RTLIB::LOG_F32, RTLIB::LOG_F64, RTLIB::LOG_F80,
4206 RTLIB::LOG_F128, RTLIB::LOG_PPCF128,
Results);
4210 ExpandFPLibCall(
Node, RTLIB::LOG2_F32, RTLIB::LOG2_F64, RTLIB::LOG2_F80,
4211 RTLIB::LOG2_F128, RTLIB::LOG2_PPCF128,
Results);
4215 ExpandFPLibCall(
Node, RTLIB::LOG10_F32, RTLIB::LOG10_F64, RTLIB::LOG10_F80,
4216 RTLIB::LOG10_F128, RTLIB::LOG10_PPCF128,
Results);
4220 ExpandFPLibCall(
Node, RTLIB::EXP_F32, RTLIB::EXP_F64, RTLIB::EXP_F80,
4221 RTLIB::EXP_F128, RTLIB::EXP_PPCF128,
Results);
4225 ExpandFPLibCall(
Node, RTLIB::EXP2_F32, RTLIB::EXP2_F64, RTLIB::EXP2_F80,
4226 RTLIB::EXP2_F128, RTLIB::EXP2_PPCF128,
Results);
4230 ExpandFPLibCall(
Node, RTLIB::TRUNC_F32, RTLIB::TRUNC_F64,
4231 RTLIB::TRUNC_F80, RTLIB::TRUNC_F128,
4232 RTLIB::TRUNC_PPCF128,
Results);
4236 ExpandFPLibCall(
Node, RTLIB::FLOOR_F32, RTLIB::FLOOR_F64,
4237 RTLIB::FLOOR_F80, RTLIB::FLOOR_F128,
4238 RTLIB::FLOOR_PPCF128,
Results);
4242 ExpandFPLibCall(
Node, RTLIB::CEIL_F32, RTLIB::CEIL_F64,
4243 RTLIB::CEIL_F80, RTLIB::CEIL_F128,
4244 RTLIB::CEIL_PPCF128,
Results);
4248 ExpandFPLibCall(
Node, RTLIB::RINT_F32, RTLIB::RINT_F64,
4249 RTLIB::RINT_F80, RTLIB::RINT_F128,
4250 RTLIB::RINT_PPCF128,
Results);
4254 ExpandFPLibCall(
Node, RTLIB::NEARBYINT_F32,
4255 RTLIB::NEARBYINT_F64,
4256 RTLIB::NEARBYINT_F80,
4257 RTLIB::NEARBYINT_F128,
4258 RTLIB::NEARBYINT_PPCF128,
Results);
4262 ExpandFPLibCall(
Node, RTLIB::ROUND_F32,
4266 RTLIB::ROUND_PPCF128,
Results);
4270 ExpandFPLibCall(
Node, RTLIB::ROUNDEVEN_F32,
4271 RTLIB::ROUNDEVEN_F64,
4272 RTLIB::ROUNDEVEN_F80,
4273 RTLIB::ROUNDEVEN_F128,
4274 RTLIB::ROUNDEVEN_PPCF128,
Results);
4278 ExpandFPLibCall(
Node, RTLIB::LDEXP_F32, RTLIB::LDEXP_F64, RTLIB::LDEXP_F80,
4279 RTLIB::LDEXP_F128, RTLIB::LDEXP_PPCF128,
Results);
4284 assert(LC != RTLIB::UNKNOWN_LIBCALL &&
"Unexpected fpowi.");
4285 if (!TLI.getLibcallName(LC)) {
4287 if (
Node->isStrictFPOpcode()) {
4290 {
Node->getValueType(0),
Node->getValueType(1)},
4291 {
Node->getOperand(0),
Node->getOperand(2)});
4294 {
Node->getValueType(0),
Node->getValueType(1)},
4301 Node->getOperand(1));
4303 Node->getValueType(0),
4308 unsigned Offset =
Node->isStrictFPOpcode() ? 1 : 0;
4309 bool ExponentHasSizeOfInt =
4310 DAG.getLibInfo().getIntSize() ==
4311 Node->getOperand(1 +
Offset).getValueType().getSizeInBits();
4312 if (!ExponentHasSizeOfInt) {
4315 DAG.getContext()->emitError(
"POWI exponent does not match sizeof(int)");
4316 Results.push_back(DAG.getUNDEF(
Node->getValueType(0)));
4324 ExpandFPLibCall(
Node, RTLIB::POW_F32, RTLIB::POW_F64, RTLIB::POW_F80,
4325 RTLIB::POW_F128, RTLIB::POW_PPCF128,
Results);
4329 ExpandArgFPLibCall(
Node, RTLIB::LROUND_F32,
4330 RTLIB::LROUND_F64, RTLIB::LROUND_F80,
4332 RTLIB::LROUND_PPCF128,
Results);
4336 ExpandArgFPLibCall(
Node, RTLIB::LLROUND_F32,
4337 RTLIB::LLROUND_F64, RTLIB::LLROUND_F80,
4338 RTLIB::LLROUND_F128,
4339 RTLIB::LLROUND_PPCF128,
Results);
4343 ExpandArgFPLibCall(
Node, RTLIB::LRINT_F32,
4344 RTLIB::LRINT_F64, RTLIB::LRINT_F80,
4346 RTLIB::LRINT_PPCF128,
Results);
4350 ExpandArgFPLibCall(
Node, RTLIB::LLRINT_F32,
4351 RTLIB::LLRINT_F64, RTLIB::LLRINT_F80,
4353 RTLIB::LLRINT_PPCF128,
Results);
4357 ExpandFPLibCall(
Node, RTLIB::DIV_F32, RTLIB::DIV_F64,
4358 RTLIB::DIV_F80, RTLIB::DIV_F128,
4363 ExpandFPLibCall(
Node, RTLIB::REM_F32, RTLIB::REM_F64,
4364 RTLIB::REM_F80, RTLIB::REM_F128,
4369 ExpandFPLibCall(
Node, RTLIB::FMA_F32, RTLIB::FMA_F64,
4370 RTLIB::FMA_F80, RTLIB::FMA_F128,
4375 ExpandFPLibCall(
Node, RTLIB::ADD_F32, RTLIB::ADD_F64,
4376 RTLIB::ADD_F80, RTLIB::ADD_F128,
4381 ExpandFPLibCall(
Node, RTLIB::MUL_F32, RTLIB::MUL_F64,
4382 RTLIB::MUL_F80, RTLIB::MUL_F128,
4386 if (
Node->getValueType(0) == MVT::f32) {
4387 Results.push_back(ExpandLibCall(RTLIB::FPEXT_F16_F32,
Node,
false));
4391 if (
Node->getValueType(0) == MVT::f32) {
4393 std::pair<SDValue, SDValue> Tmp = TLI.makeLibCall(
4394 DAG, RTLIB::FPEXT_F16_F32, MVT::f32,
Node->getOperand(1), CallOptions,
4397 Results.push_back(Tmp.second);
4404 assert(LC != RTLIB::UNKNOWN_LIBCALL &&
"Unable to expand fp_to_fp16");
4405 Results.push_back(ExpandLibCall(LC,
Node,
false));
4411 assert(LC != RTLIB::UNKNOWN_LIBCALL &&
"Unable to expand fp_to_bf16");
4412 Results.push_back(ExpandLibCall(LC,
Node,
false));
4420 bool IsStrict =
Node->isStrictFPOpcode();
4423 EVT SVT =
Node->getOperand(IsStrict ? 1 : 0).getValueType();
4424 EVT RVT =
Node->getValueType(0);
4432 for (
unsigned t = MVT::FIRST_INTEGER_VALUETYPE;
4433 t <= MVT::LAST_INTEGER_VALUETYPE && LC == RTLIB::UNKNOWN_LIBCALL;
4441 assert(LC != RTLIB::UNKNOWN_LIBCALL &&
"Unable to legalize as libcall");
4446 NVT,
Node->getOperand(IsStrict ? 1 : 0));
4449 std::pair<SDValue, SDValue> Tmp =
4450 TLI.makeLibCall(DAG, LC, RVT, Op, CallOptions, dl, Chain);
4453 Results.push_back(Tmp.second);
4461 bool IsStrict =
Node->isStrictFPOpcode();
4466 EVT SVT =
Op.getValueType();
4467 EVT RVT =
Node->getValueType(0);
4475 for (
unsigned IntVT = MVT::FIRST_INTEGER_VALUETYPE;
4476 IntVT <= MVT::LAST_INTEGER_VALUETYPE && LC == RTLIB::UNKNOWN_LIBCALL;
4484 assert(LC != RTLIB::UNKNOWN_LIBCALL &&
"Unable to legalize as libcall");
4488 std::pair<SDValue, SDValue> Tmp =
4489 TLI.makeLibCall(DAG, LC, NVT, Op, CallOptions, dl, Chain);
4494 Results.push_back(Tmp.second);
4505 bool IsStrict =
Node->isStrictFPOpcode();
4508 EVT VT =
Node->getValueType(0);
4509 assert(cast<ConstantSDNode>(
Node->getOperand(IsStrict ? 2 : 1))->isZero() &&
4510 "Unable to expand as libcall if it is not normal rounding");
4513 assert(LC != RTLIB::UNKNOWN_LIBCALL &&
"Unable to legalize as libcall");
4516 std::pair<SDValue, SDValue> Tmp =
4517 TLI.makeLibCall(DAG, LC, VT, Op, CallOptions,
SDLoc(
Node), Chain);
4520 Results.push_back(Tmp.second);
4526 Node->getValueType(0)),
4536 Node->getValueType(0));
4537 assert(LC != RTLIB::UNKNOWN_LIBCALL &&
"Unable to legalize as libcall");
4540 std::pair<SDValue, SDValue> Tmp =
4541 TLI.makeLibCall(DAG, LC,
Node->getValueType(0),
Node->getOperand(1),
4544 Results.push_back(Tmp.second);
4549 ExpandFPLibCall(
Node, RTLIB::SUB_F32, RTLIB::SUB_F64,
4550 RTLIB::SUB_F80, RTLIB::SUB_F128,
4556 RTLIB::SREM_I16, RTLIB::SREM_I32,
4557 RTLIB::SREM_I64, RTLIB::SREM_I128));
4562 RTLIB::UREM_I16, RTLIB::UREM_I32,
4563 RTLIB::UREM_I64, RTLIB::UREM_I128));
4568 RTLIB::SDIV_I16, RTLIB::SDIV_I32,
4569 RTLIB::SDIV_I64, RTLIB::SDIV_I128));
4574 RTLIB::UDIV_I16, RTLIB::UDIV_I32,
4575 RTLIB::UDIV_I64, RTLIB::UDIV_I128));
4585 RTLIB::MUL_I16, RTLIB::MUL_I32,
4586 RTLIB::MUL_I64, RTLIB::MUL_I128));
4589 switch (
Node->getSimpleValueType(0).SimpleTy) {
4593 Results.push_back(ExpandLibCall(RTLIB::CTLZ_I32,
Node,
false));
4596 Results.push_back(ExpandLibCall(RTLIB::CTLZ_I64,
Node,
false));
4599 Results.push_back(ExpandLibCall(RTLIB::CTLZ_I128,
Node,
false));
4606 SDValue Ptr = DAG.getIntPtrConstant(-1LL, dl);
4609 DAG.makeStateFunctionCall(RTLIB::FESETENV,
Ptr, Chain, dl));
4616 DAG.makeStateFunctionCall(RTLIB::FEGETENV, EnvPtr, Chain, dl));
4623 DAG.makeStateFunctionCall(RTLIB::FESETENV, EnvPtr, Chain, dl));
4630 LLVM_DEBUG(
dbgs() <<
"Successfully converted node to libcall\n");
4639 MVT EltVT,
MVT NewEltVT) {
4640 unsigned OldEltsPerNewElt = EltVT.