58#define DEBUG_TYPE "legalizedag"
64struct FloatSignAsInt {
87class SelectionDAGLegalize {
99 EVT getSetCCResultType(
EVT VT)
const {
110 LegalizedNodes(LegalizedNodes), UpdatedNodes(UpdatedNodes) {}
166 void getSignAsIntValue(FloatSignAsInt &State,
const SDLoc &
DL,
168 SDValue modifySignAsInt(
const FloatSignAsInt &State,
const SDLoc &
DL,
215 dbgs() <<
" with: "; New->dump(&DAG));
218 "Replacing one node with another that produces a different number "
222 UpdatedNodes->
insert(New);
228 dbgs() <<
" with: "; New->dump(&DAG));
232 UpdatedNodes->
insert(New.getNode());
233 ReplacedNode(Old.getNode());
240 for (
unsigned i = 0, e = Old->
getNumValues(); i != e; ++i) {
251 dbgs() <<
" with: "; New->dump(&DAG));
255 UpdatedNodes->
insert(New.getNode());
256 ReplacedNode(Old.getNode());
266 bool isObjectScalable) {
268 int FI = cast<FrameIndexSDNode>(StackPtr)->getIndex();
274 ObjectSize, MFI.getObjectAlign(FI));
281SDValue SelectionDAGLegalize::ShuffleWithNarrowerEltType(
286 unsigned NumEltsGrowth = NumDestElts / NumMaskElts;
288 assert(NumEltsGrowth &&
"Cannot promote to vector type with fewer elts!");
290 if (NumEltsGrowth == 1)
291 return DAG.getVectorShuffle(NVT, dl, N1, N2, Mask);
294 for (
unsigned i = 0; i != NumMaskElts; ++i) {
296 for (
unsigned j = 0;
j != NumEltsGrowth; ++
j) {
303 assert(NewMask.
size() == NumDestElts &&
"Non-integer NumEltsGrowth?");
304 assert(TLI.isShuffleMaskLegal(NewMask, NVT) &&
"Shuffle not legal?");
305 return DAG.getVectorShuffle(NVT, dl, N1, N2, NewMask);
324 assert((VT == MVT::f64 || VT == MVT::f32) &&
"Invalid type expansion");
326 (VT == MVT::f64) ? MVT::i64 : MVT::i32);
336 while (SVT != MVT::f32 && SVT != MVT::f16 && SVT != MVT::bf16) {
342 TLI.ShouldShrinkFPConstant(OrigVT)) {
345 Instruction::FPTrunc, LLVMC, SType, DAG.getDataLayout()));
353 DAG.getConstantPool(LLVMC, TLI.getPointerTy(DAG.getDataLayout()));
354 Align Alignment = cast<ConstantPoolSDNode>(CPIdx)->getAlign();
363 OrigVT, dl, DAG.getEntryNode(), CPIdx,
371 EVT VT =
CP->getValueType(0);
372 SDValue CPIdx = DAG.getConstantPool(
CP->getConstantIntValue(),
373 TLI.getPointerTy(DAG.getDataLayout()));
374 Align Alignment = cast<ConstantPoolSDNode>(CPIdx)->getAlign();
376 VT, dl, DAG.getEntryNode(), CPIdx,
402 for (
unsigned i = 0; i != NumElts; ++i)
403 ShufOps.
push_back(i != InsertPos->getZExtValue() ? i : NumElts);
405 return DAG.getVectorShuffle(Vec.
getValueType(), dl, Vec, ScVec, ShufOps);
408 return ExpandInsertToVectorThroughStack(
Op);
435 TLI.isTypeLegal(MVT::i32)) {
437 bitcastToAPInt().zextOrTrunc(32),
438 SDLoc(CFP), MVT::i32);
439 return DAG.getStore(Chain, dl, Con,
Ptr,
ST->getPointerInfo(),
440 ST->getOriginalAlign(), MMOFlags, AAInfo);
446 if (TLI.isTypeLegal(MVT::i64)) {
448 zextOrTrunc(64),
SDLoc(CFP), MVT::i64);
449 return DAG.getStore(Chain, dl, Con,
Ptr,
ST->getPointerInfo(),
450 ST->getOriginalAlign(), MMOFlags, AAInfo);
453 if (TLI.isTypeLegal(MVT::i32) && !
ST->isVolatile()) {
460 if (DAG.getDataLayout().isBigEndian())
463 Lo = DAG.getStore(Chain, dl,
Lo,
Ptr,
ST->getPointerInfo(),
464 ST->getOriginalAlign(), MMOFlags, AAInfo);
466 Hi = DAG.getStore(Chain, dl,
Hi,
Ptr,
467 ST->getPointerInfo().getWithOffset(4),
468 ST->getOriginalAlign(), MMOFlags, AAInfo);
477void SelectionDAGLegalize::LegalizeStoreOps(
SDNode *
Node) {
486 if (!
ST->isTruncatingStore()) {
489 ReplaceNode(ST, OptStore);
494 MVT VT =
Value.getSimpleValueType();
495 switch (TLI.getOperationAction(
ISD::STORE, VT)) {
497 case TargetLowering::Legal: {
500 EVT MemVT =
ST->getMemoryVT();
502 if (!TLI.allowsMemoryAccessForAlignment(*DAG.getContext(),
DL, MemVT,
503 *
ST->getMemOperand())) {
506 ReplaceNode(
SDValue(ST, 0), Result);
511 case TargetLowering::Custom: {
518 case TargetLowering::Promote: {
521 "Can only promote stores to same size type");
524 ST->getOriginalAlign(), MMOFlags, AAInfo);
534 EVT StVT =
ST->getMemoryVT();
537 auto &
DL = DAG.getDataLayout();
539 if (StWidth != StSize) {
544 Value = DAG.getZeroExtendInReg(
Value, dl, StVT);
546 DAG.getTruncStore(Chain, dl,
Value,
Ptr,
ST->getPointerInfo(), NVT,
547 ST->getOriginalAlign(), MMOFlags, AAInfo);
553 unsigned LogStWidth =
Log2_32(StWidthBits);
555 unsigned RoundWidth = 1 << LogStWidth;
556 assert(RoundWidth < StWidthBits);
557 unsigned ExtraWidth = StWidthBits - RoundWidth;
558 assert(ExtraWidth < RoundWidth);
559 assert(!(RoundWidth % 8) && !(ExtraWidth % 8) &&
560 "Store size not an integral number of bytes!");
564 unsigned IncrementSize;
566 if (
DL.isLittleEndian()) {
569 Lo = DAG.getTruncStore(Chain, dl,
Value,
Ptr,
ST->getPointerInfo(),
570 RoundVT,
ST->getOriginalAlign(), MMOFlags, AAInfo);
573 IncrementSize = RoundWidth / 8;
578 DAG.getConstant(RoundWidth, dl,
579 TLI.getShiftAmountTy(
Value.getValueType(),
DL)));
580 Hi = DAG.getTruncStore(Chain, dl,
Hi,
Ptr,
581 ST->getPointerInfo().getWithOffset(IncrementSize),
582 ExtraVT,
ST->getOriginalAlign(), MMOFlags, AAInfo);
589 DAG.getConstant(ExtraWidth, dl,
590 TLI.getShiftAmountTy(
Value.getValueType(),
DL)));
591 Hi = DAG.getTruncStore(Chain, dl,
Hi,
Ptr,
ST->getPointerInfo(), RoundVT,
592 ST->getOriginalAlign(), MMOFlags, AAInfo);
595 IncrementSize = RoundWidth / 8;
597 DAG.getConstant(IncrementSize, dl,
598 Ptr.getValueType()));
600 ST->getPointerInfo().getWithOffset(IncrementSize),
601 ExtraVT,
ST->getOriginalAlign(), MMOFlags, AAInfo);
608 switch (TLI.getTruncStoreAction(
ST->getValue().getValueType(), StVT)) {
610 case TargetLowering::Legal: {
611 EVT MemVT =
ST->getMemoryVT();
614 if (!TLI.allowsMemoryAccessForAlignment(*DAG.getContext(),
DL, MemVT,
615 *
ST->getMemOperand())) {
617 ReplaceNode(
SDValue(ST, 0), Result);
621 case TargetLowering::Custom: {
627 case TargetLowering::Expand:
629 "Vector Stores are handled in LegalizeVectorOps");
634 if (TLI.isTypeLegal(StVT)) {
637 ST->getOriginalAlign(), MMOFlags, AAInfo);
642 TLI.getTypeToTransformTo(*DAG.getContext(), StVT),
645 DAG.getTruncStore(Chain, dl,
Value,
Ptr,
ST->getPointerInfo(), StVT,
646 ST->getOriginalAlign(), MMOFlags, AAInfo);
655void SelectionDAGLegalize::LegalizeLoadOps(
SDNode *
Node) {
664 LLVM_DEBUG(
dbgs() <<
"Legalizing non-extending load operation\n");
665 MVT VT =
Node->getSimpleValueType(0);
669 switch (TLI.getOperationAction(
Node->getOpcode(), VT)) {
671 case TargetLowering::Legal: {
672 EVT MemVT =
LD->getMemoryVT();
676 if (!TLI.allowsMemoryAccessForAlignment(*DAG.getContext(),
DL, MemVT,
677 *
LD->getMemOperand())) {
678 std::tie(RVal, RChain) = TLI.expandUnalignedLoad(LD, DAG);
682 case TargetLowering::Custom:
683 if (
SDValue Res = TLI.LowerOperation(RVal, DAG)) {
689 case TargetLowering::Promote: {
690 MVT NVT = TLI.getTypeToPromoteTo(
Node->getOpcode(), VT);
692 "Can only promote loads to same size type");
694 SDValue Res = DAG.getLoad(NVT, dl, Chain,
Ptr,
LD->getMemOperand());
702 DAG.ReplaceAllUsesOfValueWith(
SDValue(
Node, 0), RVal);
703 DAG.ReplaceAllUsesOfValueWith(
SDValue(
Node, 1), RChain);
705 UpdatedNodes->insert(RVal.
getNode());
706 UpdatedNodes->insert(RChain.
getNode());
714 EVT SrcVT =
LD->getMemoryVT();
728 TLI.getLoadExtAction(ExtType,
Node->getValueType(0), MVT::i1) ==
729 TargetLowering::Promote)) {
743 Chain,
Ptr,
LD->getPointerInfo(), NVT,
744 LD->getOriginalAlign(), MMOFlags, AAInfo);
752 Result, DAG.getValueType(SrcVT));
756 Result.getValueType(), Result,
757 DAG.getValueType(SrcVT));
765 unsigned LogSrcWidth =
Log2_32(SrcWidthBits);
767 unsigned RoundWidth = 1 << LogSrcWidth;
768 assert(RoundWidth < SrcWidthBits);
769 unsigned ExtraWidth = SrcWidthBits - RoundWidth;
770 assert(ExtraWidth < RoundWidth);
771 assert(!(RoundWidth % 8) && !(ExtraWidth % 8) &&
772 "Load size not an integral number of bytes!");
776 unsigned IncrementSize;
777 auto &
DL = DAG.getDataLayout();
779 if (
DL.isLittleEndian()) {
783 LD->getPointerInfo(), RoundVT,
LD->getOriginalAlign(),
787 IncrementSize = RoundWidth / 8;
790 Hi = DAG.getExtLoad(ExtType, dl,
Node->getValueType(0), Chain,
Ptr,
791 LD->getPointerInfo().getWithOffset(IncrementSize),
792 ExtraVT,
LD->getOriginalAlign(), MMOFlags, AAInfo);
802 DAG.getConstant(RoundWidth, dl,
803 TLI.getShiftAmountTy(
Hi.getValueType(),
DL)));
811 Hi = DAG.getExtLoad(ExtType, dl,
Node->getValueType(0), Chain,
Ptr,
812 LD->getPointerInfo(), RoundVT,
LD->getOriginalAlign(),
816 IncrementSize = RoundWidth / 8;
820 LD->getPointerInfo().getWithOffset(IncrementSize),
821 ExtraVT,
LD->getOriginalAlign(), MMOFlags, AAInfo);
831 DAG.getConstant(ExtraWidth, dl,
832 TLI.getShiftAmountTy(
Hi.getValueType(),
DL)));
840 bool isCustom =
false;
841 switch (TLI.getLoadExtAction(ExtType,
Node->getValueType(0),
844 case TargetLowering::Custom:
847 case TargetLowering::Legal:
859 EVT MemVT =
LD->getMemoryVT();
861 if (!TLI.allowsMemoryAccess(*DAG.getContext(),
DL, MemVT,
862 *
LD->getMemOperand())) {
863 std::tie(
Value, Chain) = TLI.expandUnalignedLoad(LD, DAG);
868 case TargetLowering::Expand: {
869 EVT DestVT =
Node->getValueType(0);
875 (TLI.isTypeLegal(SrcVT) ||
876 TLI.isLoadExtLegal(ExtType, LoadVT, SrcVT))) {
883 SrcVT,
LD->getMemOperand());
886 Value = DAG.getNode(ExtendOp, dl,
Node->getValueType(0), Load);
887 Chain =
Load.getValue(1);
896 if (SVT == MVT::f16 || SVT == MVT::bf16) {
902 Ptr, ISrcVT,
LD->getMemOperand());
906 Chain =
Result.getValue(1);
912 "Vector Loads are handled in LegalizeVectorOps");
919 "EXTLOAD should always be supported!");
923 Node->getValueType(0),
925 LD->getMemOperand());
930 Result, DAG.getValueType(SrcVT));
932 ValRes = DAG.getZeroExtendInReg(Result, dl, SrcVT);
934 Chain =
Result.getValue(1);
945 DAG.ReplaceAllUsesOfValueWith(
SDValue(
Node, 1), Chain);
947 UpdatedNodes->insert(
Value.getNode());
948 UpdatedNodes->insert(Chain.
getNode());
955void SelectionDAGLegalize::LegalizeOp(
SDNode *
Node) {
964 for (
unsigned i = 0, e =
Node->getNumValues(); i != e; ++i)
965 assert(TLI.getTypeAction(*DAG.getContext(),
Node->getValueType(i)) ==
966 TargetLowering::TypeLegal &&
967 "Unexpected illegal type!");
970 assert((TLI.getTypeAction(*DAG.getContext(),
Op.getValueType()) ==
971 TargetLowering::TypeLegal ||
974 "Unexpected illegal type!");
979 bool SimpleFinishLegalizing =
true;
980 switch (
Node->getOpcode()) {
985 Action = TLI.getOperationAction(
Node->getOpcode(), MVT::Other);
988 Action = TLI.getOperationAction(
Node->getOpcode(),
989 Node->getValueType(0));
992 Action = TLI.getOperationAction(
Node->getOpcode(),
993 Node->getValueType(0));
994 if (Action != TargetLowering::Promote)
995 Action = TLI.getOperationAction(
Node->getOpcode(), MVT::Other);
999 Action = TLI.getOperationAction(
Node->getOpcode(),
1000 Node->getOperand(1).getValueType());
1011 Action = TLI.getOperationAction(
Node->getOpcode(),
1012 Node->getOperand(0).getValueType());
1025 Action = TLI.getOperationAction(
Node->getOpcode(),
1026 Node->getOperand(1).getValueType());
1029 EVT InnerType = cast<VTSDNode>(
Node->getOperand(1))->getVT();
1030 Action = TLI.getOperationAction(
Node->getOpcode(), InnerType);
1034 Action = TLI.getOperationAction(
Node->getOpcode(),
1035 Node->getOperand(1).getValueType());
1044 unsigned Opc =
Node->getOpcode();
1049 : (Opc ==
ISD::SETCC || Opc == ISD::VP_SETCC) ? 2
1051 unsigned CompareOperand = Opc ==
ISD::BR_CC ? 2
1055 MVT OpVT =
Node->getOperand(CompareOperand).getSimpleValueType();
1057 cast<CondCodeSDNode>(
Node->getOperand(CCOperand))->get();
1058 Action = TLI.getCondCodeAction(CCCode, OpVT);
1059 if (Action == TargetLowering::Legal) {
1061 Action = TLI.getOperationAction(
Node->getOpcode(),
1062 Node->getValueType(0));
1064 Action = TLI.getOperationAction(
Node->getOpcode(), OpVT);
1072 SimpleFinishLegalizing =
false;
1079 SimpleFinishLegalizing =
false;
1092 Action = TLI.getOperationAction(
Node->getOpcode(),
Node->getValueType(0));
1093 if (Action == TargetLowering::Legal)
1094 Action = TargetLowering::Expand;
1104 Action = TLI.getOperationAction(
Node->getOpcode(),
Node->getValueType(0));
1105 if (Action == TargetLowering::Legal)
1106 Action = TargetLowering::Custom;
1111 Action = TLI.getOperationAction(
Node->getOpcode(),
Node->getValueType(0));
1117 Action = TLI.getOperationAction(
Node->getOpcode(), MVT::i64);
1124 Action = TargetLowering::Legal;
1127 Action = TLI.getOperationAction(
Node->getOpcode(),
Node->getValueType(0));
1128 if (Action == TargetLowering::Expand) {
1132 Node->getOperand(0));
1139 Action = TLI.getOperationAction(
Node->getOpcode(),
Node->getValueType(0));
1140 if (Action == TargetLowering::Expand) {
1144 Node->getOperand(0));
1160 Action = TLI.getOperationAction(
Node->getOpcode(),
Node->getValueType(0));
1170 unsigned Scale =
Node->getConstantOperandVal(2);
1171 Action = TLI.getFixedPointOperationAction(
Node->getOpcode(),
1172 Node->getValueType(0), Scale);
1176 Action = TLI.getOperationAction(
Node->getOpcode(),
1177 cast<MaskedScatterSDNode>(
Node)->getValue().getValueType());
1180 Action = TLI.getOperationAction(
Node->getOpcode(),
1181 cast<MaskedStoreSDNode>(
Node)->getValue().getValueType());
1183 case ISD::VP_SCATTER:
1184 Action = TLI.getOperationAction(
1186 cast<VPScatterSDNode>(
Node)->getValue().getValueType());
1189 Action = TLI.getOperationAction(
1191 cast<VPStoreSDNode>(
Node)->getValue().getValueType());
1193 case ISD::EXPERIMENTAL_VP_STRIDED_STORE:
1194 Action = TLI.getOperationAction(
1196 cast<VPStridedStoreSDNode>(
Node)->getValue().getValueType());
1214 Action = TLI.getOperationAction(
1215 Node->getOpcode(),
Node->getOperand(0).getValueType());
1219 case ISD::VP_REDUCE_FADD:
1220 case ISD::VP_REDUCE_FMUL:
1221 case ISD::VP_REDUCE_ADD:
1222 case ISD::VP_REDUCE_MUL:
1223 case ISD::VP_REDUCE_AND:
1224 case ISD::VP_REDUCE_OR:
1225 case ISD::VP_REDUCE_XOR:
1226 case ISD::VP_REDUCE_SMAX:
1227 case ISD::VP_REDUCE_SMIN:
1228 case ISD::VP_REDUCE_UMAX:
1229 case ISD::VP_REDUCE_UMIN:
1230 case ISD::VP_REDUCE_FMAX:
1231 case ISD::VP_REDUCE_FMIN:
1232 case ISD::VP_REDUCE_FMAXIMUM:
1233 case ISD::VP_REDUCE_FMINIMUM:
1234 case ISD::VP_REDUCE_SEQ_FADD:
1235 case ISD::VP_REDUCE_SEQ_FMUL:
1236 Action = TLI.getOperationAction(
1237 Node->getOpcode(),
Node->getOperand(1).getValueType());
1239 case ISD::VP_CTTZ_ELTS:
1240 case ISD::VP_CTTZ_ELTS_ZERO_UNDEF:
1241 Action = TLI.getOperationAction(
Node->getOpcode(),
1242 Node->getOperand(0).getValueType());
1246 Action = TLI.getCustomOperationAction(*
Node);
1248 Action = TLI.getOperationAction(
Node->getOpcode(),
Node->getValueType(0));
1253 if (SimpleFinishLegalizing) {
1255 switch (
Node->getOpcode()) {
1274 NewNode = DAG.UpdateNodeOperands(
Node, Op0, SAO);
1294 NewNode = DAG.UpdateNodeOperands(
Node, Op0, Op1, SAO);
1300 if (NewNode !=
Node) {
1301 ReplaceNode(
Node, NewNode);
1305 case TargetLowering::Legal:
1308 case TargetLowering::Custom:
1316 if (
Node->getNumValues() == 1) {
1320 Node->getValueType(0) == MVT::Glue) &&
1321 "Type mismatch for custom legalized operation");
1329 for (
unsigned i = 0, e =
Node->getNumValues(); i != e; ++i) {
1333 Node->getValueType(i) == MVT::Glue) &&
1334 "Type mismatch for custom legalized operation");
1338 ReplaceNode(
Node, ResultVals.
data());
1343 case TargetLowering::Expand:
1344 if (ExpandNode(
Node))
1347 case TargetLowering::LibCall:
1348 ConvertNodeToLibcall(
Node);
1350 case TargetLowering::Promote:
1356 switch (
Node->getOpcode()) {
1369 return LegalizeLoadOps(
Node);
1371 return LegalizeStoreOps(
Node);
1375SDValue SelectionDAGLegalize::ExpandExtractFromVectorThroughStack(
SDValue Op) {
1395 if (
ST->isIndexed() ||
ST->isTruncatingStore() ||
1396 ST->getValue() != Vec)
1401 if (!
ST->getChain().reachesChainWithoutSideEffects(DAG.getEntryNode()))
1410 ST->hasPredecessor(
Op.getNode()))
1423 StackPtr = DAG.CreateStackTemporary(VecVT);
1426 Ch = DAG.getStore(DAG.getEntryNode(), dl, Vec, StackPtr, StoreMMO);
1430 Align ElementAlignment =
1431 std::min(cast<StoreSDNode>(Ch)->
getAlign(),
1432 DAG.getDataLayout().getPrefTypeAlign(
1433 Op.getValueType().getTypeForEVT(*DAG.getContext())));
1435 if (
Op.getValueType().isVector()) {
1436 StackPtr = TLI.getVectorSubVecPointer(DAG, StackPtr, VecVT,
1437 Op.getValueType(),
Idx);
1438 NewLoad = DAG.getLoad(
Op.getValueType(), dl, Ch, StackPtr,
1441 StackPtr = TLI.getVectorElementPointer(DAG, StackPtr, VecVT,
Idx);
1442 NewLoad = DAG.getExtLoad(
ISD::EXTLOAD, dl,
Op.getValueType(), Ch, StackPtr,
1448 DAG.ReplaceAllUsesOfValueWith(Ch,
SDValue(NewLoad.
getNode(), 1));
1453 NewLoadOperands[0] = Ch;
1455 SDValue(DAG.UpdateNodeOperands(NewLoad.
getNode(), NewLoadOperands), 0);
1459SDValue SelectionDAGLegalize::ExpandInsertToVectorThroughStack(
SDValue Op) {
1460 assert(
Op.getValueType().isVector() &&
"Non-vector insert subvector!");
1471 int FI = cast<FrameIndexSDNode>(
StackPtr.getNode())->getIndex();
1476 Align BaseVecAlignment =
1477 DAG.getMachineFunction().getFrameInfo().getObjectAlign(FI);
1478 SDValue Ch = DAG.getStore(DAG.getEntryNode(), dl, Vec, StackPtr, PtrInfo,
1482 Idx = DAG.getFreeze(
Idx);
1485 Align PartAlignment = DAG.getDataLayout().getPrefTypeAlign(PartTy);
1490 TLI.getVectorSubVecPointer(DAG, StackPtr, VecVT, PartVT,
Idx);
1494 Ch, dl, Part, SubStackPtr,
1499 TLI.getVectorElementPointer(DAG, StackPtr, VecVT,
Idx);
1502 Ch = DAG.getTruncStore(
1503 Ch, dl, Part, SubStackPtr,
1509 "ElementAlignment does not match!");
1512 return DAG.getLoad(
Op.getValueType(), dl, Ch, StackPtr, PtrInfo,
1519 "Unexpected opcode!");
1525 EVT VT =
Node->getValueType(0);
1527 :
Node->getOperand(0).getValueType();
1529 SDValue FIPtr = DAG.CreateStackTemporary(VT);
1530 int FI = cast<FrameIndexSDNode>(FIPtr.
getNode())->getIndex();
1537 assert(TypeByteSize > 0 &&
"Vector element type too small for stack store!");
1541 bool Truncate = isa<BuildVectorSDNode>(
Node) &&
1542 MemVT.
bitsLT(
Node->getOperand(0).getValueType());
1545 for (
unsigned i = 0, e =
Node->getNumOperands(); i != e; ++i) {
1547 if (
Node->getOperand(i).isUndef())
continue;
1549 unsigned Offset = TypeByteSize*i;
1555 Stores.
push_back(DAG.getTruncStore(DAG.getEntryNode(), dl,
1559 Stores.
push_back(DAG.getStore(DAG.getEntryNode(), dl,
Node->getOperand(i),
1564 if (!Stores.
empty())
1567 StoreChain = DAG.getEntryNode();
1570 return DAG.getLoad(VT, dl, StoreChain, FIPtr, PtrInfo);
1576void SelectionDAGLegalize::getSignAsIntValue(FloatSignAsInt &State,
1579 EVT FloatVT =
Value.getValueType();
1581 State.FloatVT = FloatVT;
1584 if (TLI.isTypeLegal(IVT)) {
1587 State.SignBit = NumBits - 1;
1593 MVT LoadTy = TLI.getRegisterType(MVT::i8);
1596 int FI = cast<FrameIndexSDNode>(
StackPtr.getNode())->getIndex();
1601 State.Chain = DAG.getStore(DAG.getEntryNode(),
DL,
Value, State.FloatPtr,
1602 State.FloatPointerInfo);
1609 State.IntPointerInfo = State.FloatPointerInfo;
1612 unsigned ByteOffset = (NumBits / 8) - 1;
1619 State.IntPtr = IntPtr;
1620 State.IntValue = DAG.getExtLoad(
ISD::EXTLOAD,
DL, LoadTy, State.Chain, IntPtr,
1621 State.IntPointerInfo, MVT::i8);
1628SDValue SelectionDAGLegalize::modifySignAsInt(
const FloatSignAsInt &State,
1635 SDValue Chain = DAG.getTruncStore(State.Chain,
DL, NewIntValue, State.IntPtr,
1636 State.IntPointerInfo, MVT::i8);
1637 return DAG.getLoad(State.FloatVT,
DL, Chain, State.FloatPtr,
1638 State.FloatPointerInfo);
1647 FloatSignAsInt SignAsInt;
1648 getSignAsIntValue(SignAsInt,
DL, Sign);
1650 EVT IntVT = SignAsInt.IntValue.getValueType();
1651 SDValue SignMask = DAG.getConstant(SignAsInt.SignMask,
DL, IntVT);
1657 if (TLI.isOperationLegalOrCustom(
ISD::FABS, FloatVT) &&
1658 TLI.isOperationLegalOrCustom(
ISD::FNEG, FloatVT)) {
1661 SDValue Cond = DAG.getSetCC(
DL, getSetCCResultType(IntVT), SignBit,
1663 return DAG.getSelect(
DL, FloatVT,
Cond, NegValue, AbsValue);
1667 FloatSignAsInt MagAsInt;
1668 getSignAsIntValue(MagAsInt,
DL, Mag);
1669 EVT MagVT = MagAsInt.IntValue.getValueType();
1670 SDValue ClearSignMask = DAG.getConstant(~MagAsInt.SignMask,
DL, MagVT);
1675 int ShiftAmount = SignAsInt.SignBit - MagAsInt.SignBit;
1676 EVT ShiftVT = IntVT;
1682 if (ShiftAmount > 0) {
1683 SDValue ShiftCnst = DAG.getConstant(ShiftAmount,
DL, ShiftVT);
1685 }
else if (ShiftAmount < 0) {
1686 SDValue ShiftCnst = DAG.getConstant(-ShiftAmount,
DL, ShiftVT);
1695 Flags.setDisjoint(
true);
1701 return modifySignAsInt(MagAsInt,
DL, CopiedSign);
1707 FloatSignAsInt SignAsInt;
1708 getSignAsIntValue(SignAsInt,
DL,
Node->getOperand(0));
1709 EVT IntVT = SignAsInt.IntValue.getValueType();
1712 SDValue SignMask = DAG.getConstant(SignAsInt.SignMask,
DL, IntVT);
1717 return modifySignAsInt(SignAsInt,
DL, SignFlip);
1725 EVT FloatVT =
Value.getValueType();
1732 FloatSignAsInt ValueAsInt;
1733 getSignAsIntValue(ValueAsInt,
DL,
Value);
1734 EVT IntVT = ValueAsInt.IntValue.getValueType();
1735 SDValue ClearSignMask = DAG.getConstant(~ValueAsInt.SignMask,
DL, IntVT);
1738 return modifySignAsInt(ValueAsInt,
DL, ClearedSign);
1741void SelectionDAGLegalize::ExpandDYNAMIC_STACKALLOC(
SDNode*
Node,
1743 Register SPReg = TLI.getStackPointerRegisterToSaveRestore();
1744 assert(SPReg &&
"Target cannot require DYNAMIC_STACKALLOC expansion and"
1745 " not tell us which reg is the stack pointer!");
1747 EVT VT =
Node->getValueType(0);
1755 Chain = DAG.getCALLSEQ_START(Chain, 0, 0, dl);
1758 SDValue SP = DAG.getCopyFromReg(Chain, dl, SPReg, VT);
1760 Align Alignment = cast<ConstantSDNode>(Tmp3)->getAlignValue();
1768 if (Alignment > StackAlign)
1770 DAG.getConstant(-Alignment.
value(), dl, VT));
1771 Chain = DAG.getCopyToReg(Chain, dl, SPReg, Tmp1);
1773 Tmp2 = DAG.getCALLSEQ_END(Chain, 0, 0,
SDValue(), dl);
1785 return EmitStackConvert(
SrcOp, SlotVT, DestVT, dl, DAG.getEntryNode());
1793 Align DestAlign = DAG.getDataLayout().getPrefTypeAlign(DestType);
1796 if ((SrcVT.
bitsGT(SlotVT) &&
1797 !TLI.isTruncStoreLegalOrCustom(
SrcOp.getValueType(), SlotVT)) ||
1798 (SlotVT.
bitsLT(DestVT) &&
1799 !TLI.isLoadExtLegalOrCustom(
ISD::EXTLOAD, DestVT, SlotVT)))
1803 Align SrcAlign = DAG.getDataLayout().getPrefTypeAlign(
1804 SrcOp.getValueType().getTypeForEVT(*DAG.getContext()));
1816 if (SrcVT.
bitsGT(SlotVT))
1817 Store = DAG.getTruncStore(Chain, dl,
SrcOp, FIPtr, PtrInfo,
1821 Store = DAG.getStore(Chain, dl,
SrcOp, FIPtr, PtrInfo, SrcAlign);
1825 if (SlotVT.
bitsEq(DestVT))
1826 return DAG.getLoad(DestVT, dl, Store, FIPtr, PtrInfo, DestAlign);
1829 return DAG.getExtLoad(
ISD::EXTLOAD, dl, DestVT, Store, FIPtr, PtrInfo, SlotVT,
1842 SDValue Ch = DAG.getTruncStore(
1843 DAG.getEntryNode(), dl,
Node->getOperand(0), StackPtr,
1845 Node->getValueType(0).getVectorElementType());
1847 Node->getValueType(0), dl, Ch, StackPtr,
1854 unsigned NumElems =
Node->getNumOperands();
1856 EVT VT =
Node->getValueType(0);
1868 for (
unsigned i = 0; i < NumElems; ++i) {
1879 while (IntermedVals.
size() > 2) {
1880 NewIntermedVals.
clear();
1881 for (
unsigned i = 0, e = (IntermedVals.
size() & ~1u); i < e; i += 2) {
1887 FinalIndices.
reserve(IntermedVals[i].second.
size() +
1888 IntermedVals[i+1].second.
size());
1891 for (
unsigned j = 0, f = IntermedVals[i].second.
size(); j != f;
1894 FinalIndices.
push_back(IntermedVals[i].second[j]);
1896 for (
unsigned j = 0, f = IntermedVals[i+1].second.
size(); j != f;
1898 ShuffleVec[k] = NumElems + j;
1899 FinalIndices.
push_back(IntermedVals[i+1].second[j]);
1905 IntermedVals[i+1].first,
1910 std::make_pair(Shuffle, std::move(FinalIndices)));
1915 if ((IntermedVals.
size() & 1) != 0)
1918 IntermedVals.
swap(NewIntermedVals);
1922 "Invalid number of intermediate vectors");
1923 SDValue Vec1 = IntermedVals[0].first;
1925 if (IntermedVals.
size() > 1)
1926 Vec2 = IntermedVals[1].first;
1931 for (
unsigned i = 0, e = IntermedVals[0].second.
size(); i != e; ++i)
1932 ShuffleVec[IntermedVals[0].second[i]] = i;
1933 for (
unsigned i = 0, e = IntermedVals[1].second.
size(); i != e; ++i)
1934 ShuffleVec[IntermedVals[1].second[i]] = NumElems + i;
1948 unsigned NumElems =
Node->getNumOperands();
1951 EVT VT =
Node->getValueType(0);
1952 EVT OpVT =
Node->getOperand(0).getValueType();
1957 bool isOnlyLowElement =
true;
1958 bool MoreThanTwoValues =
false;
1960 for (
unsigned i = 0; i < NumElems; ++i) {
1965 isOnlyLowElement =
false;
1966 if (!isa<ConstantFPSDNode>(V) && !isa<ConstantSDNode>(V))
1971 }
else if (!Value2.
getNode()) {
1974 }
else if (V != Value1 && V != Value2) {
1975 MoreThanTwoValues =
true;
1980 return DAG.getUNDEF(VT);
1982 if (isOnlyLowElement)
1988 for (
unsigned i = 0, e = NumElems; i !=
e; ++i) {
1990 dyn_cast<ConstantFPSDNode>(
Node->getOperand(i))) {
1993 dyn_cast<ConstantSDNode>(
Node->getOperand(i))) {
2012 DAG.getConstantPool(CP, TLI.getPointerTy(DAG.getDataLayout()));
2013 Align Alignment = cast<ConstantPoolSDNode>(CPIdx)->getAlign();
2015 VT, dl, DAG.getEntryNode(), CPIdx,
2021 for (
unsigned i = 0; i < NumElems; ++i) {
2022 if (
Node->getOperand(i).isUndef())
2027 if (TLI.shouldExpandBuildVectorWithShuffles(VT, DefinedValues.
size())) {
2028 if (!MoreThanTwoValues) {
2030 for (
unsigned i = 0; i < NumElems; ++i) {
2034 ShuffleVec[i] =
V == Value1 ? 0 : NumElems;
2036 if (TLI.isShuffleMaskLegal(ShuffleVec,
Node->getValueType(0))) {
2043 Vec2 = DAG.getUNDEF(VT);
2046 return DAG.getVectorShuffle(VT, dl, Vec1, Vec2, ShuffleVec);
2056 return ExpandVectorBuildThroughStack(
Node);
2061 EVT VT =
Node->getValueType(0);
2064 return DAG.getSplatBuildVector(VT,
DL, SplatVal);
2075 EVT CodePtrTy = TLI.getPointerTy(DAG.getDataLayout());
2077 if (
const char *LibcallName = TLI.getLibcallName(LC))
2078 Callee = DAG.getExternalSymbol(LibcallName, CodePtrTy);
2080 Callee = DAG.getUNDEF(CodePtrTy);
2081 DAG.getContext()->emitError(
Twine(
"no libcall available for ") +
2082 Node->getOperationName(&DAG));
2085 EVT RetVT =
Node->getValueType(0);
2092 SDValue InChain = DAG.getEntryNode();
2097 const Function &
F = DAG.getMachineFunction().getFunction();
2099 TLI.isInTailCallPosition(DAG,
Node, TCChain) &&
2100 (
RetTy ==
F.getReturnType() ||
F.getReturnType()->isVoidTy());
2105 bool signExtend = TLI.shouldSignExtendTypeInLibCall(RetVT,
isSigned);
2108 .setLibCallee(TLI.getLibcallCallingConv(LC),
RetTy, Callee,
2110 .setTailCall(isTailCall)
2111 .setSExtResult(signExtend)
2112 .setZExtResult(!signExtend)
2113 .setIsPostTypeLegalization(
true);
2115 std::pair<SDValue, SDValue>
CallInfo = TLI.LowerCallTo(CLI);
2120 return {DAG.getRoot(), DAG.getRoot()};
2132 EVT ArgVT =
Op.getValueType();
2136 Entry.IsSExt = TLI.shouldSignExtendTypeInLibCall(ArgVT,
isSigned);
2138 Args.push_back(Entry);
2141 return ExpandLibCall(LC,
Node, std::move(Args),
isSigned);
2144void SelectionDAGLegalize::ExpandFrexpLibCall(
2147 EVT VT =
Node->getValueType(0);
2148 EVT ExpVT =
Node->getValueType(1);
2156 FPArgEntry.
Node = FPOp;
2157 FPArgEntry.
Ty = ArgTy;
2159 SDValue StackSlot = DAG.CreateStackTemporary(ExpVT);
2161 PtrArgEntry.
Node = StackSlot;
2162 PtrArgEntry.
Ty = PointerType::get(*DAG.getContext(),
2163 DAG.getDataLayout().getAllocaAddrSpace());
2168 auto [
Call, Chain] = ExpandLibCall(LC,
Node, std::move(Args),
false);
2172 int FrameIdx = cast<FrameIndexSDNode>(StackSlot)->getIndex();
2176 SDValue LoadExp = DAG.getLoad(ExpVT, dl, Chain, StackSlot, PtrInfo);
2178 LoadExp.
getValue(1), DAG.getRoot());
2179 DAG.setRoot(OutputChain);
2185void SelectionDAGLegalize::ExpandFPLibCall(
SDNode*
Node,
2188 if (LC == RTLIB::UNKNOWN_LIBCALL)
2191 if (
Node->isStrictFPOpcode()) {
2192 EVT RetVT =
Node->getValueType(0);
2196 std::pair<SDValue, SDValue> Tmp = TLI.makeLibCall(DAG, LC, RetVT,
2199 Node->getOperand(0));
2201 Results.push_back(Tmp.second);
2203 SDValue Tmp = ExpandLibCall(LC,
Node,
false).first;
2209void SelectionDAGLegalize::ExpandFPLibCall(
SDNode*
Node,
2217 Call_F32, Call_F64, Call_F80,
2218 Call_F128, Call_PPCF128);
2229 switch (
Node->getSimpleValueType(0).SimpleTy) {
2231 case MVT::i8: LC = Call_I8;
break;
2232 case MVT::i16: LC = Call_I16;
break;
2233 case MVT::i32: LC = Call_I32;
break;
2234 case MVT::i64: LC = Call_I64;
break;
2235 case MVT::i128: LC = Call_I128;
break;
2242void SelectionDAGLegalize::ExpandArgFPLibCall(
SDNode*
Node,
2249 EVT InVT =
Node->getOperand(
Node->isStrictFPOpcode() ? 1 : 0).getValueType();
2251 Call_F32, Call_F64, Call_F80,
2252 Call_F128, Call_PPCF128);
2258SelectionDAGLegalize::ExpandDivRemLibCall(
SDNode *
Node,
2260 unsigned Opcode =
Node->getOpcode();
2264 switch (
Node->getSimpleValueType(0).SimpleTy) {
2266 case MVT::i8: LC=
isSigned ? RTLIB::SDIVREM_I8 : RTLIB::UDIVREM_I8;
break;
2267 case MVT::i16: LC=
isSigned ? RTLIB::SDIVREM_I16 : RTLIB::UDIVREM_I16;
break;
2268 case MVT::i32: LC=
isSigned ? RTLIB::SDIVREM_I32 : RTLIB::UDIVREM_I32;
break;
2269 case MVT::i64: LC=
isSigned ? RTLIB::SDIVREM_I64 : RTLIB::UDIVREM_I64;
break;
2270 case MVT::i128: LC=
isSigned ? RTLIB::SDIVREM_I128:RTLIB::UDIVREM_I128;
break;
2276 SDValue InChain = DAG.getEntryNode();
2278 EVT RetVT =
Node->getValueType(0);
2284 EVT ArgVT =
Op.getValueType();
2290 Args.push_back(Entry);
2294 SDValue FIPtr = DAG.CreateStackTemporary(RetVT);
2296 Entry.Ty = PointerType::getUnqual(
RetTy->getContext());
2299 Args.push_back(Entry);
2301 SDValue Callee = DAG.getExternalSymbol(TLI.getLibcallName(LC),
2302 TLI.getPointerTy(DAG.getDataLayout()));
2308 .setLibCallee(TLI.getLibcallCallingConv(LC),
RetTy, Callee,
2313 std::pair<SDValue, SDValue>
CallInfo = TLI.LowerCallTo(CLI);
2325 switch (
Node->getSimpleValueType(0).SimpleTy) {
2327 case MVT::f32: LC = RTLIB::SINCOS_F32;
break;
2328 case MVT::f64: LC = RTLIB::SINCOS_F64;
break;
2329 case MVT::f80: LC = RTLIB::SINCOS_F80;
break;
2330 case MVT::f128: LC = RTLIB::SINCOS_F128;
break;
2331 case MVT::ppcf128: LC = RTLIB::SINCOS_PPCF128;
break;
2354SelectionDAGLegalize::ExpandSinCosLibCall(
SDNode *
Node,
2357 switch (
Node->getSimpleValueType(0).SimpleTy) {
2359 case MVT::f32: LC = RTLIB::SINCOS_F32;
break;
2360 case MVT::f64: LC = RTLIB::SINCOS_F64;
break;
2361 case MVT::f80: LC = RTLIB::SINCOS_F80;
break;
2362 case MVT::f128: LC = RTLIB::SINCOS_F128;
break;
2363 case MVT::ppcf128: LC = RTLIB::SINCOS_PPCF128;
break;
2369 SDValue InChain = DAG.getEntryNode();
2371 EVT RetVT =
Node->getValueType(0);
2380 Entry.IsSExt =
false;
2381 Entry.IsZExt =
false;
2382 Args.push_back(Entry);
2385 SDValue SinPtr = DAG.CreateStackTemporary(RetVT);
2386 Entry.Node = SinPtr;
2387 Entry.Ty = PointerType::getUnqual(
RetTy->getContext());
2388 Entry.IsSExt =
false;
2389 Entry.IsZExt =
false;
2390 Args.push_back(Entry);
2393 SDValue CosPtr = DAG.CreateStackTemporary(RetVT);
2394 Entry.Node = CosPtr;
2395 Entry.Ty = PointerType::getUnqual(
RetTy->getContext());
2396 Entry.IsSExt =
false;
2397 Entry.IsZExt =
false;
2398 Args.push_back(Entry);
2400 SDValue Callee = DAG.getExternalSymbol(TLI.getLibcallName(LC),
2401 TLI.getPointerTy(DAG.getDataLayout()));
2405 CLI.setDebugLoc(dl).setChain(InChain).setLibCallee(
2406 TLI.getLibcallCallingConv(LC),
Type::getVoidTy(*DAG.getContext()), Callee,
2409 std::pair<SDValue, SDValue>
CallInfo = TLI.LowerCallTo(CLI);
2419 EVT VT =
Node->getValueType(0);
2422 EVT ExpVT =
N.getValueType();
2424 if (AsIntVT ==
EVT())
2437 TLI.getSetCCResultType(DAG.getDataLayout(), *DAG.getContext(), ExpVT);
2442 const int Precision = APFloat::semanticsPrecision(FltSem);
2444 const SDValue MaxExp = DAG.getConstant(MaxExpVal, dl, ExpVT);
2445 const SDValue MinExp = DAG.getConstant(MinExpVal, dl, ExpVT);
2447 const SDValue DoubleMaxExp = DAG.getConstant(2 * MaxExpVal, dl, ExpVT);
2449 const APFloat One(FltSem,
"1.0");
2450 APFloat ScaleUpK =
scalbn(One, MaxExpVal, APFloat::rmNearestTiesToEven);
2454 scalbn(One, MinExpVal + Precision, APFloat::rmNearestTiesToEven);
2463 SDValue ClampMaxVal = DAG.getConstant(3 * MaxExpVal, dl, ExpVT);
2469 DAG.getSetCC(dl, SetCCVT,
N, DoubleMaxExp,
ISD::SETUGT);
2471 const SDValue ScaleUpVal = DAG.getConstantFP(ScaleUpK, dl, VT);
2483 SDValue Increment0 = DAG.getConstant(-(MinExpVal + Precision), dl, ExpVT);
2484 SDValue Increment1 = DAG.getConstant(-2 * (MinExpVal + Precision), dl, ExpVT);
2489 DAG.getConstant(3 * MinExpVal + 2 * Precision, dl, ExpVT);
2494 const SDValue ScaleDownVal = DAG.getConstantFP(ScaleDownK, dl, VT);
2498 SDValue ScaleDownTwice = DAG.getSetCC(
2499 dl, SetCCVT,
N, DAG.getConstant(2 * MinExpVal + Precision, dl, ExpVT),
2511 DAG.getNode(
ISD::SELECT, dl, VT, NLtMinExp, SelectX_Small,
X));
2515 DAG.getNode(
ISD::SELECT, dl, ExpVT, NLtMinExp, SelectN_Small,
N));
2520 DAG.getShiftAmountConstant(Precision - 1, ExpVT, dl);
2521 SDValue CastExpToValTy = DAG.getZExtOrTrunc(BiasedN, dl, AsIntVT);
2524 ExponentShiftAmt, NUW_NSW);
2526 return DAG.getNode(
ISD::FMUL, dl, VT, NewX, AsFP);
2533 EVT ExpVT =
Node->getValueType(1);
2535 if (AsIntVT ==
EVT())
2540 const unsigned Precision = APFloat::semanticsPrecision(FltSem);
2557 SDValue NegSmallestNormalizedInt = DAG.getConstant(
2561 SDValue SmallestNormalizedInt = DAG.getConstant(
2567 DAG.getConstant(
APFloat::getInf(FltSem).bitcastToAPInt(), dl, AsIntVT);
2573 FractSignMaskVal.
setBit(BitSize - 1);
2576 SDValue SignMask = DAG.getConstant(SignMaskVal, dl, AsIntVT);
2578 SDValue FractSignMask = DAG.getConstant(FractSignMaskVal, dl, AsIntVT);
2580 const APFloat One(FltSem,
"1.0");
2584 scalbn(One, Precision + 1, APFloat::rmNearestTiesToEven);
2586 SDValue ScaleUpK = DAG.getConstantFP(ScaleUpKVal, dl, VT);
2590 TLI.getSetCCResultType(DAG.getDataLayout(), *DAG.getContext(), VT);
2596 SDValue AddNegSmallestNormal =
2598 SDValue DenormOrZero = DAG.getSetCC(dl, SetCCVT, AddNegSmallestNormal,
2602 DAG.getSetCC(dl, SetCCVT, Abs, SmallestNormalizedInt,
ISD::SETULT);
2604 SDValue MinExp = DAG.getConstant(MinExpVal, dl, ExpVT);
2619 DAG.getShiftAmountConstant(Precision - 1, AsIntVT, dl);
2622 SDValue Exp = DAG.getSExtOrTrunc(ShiftedExp, dl, ExpVT);
2625 SDValue DenormalOffset = DAG.getConstant(-Precision - 1, dl, ExpVT);
2632 SDValue FPHalf = DAG.getConstant(
Half.bitcastToAPInt(), dl, AsIntVT);
2645 return DAG.getMergeValues({Result0, Result1}, dl);
2656 EVT DestVT =
Node->getValueType(0);
2658 unsigned OpNo =
Node->isStrictFPOpcode() ? 1 : 0;
2664 if (SrcVT == MVT::i32 && TLI.isTypeLegal(MVT::f64) &&
2665 (DestVT.
bitsLE(MVT::f64) ||
2669 LLVM_DEBUG(
dbgs() <<
"32-bit [signed|unsigned] integer to float/double "
2673 SDValue StackSlot = DAG.CreateStackTemporary(MVT::f64);
2680 DAG.getConstant(0x80000000u, dl, MVT::i32));
2683 SDValue Hi = DAG.getConstant(0x43300000u, dl, MVT::i32);
2686 if (DAG.getDataLayout().isBigEndian())
2689 SDValue MemChain = DAG.getEntryNode();
2692 SDValue Store1 = DAG.getStore(MemChain, dl,
Lo, StackSlot,
2705 SDValue Bias = DAG.getConstantFP(
2706 isSigned ? llvm::bit_cast<double>(0x4330000080000000ULL)
2707 : llvm::bit_cast<double>(0x4330000000000000ULL),
2712 if (
Node->isStrictFPOpcode()) {
2714 {
Node->getOperand(0), Load, Bias});
2717 std::pair<SDValue, SDValue> ResultPair;
2719 DAG.getStrictFPExtendOrRound(Sub, Chain, dl, DestVT);
2720 Result = ResultPair.first;
2721 Chain = ResultPair.second;
2727 Result = DAG.getFPExtendOrRound(Sub, dl, DestVT);
2736 if (((SrcVT == MVT::i32 || SrcVT == MVT::i64) && DestVT == MVT::f32) ||
2737 (SrcVT == MVT::i64 && DestVT == MVT::f64)) {
2738 LLVM_DEBUG(
dbgs() <<
"Converting unsigned i32/i64 to f32/f64\n");
2753 EVT SetCCVT = getSetCCResultType(SrcVT);
2755 SDValue SignBitTest = DAG.getSetCC(
2756 dl, SetCCVT, Op0, DAG.getConstant(0, dl, SrcVT),
ISD::SETLT);
2758 EVT ShiftVT = TLI.getShiftAmountTy(SrcVT, DAG.getDataLayout());
2759 SDValue ShiftConst = DAG.getConstant(1, dl, ShiftVT);
2761 SDValue AndConst = DAG.getConstant(1, dl, SrcVT);
2766 if (
Node->isStrictFPOpcode()) {
2769 SDValue InCvt = DAG.getSelect(dl, SrcVT, SignBitTest,
Or, Op0);
2771 {
Node->getOperand(0), InCvt });
2779 Flags.setNoFPExcept(
Node->getFlags().hasNoFPExcept());
2780 Fast->setFlags(Flags);
2781 Flags.setNoFPExcept(
true);
2789 return DAG.getSelect(dl, DestVT, SignBitTest, Slow,
Fast);
2793 if (!TLI.isOperationLegalOrCustom(
2802 "Cannot perform lossless SINT_TO_FP!");
2805 if (
Node->isStrictFPOpcode()) {
2807 {
Node->getOperand(0), Op0 });
2811 SDValue SignSet = DAG.getSetCC(dl, getSetCCResultType(SrcVT), Op0,
2814 Four = DAG.getIntPtrConstant(4, dl);
2815 SDValue CstOffset = DAG.getSelect(dl,
Zero.getValueType(),
2816 SignSet, Four, Zero);
2825 case MVT::i8 : FF = 0x43800000ULL;
break;
2826 case MVT::i16: FF = 0x47800000ULL;
break;
2827 case MVT::i32: FF = 0x4F800000ULL;
break;
2828 case MVT::i64: FF = 0x5F800000ULL;
break;
2830 if (DAG.getDataLayout().isLittleEndian())
2832 Constant *FudgeFactor = ConstantInt::get(
2836 DAG.getConstantPool(FudgeFactor, TLI.getPointerTy(DAG.getDataLayout()));
2837 Align Alignment = cast<ConstantPoolSDNode>(CPIdx)->getAlign();
2841 if (DestVT == MVT::f32)
2842 FudgeInReg = DAG.getLoad(
2843 MVT::f32, dl, DAG.getEntryNode(), CPIdx,
2852 LegalizeOp(
Load.getNode());
2856 if (
Node->isStrictFPOpcode()) {
2858 { Tmp1.
getValue(1), Tmp1, FudgeInReg });
2859 Chain =
Result.getValue(1);
2863 return DAG.getNode(
ISD::FADD, dl, DestVT, Tmp1, FudgeInReg);
2871void SelectionDAGLegalize::PromoteLegalINT_TO_FP(
2873 bool IsStrict =
N->isStrictFPOpcode();
2876 EVT DestVT =
N->getValueType(0);
2877 SDValue LegalOp =
N->getOperand(IsStrict ? 1 : 0);
2884 unsigned OpToUse = 0;
2892 if (TLI.isOperationLegalOrCustom(SIntOp, NewInTy)) {
2900 if (TLI.isOperationLegalOrCustom(UIntOp, NewInTy)) {
2912 DAG.
getNode(OpToUse, dl, {DestVT, MVT::Other},
2915 dl, NewInTy, LegalOp)});
2922 DAG.getNode(OpToUse, dl, DestVT,
2924 dl, NewInTy, LegalOp)));
2932void SelectionDAGLegalize::PromoteLegalFP_TO_INT(
SDNode *
N,
const SDLoc &dl,
2934 bool IsStrict =
N->isStrictFPOpcode();
2937 EVT DestVT =
N->getValueType(0);
2938 SDValue LegalOp =
N->getOperand(IsStrict ? 1 : 0);
2940 EVT NewOutTy = DestVT;
2942 unsigned OpToUse = 0;
2952 if (TLI.isOperationLegalOrCustom(OpToUse, NewOutTy))
2957 if (!IsSigned && TLI.isOperationLegalOrCustom(OpToUse, NewOutTy))
2966 SDVTList VTs = DAG.getVTList(NewOutTy, MVT::Other);
2967 Operation = DAG.getNode(OpToUse, dl, VTs,
N->getOperand(0), LegalOp);
2969 Operation = DAG.getNode(OpToUse, dl, NewOutTy, LegalOp);
2984 unsigned Opcode =
Node->getOpcode();
2987 EVT NewOutTy =
Node->getValueType(0);
2992 if (TLI.isOperationLegalOrCustom(Opcode, NewOutTy))
2999 Node->getOperand(1));
3005 EVT VT =
Op.getValueType();
3006 EVT ShVT = TLI.getShiftAmountTy(VT, DAG.getDataLayout());
3011 if (TLI.isOperationLegalOrPromote(
ISD::CTPOP, VT)) {
3017 DAG.getConstant(1ULL << (--i), dl, ShVT));
3022 return DAG.getNode(
ISD::AND, dl, VT, Result, DAG.getConstant(1, dl, VT));
3026 MVT VecVT =
Node->getOperand(1).getSimpleValueType();
3027 MVT NewVecVT = TLI.getTypeToPromoteTo(
Node->getOpcode(), VecVT);
3028 MVT ScalarVT =
Node->getSimpleValueType(0);
3036 assert(
Node->getOperand(0).getValueType().isFloatingPoint() &&
3037 "Only FP promotion is supported");
3041 for (
unsigned j = 1;
j !=
Node->getNumOperands(); ++
j)
3042 if (
Node->getOperand(j).getValueType().isVector() &&
3047 assert(
Node->getOperand(j).getValueType().isFloatingPoint() &&
3048 "Only FP promotion is supported");
3060 DAG.getIntPtrConstant(0,
DL,
true));
3063bool SelectionDAGLegalize::ExpandNode(
SDNode *
Node) {
3067 SDValue Tmp1, Tmp2, Tmp3, Tmp4;
3069 switch (
Node->getOpcode()) {
3071 if ((Tmp1 = TLI.expandABS(
Node, DAG)))
3076 if ((Tmp1 = TLI.expandABD(
Node, DAG)))
3083 if ((Tmp1 = TLI.expandAVG(
Node, DAG)))
3087 if ((Tmp1 = TLI.expandCTPOP(
Node, DAG)))
3092 if ((Tmp1 = TLI.expandCTLZ(
Node, DAG)))
3097 if ((Tmp1 = TLI.expandCTTZ(
Node, DAG)))
3101 if ((Tmp1 = TLI.expandBITREVERSE(
Node, DAG)))
3105 if ((Tmp1 = TLI.expandBSWAP(
Node, DAG)))
3109 Results.push_back(ExpandPARITY(
Node->getOperand(0), dl));
3114 Results.push_back(DAG.getConstant(0, dl,
Node->getValueType(0)));
3117 SDValue CfaArg = DAG.getSExtOrTrunc(
Node->getOperand(0), dl,
3118 TLI.getPointerTy(DAG.getDataLayout()));
3126 DAG.getConstant(0, dl, TLI.getPointerTy(DAG.getDataLayout())));
3132 Results.push_back(DAG.getConstant(1, dl,
Node->getValueType(0)));
3149 DAG.getConstant(0, dl,
Node->getValueType(0)));
3155 Results.push_back(DAG.getConstant(0, dl, MVT::i32));
3161 SDVTList VTs = DAG.getVTList(
Node->getValueType(0), MVT::Other);
3162 SDValue Swap = DAG.getAtomicCmpSwap(
3164 Node->getOperand(0),
Node->getOperand(1), Zero, Zero,
3165 cast<AtomicSDNode>(
Node)->getMemOperand());
3174 Node->getOperand(0),
Node->getOperand(2),
Node->getOperand(1),
3175 cast<AtomicSDNode>(
Node)->getMemOperand());
3183 SDVTList VTs = DAG.getVTList(
Node->getValueType(0), MVT::Other);
3184 SDValue Res = DAG.getAtomicCmpSwap(
3186 Node->getOperand(0),
Node->getOperand(1),
Node->getOperand(2),
3187 Node->getOperand(3), cast<MemSDNode>(
Node)->getMemOperand());
3193 EVT AtomicType = cast<AtomicSDNode>(
Node)->getMemoryVT();
3194 EVT OuterType =
Node->getValueType(0);
3195 switch (TLI.getExtendForAtomicOps()) {
3198 DAG.getValueType(AtomicType));
3200 Node->getOperand(2), DAG.getValueType(AtomicType));
3205 DAG.getValueType(AtomicType));
3206 RHS = DAG.getZeroExtendInReg(
Node->getOperand(2), dl, AtomicType);
3210 LHS = DAG.getZeroExtendInReg(Res, dl, AtomicType);
3211 RHS = DAG.getZeroExtendInReg(
Node->getOperand(2), dl, AtomicType);
3227 EVT VT =
Node->getValueType(0);
3231 cast<VTSDNode>(
RHS->getOperand(1))->getVT() == AN->
getMemoryVT())
3232 RHS =
RHS->getOperand(0);
3236 Node->getOperand(0),
Node->getOperand(1),
3246 for (
unsigned i = 0; i <
Node->getNumValues(); i++)
3250 EVT VT =
Node->getValueType(0);
3252 Results.push_back(DAG.getConstant(0, dl, VT));
3255 Results.push_back(DAG.getConstantFP(0, dl, VT));
3262 if (TLI.isStrictFPEnabled())
3266 if (TLI.getStrictFPOperationAction(
Node->getOpcode(),
3267 Node->getValueType(0))
3268 == TargetLowering::Legal)
3272 if ((Tmp1 = EmitStackConvert(
Node->getOperand(1),
Node->getValueType(0),
3273 Node->getValueType(0), dl,
3274 Node->getOperand(0)))) {
3276 LLVM_DEBUG(
dbgs() <<
"Successfully expanded STRICT_FP_ROUND node\n");
3281 if ((Tmp1 = TLI.expandFP_ROUND(
Node, DAG))) {
3289 if ((Tmp1 = EmitStackConvert(
Node->getOperand(0),
Node->getValueType(0),
3290 Node->getValueType(0), dl)))
3296 if (TLI.isStrictFPEnabled())
3300 if (TLI.getStrictFPOperationAction(
Node->getOpcode(),
3301 Node->getValueType(0))
3302 == TargetLowering::Legal)
3306 if ((Tmp1 = EmitStackConvert(
3307 Node->getOperand(1),
Node->getOperand(1).getValueType(),
3308 Node->getValueType(0), dl,
Node->getOperand(0)))) {
3310 LLVM_DEBUG(
dbgs() <<
"Successfully expanded STRICT_FP_EXTEND node\n");
3316 EVT SrcVT =
Op.getValueType();
3317 EVT DstVT =
Node->getValueType(0);
3323 if ((Tmp1 = EmitStackConvert(
Op, SrcVT, DstVT, dl)))
3333 if (
Op.getValueType() == MVT::bf16) {
3337 Op = DAG.getAnyExtOrTrunc(
Op, dl, MVT::i32);
3341 DAG.getConstant(16, dl,
3342 TLI.getShiftAmountTy(MVT::i32, DAG.getDataLayout())));
3345 if (
Node->getValueType(0) != MVT::f32)
3352 if (
Op.getValueType() != MVT::f32)
3354 DAG.getIntPtrConstant(0, dl,
true));
3356 if (!DAG.isKnownNeverSNaN(
Op)) {
3361 DAG.getConstant(16, dl,
3362 TLI.getShiftAmountTy(MVT::i32, DAG.getDataLayout())));
3365 if (
Node->getValueType(0) == MVT::bf16) {
3369 Op = DAG.getAnyExtOrTrunc(
Op, dl,
Node->getValueType(0));
3375 EVT ExtraVT = cast<VTSDNode>(
Node->getOperand(1))->getVT();
3376 EVT VT =
Node->getValueType(0);
3386 SDValue One = DAG.getConstant(1, dl, VT);
3396 EVT ShiftAmountTy = TLI.getShiftAmountTy(VT, DAG.getDataLayout());
3399 SDValue ShiftCst = DAG.getConstant(BitsDiff, dl, ShiftAmountTy);
3401 Node->getOperand(0), ShiftCst);
3408 if (TLI.expandUINT_TO_FP(
Node, Tmp1, Tmp2, DAG)) {
3410 if (
Node->isStrictFPOpcode())
3417 if ((Tmp1 = ExpandLegalINT_TO_FP(
Node, Tmp2))) {
3419 if (
Node->isStrictFPOpcode())
3424 if (TLI.expandFP_TO_SINT(
Node, Tmp1, DAG))
3428 if (TLI.expandFP_TO_SINT(
Node, Tmp1, DAG)) {
3430 LLVM_DEBUG(
dbgs() <<
"Successfully expanded STRICT_FP_TO_SINT node\n");
3435 if (TLI.expandFP_TO_UINT(
Node, Tmp1, Tmp2, DAG))
3439 if (TLI.expandFP_TO_UINT(
Node, Tmp1, Tmp2, DAG)) {
3441 DAG.ReplaceAllUsesOfValueWith(
SDValue(
Node,1), Tmp2);
3444 LLVM_DEBUG(
dbgs() <<
"Successfully expanded STRICT_FP_TO_UINT node\n");
3450 Results.push_back(TLI.expandFP_TO_INT_SAT(
Node, DAG));
3456 EVT ResVT =
Node->getValueType(0);
3470 if (
Node->getOperand(0).getValueType().getVectorElementCount().isScalar())
3473 Node->getOperand(0));
3475 Tmp1 = ExpandExtractFromVectorThroughStack(
SDValue(
Node, 0));
3485 Results.push_back(ExpandVectorBuildThroughStack(
Node));
3497 EVT VT =
Node->getValueType(0);
3501 if (!TLI.isTypeLegal(EltVT)) {
3502 EVT NewEltVT = TLI.getTypeToTransformTo(*DAG.getContext(), EltVT);
3507 if (NewEltVT.
bitsLT(EltVT)) {
3523 unsigned int factor =
3531 for (
unsigned fi = 0; fi < factor; ++fi)
3535 for (
unsigned fi = 0; fi < factor; ++fi)
3546 for (
unsigned i = 0; i != NumElems; ++i) {
3554 DAG.getVectorIdxConstant(
Idx, dl)));
3558 DAG.getVectorIdxConstant(
Idx - NumElems, dl)));
3561 Tmp1 = DAG.getBuildVector(VT, dl, Ops);
3568 Results.push_back(TLI.expandVectorSplice(
Node, DAG));
3572 EVT OpTy =
Node->getOperand(0).getValueType();
3573 if (
Node->getConstantOperandVal(1)) {
3577 TLI.getShiftAmountTy(
3578 Node->getOperand(0).getValueType(),
3579 DAG.getDataLayout())));
3584 Node->getOperand(0));
3592 if (
Register SP = TLI.getStackPointerRegisterToSaveRestore()) {
3593 Results.push_back(DAG.getCopyFromReg(
Node->getOperand(0), dl, SP,
3594 Node->getValueType(0)));
3597 Results.push_back(DAG.getUNDEF(
Node->getValueType(0)));
3604 if (
Register SP = TLI.getStackPointerRegisterToSaveRestore()) {
3605 Results.push_back(DAG.getCopyToReg(
Node->getOperand(0), dl, SP,
3606 Node->getOperand(1)));
3612 Results.push_back(DAG.getConstant(0, dl,
Node->getValueType(0)));
3627 TLI.expandIS_FPCLASS(
Node->getValueType(0),
Node->getOperand(0),
3638 switch (
Node->getOpcode()) {
3645 Tmp1 =
Node->getOperand(0);
3646 Tmp2 =
Node->getOperand(1);
3647 Tmp1 = DAG.getSelectCC(dl, Tmp1, Tmp2, Tmp1, Tmp2, Pred);
3653 if (
SDValue Expanded = TLI.expandFMINNUM_FMAXNUM(
Node, DAG))
3659 if (
SDValue Expanded = TLI.expandFMINIMUM_FMAXIMUM(
Node, DAG))
3665 EVT VT =
Node->getValueType(0);
3671 SDVTList VTs = DAG.getVTList(VT, VT);
3681 EVT VT =
Node->getValueType(0);
3685 if (TLI.getLibcallName(LC))
3691 Results.push_back(Expanded.getValue(1));
3700 if (TLI.getLibcallName(LC))
3705 Results.push_back(Expanded.getValue(1));
3713 if (
Node->getValueType(0) != MVT::f32) {
3725 if (
Node->getValueType(0) != MVT::f32) {
3730 {Node->getOperand(0), Node->getOperand(1)});
3732 {
Node->getValueType(0), MVT::Other},
3740 if (!TLI.useSoftFloat() &&
TM.Options.UnsafeFPMath) {
3742 MVT SVT =
Op.getSimpleValueType();
3743 if ((SVT == MVT::f64 || SVT == MVT::f80) &&
3749 DAG.getIntPtrConstant(0, dl,
true));
3760 DAG.shouldOptForSize()))
3761 Results.push_back(ExpandConstantFP(CFP,
true));
3766 Results.push_back(ExpandConstant(CP));
3770 EVT VT =
Node->getValueType(0);
3771 if (TLI.isOperationLegalOrCustom(
ISD::FADD, VT) &&
3772 TLI.isOperationLegalOrCustom(
ISD::FNEG, VT)) {
3781 EVT VT =
Node->getValueType(0);
3783 TLI.isOperationLegalOrCustom(
ISD::XOR, VT) &&
3784 "Don't know how to expand this subtraction!");
3785 Tmp1 = DAG.getNOT(dl,
Node->getOperand(1), VT);
3786 Tmp1 = DAG.
getNode(
ISD::ADD, dl, VT, Tmp1, DAG.getConstant(1, dl, VT));
3792 if (TLI.expandREM(
Node, Tmp1, DAG))
3799 EVT VT =
Node->getValueType(0);
3800 if (TLI.isOperationLegalOrCustom(DivRemOpc, VT)) {
3801 SDVTList VTs = DAG.getVTList(VT, VT);
3802 Tmp1 = DAG.
getNode(DivRemOpc, dl, VTs,
Node->getOperand(0),
3803 Node->getOperand(1));
3810 unsigned ExpandOpcode =
3812 EVT VT =
Node->getValueType(0);
3813 SDVTList VTs = DAG.getVTList(VT, VT);
3815 Tmp1 = DAG.
getNode(ExpandOpcode, dl, VTs,
Node->getOperand(0),
3816 Node->getOperand(1));
3824 MVT VT =
LHS.getSimpleValueType();
3825 unsigned MULHOpcode =
3828 if (TLI.isOperationLegalOrCustom(MULHOpcode, VT)) {
3830 Results.push_back(DAG.getNode(MULHOpcode, dl, VT, LHS, RHS));
3836 assert(TLI.isTypeLegal(HalfType));
3837 if (TLI.expandMUL_LOHI(
Node->getOpcode(), VT, dl, LHS, RHS, Halves,
3839 TargetLowering::MulExpansionKind::Always)) {
3840 for (
unsigned i = 0; i < 2; ++i) {
3843 SDValue Shift = DAG.getConstant(
3845 TLI.getShiftAmountTy(HalfType, DAG.getDataLayout()));
3854 EVT VT =
Node->getValueType(0);
3855 SDVTList VTs = DAG.getVTList(VT, VT);
3861 bool HasSMUL_LOHI = TLI.isOperationLegalOrCustom(
ISD::SMUL_LOHI, VT);
3862 bool HasUMUL_LOHI = TLI.isOperationLegalOrCustom(
ISD::UMUL_LOHI, VT);
3863 bool HasMULHS = TLI.isOperationLegalOrCustom(
ISD::MULHS, VT);
3864 bool HasMULHU = TLI.isOperationLegalOrCustom(
ISD::MULHU, VT);
3865 unsigned OpToUse = 0;
3866 if (HasSMUL_LOHI && !HasMULHS) {
3868 }
else if (HasUMUL_LOHI && !HasMULHU) {
3870 }
else if (HasSMUL_LOHI) {
3872 }
else if (HasUMUL_LOHI) {
3876 Results.push_back(DAG.getNode(OpToUse, dl, VTs,
Node->getOperand(0),
3877 Node->getOperand(1)));
3885 TLI.isOperationLegalOrCustom(
ISD::SHL, VT) &&
3886 TLI.isOperationLegalOrCustom(
ISD::OR, VT) &&
3887 TLI.expandMUL(
Node,
Lo,
Hi, HalfType, DAG,
3888 TargetLowering::MulExpansionKind::OnlyLegalOrCustom)) {
3893 TLI.getShiftAmountTy(HalfType, DAG.getDataLayout()));
3901 if (
SDValue Expanded = TLI.expandFunnelShift(
Node, DAG))
3906 if (
SDValue Expanded = TLI.expandROT(
Node,
true , DAG))
3913 Results.push_back(TLI.expandAddSubSat(
Node, DAG));
3927 Results.push_back(TLI.expandFixedPointMul(
Node, DAG));
3934 Node->getOperand(0),
3935 Node->getOperand(1),
3936 Node->getConstantOperandVal(2),
3959 EVT VT =
LHS.getValueType();
3963 EVT CarryType =
Node->getValueType(1);
3964 EVT SetCCType = getSetCCResultType(
Node->getValueType(0));
3966 SDValue Overflow = DAG.getSetCC(dl, SetCCType, Sum, LHS,
CC);
3969 SDValue One = DAG.getConstant(1, dl, VT);
3971 DAG.
getNode(
ISD::AND, dl, VT, DAG.getZExtOrTrunc(Carry, dl, VT), One);
3980 IsAdd ? DAG.getSetCC(dl, SetCCType, Sum2, Zero,
ISD::SETEQ)
3981 : DAG.getSetCC(dl, SetCCType, Sum, Zero,
ISD::SETEQ);
3983 DAG.getZExtOrTrunc(Carry, dl, SetCCType));
3989 Results.push_back(DAG.getBoolExtOrTrunc(ResultCarry, dl, CarryType, VT));
3995 TLI.expandSADDSUBO(
Node, Result, Overflow, DAG);
4003 TLI.expandUADDSUBO(
Node, Result, Overflow, DAG);
4011 if (TLI.expandMULO(
Node, Result, Overflow, DAG)) {
4023 DAG.getConstant(
PairTy.getSizeInBits() / 2, dl,
4024 TLI.getShiftAmountTy(
PairTy, DAG.getDataLayout())));
4029 Tmp1 =
Node->getOperand(0);
4030 Tmp2 =
Node->getOperand(1);
4031 Tmp3 =
Node->getOperand(2);
4035 cast<CondCodeSDNode>(Tmp1.
getOperand(2))->get());
4037 Tmp1 = DAG.getSelectCC(dl, Tmp1,
4048 int JTI = cast<JumpTableSDNode>(Table.
getNode())->getIndex();
4051 EVT PTy = TLI.getPointerTy(TD);
4053 unsigned EntrySize =
4054 DAG.getMachineFunction().getJumpTableInfo()->getEntrySize(TD);
4061 Index = DAG.getNode(
4066 DAG.getConstant(EntrySize, dl,
Index.getValueType()));
4075 if (TLI.isJumpTableRelative()) {
4080 TLI.getPICJumpTableRelocBase(Table, DAG));
4083 Tmp1 = TLI.expandIndirectJTBranch(dl,
LD.getValue(1),
Addr, JTI, DAG);
4090 Tmp1 =
Node->getOperand(0);
4091 Tmp2 =
Node->getOperand(1);
4097 Node->getOperand(2));
4109 Node->getOperand(2));
4117 bool IsVP =
Node->getOpcode() == ISD::VP_SETCC;
4122 unsigned Offset = IsStrict ? 1 : 0;
4131 bool Legalized = TLI.LegalizeSetCCCondCode(
4132 DAG,
Node->getValueType(0), Tmp1, Tmp2, Tmp3, Mask, EVL, NeedInvert, dl,
4133 Chain, IsSignaling);
4141 {Chain, Tmp1, Tmp2, Tmp3},
Node->getFlags());
4145 {Tmp1, Tmp2, Tmp3, Mask, EVL},
Node->getFlags());
4147 Tmp1 = DAG.
getNode(
Node->getOpcode(), dl,
Node->getValueType(0), Tmp1,
4148 Tmp2, Tmp3,
Node->getFlags());
4156 Tmp1 = DAG.getLogicalNOT(dl, Tmp1, Tmp1->
getValueType(0));
4159 DAG.getVPLogicalNOT(dl, Tmp1, Mask, EVL, Tmp1->
getValueType(0));
4171 assert(!IsStrict &&
"Don't know how to expand for strict nodes.");
4176 EVT VT =
Node->getValueType(0);
4179 DAG.getBoolConstant(
true, dl, VT, Tmp1VT),
4180 DAG.getBoolConstant(
false, dl, VT, Tmp1VT), Tmp3);
4187 Tmp1 =
Node->getOperand(0);
4188 Tmp2 =
Node->getOperand(1);
4189 Tmp3 =
Node->getOperand(2);
4190 Tmp4 =
Node->getOperand(3);
4191 EVT VT =
Node->getValueType(0);
4201 "Cannot expand ISD::SELECT_CC when ISD::SELECT also needs to be "
4203 EVT CCVT = getSetCCResultType(CmpVT);
4206 DAG.getSelect(dl, VT,
Cond, Tmp3, Tmp4,
Node->getFlags()));
4211 bool Legalized =
false;
4219 Tmp1 = DAG.getSelectCC(dl, Tmp1, Tmp2, Tmp4, Tmp3, InvCC);
4229 Tmp1 = DAG.getSelectCC(dl, Tmp2, Tmp1, Tmp4, Tmp3, SwapInvCC);
4235 Legalized = TLI.LegalizeSetCCCondCode(
4239 assert(Legalized &&
"Can't legalize SELECT_CC with legal condition!");
4250 Tmp1, Tmp2, Tmp3, Tmp4,
CC);
4255 Tmp2, Tmp3, Tmp4,
CC);
4265 Tmp1 =
Node->getOperand(0);
4266 Tmp2 =
Node->getOperand(2);
4267 Tmp3 =
Node->getOperand(3);
4268 Tmp4 =
Node->getOperand(1);
4270 bool Legalized = TLI.LegalizeSetCCCondCode(
4271 DAG, getSetCCResultType(Tmp2.
getValueType()), Tmp2, Tmp3, Tmp4,
4274 assert(Legalized &&
"Can't legalize BR_CC with legal condition!");
4279 assert(!NeedInvert &&
"Don't know how to invert BR_CC!");
4282 Tmp4, Tmp2, Tmp3,
Node->getOperand(4));
4287 Tmp2, Tmp3,
Node->getOperand(4));
4302 EVT VT =
Node->getValueType(0);
4308 for (
unsigned Idx = 0;
Idx < NumElem;
Idx++) {
4311 Node->getOperand(0), DAG.getVectorIdxConstant(
Idx, dl));
4314 Node->getOperand(1), DAG.getVectorIdxConstant(
Idx, dl));
4338 Results.push_back(TLI.expandVecReduce(
Node, DAG));
4340 case ISD::VP_CTTZ_ELTS:
4341 case ISD::VP_CTTZ_ELTS_ZERO_UNDEF:
4342 Results.push_back(TLI.expandVPCTTZElements(
Node, DAG));
4353 EVT ResVT =
Node->getValueType(0);
4374 if (!TLI.isStrictFPEnabled() &&
Results.
empty() &&
Node->isStrictFPOpcode()) {
4380 switch (
Node->getOpcode()) {
4382 if (TLI.getStrictFPOperationAction(
Node->getOpcode(),
4383 Node->getValueType(0))
4384 == TargetLowering::Legal)
4388 if (TLI.getStrictFPOperationAction(
4391 if (TLI.getStrictFPOperationAction(
4395 EVT VT =
Node->getValueType(0);
4399 {Node->getOperand(0), Node->getOperand(1), Neg},
4414 if (TLI.getStrictFPOperationAction(
Node->getOpcode(),
4415 Node->getOperand(1).getValueType())
4416 == TargetLowering::Legal)
4433void SelectionDAGLegalize::ConvertNodeToLibcall(
SDNode *
Node) {
4438 unsigned Opc =
Node->getOpcode();
4447 .setChain(
Node->getOperand(0))
4450 DAG.getExternalSymbol(
"__sync_synchronize",
4451 TLI.getPointerTy(DAG.getDataLayout())),
4454 std::pair<SDValue, SDValue> CallResult = TLI.LowerCallTo(CLI);
4456 Results.push_back(CallResult.second);
4478 EVT RetVT =
Node->getValueType(0);
4481 if (TLI.getLibcallName(LC)) {
4488 assert(LC != RTLIB::UNKNOWN_LIBCALL &&
4489 "Unexpected atomic op or value type!");
4493 std::pair<SDValue, SDValue> Tmp = TLI.makeLibCall(DAG, LC, RetVT,
4496 Node->getOperand(0));
4498 Results.push_back(Tmp.second);
4506 .setChain(
Node->getOperand(0))
4508 DAG.getExternalSymbol(
4509 "abort", TLI.getPointerTy(DAG.getDataLayout())),
4511 std::pair<SDValue, SDValue> CallResult = TLI.LowerCallTo(CLI);
4513 Results.push_back(CallResult.second);
4521 std::pair<SDValue, SDValue> Tmp = TLI.makeLibCall(
4522 DAG, RTLIB::CLEAR_CACHE, MVT::isVoid, {StartVal, EndVal}, CallOptions,
4524 Results.push_back(Tmp.second);
4529 ExpandFPLibCall(
Node, RTLIB::FMIN_F32, RTLIB::FMIN_F64,
4530 RTLIB::FMIN_F80, RTLIB::FMIN_F128,
4531 RTLIB::FMIN_PPCF128,
Results);
4538 ExpandFPLibCall(
Node, RTLIB::FMAX_F32, RTLIB::FMAX_F64,
4539 RTLIB::FMAX_F80, RTLIB::FMAX_F128,
4540 RTLIB::FMAX_PPCF128,
Results);
4544 ExpandFPLibCall(
Node, RTLIB::SQRT_F32, RTLIB::SQRT_F64,
4545 RTLIB::SQRT_F80, RTLIB::SQRT_F128,
4546 RTLIB::SQRT_PPCF128,
Results);
4549 ExpandFPLibCall(
Node, RTLIB::CBRT_F32, RTLIB::CBRT_F64,
4550 RTLIB::CBRT_F80, RTLIB::CBRT_F128,
4551 RTLIB::CBRT_PPCF128,
Results);
4555 ExpandFPLibCall(
Node, RTLIB::SIN_F32, RTLIB::SIN_F64,
4556 RTLIB::SIN_F80, RTLIB::SIN_F128,
4561 ExpandFPLibCall(
Node, RTLIB::COS_F32, RTLIB::COS_F64,
4562 RTLIB::COS_F80, RTLIB::COS_F128,
4567 ExpandFPLibCall(
Node, RTLIB::TAN_F32, RTLIB::TAN_F64, RTLIB::TAN_F80,
4568 RTLIB::TAN_F128, RTLIB::TAN_PPCF128,
Results);
4572 ExpandFPLibCall(
Node, RTLIB::ASIN_F32, RTLIB::ASIN_F64, RTLIB::ASIN_F80,
4573 RTLIB::ASIN_F128, RTLIB::ASIN_PPCF128,
Results);
4577 ExpandFPLibCall(
Node, RTLIB::ACOS_F32, RTLIB::ACOS_F64, RTLIB::ACOS_F80,
4578 RTLIB::ACOS_F128, RTLIB::ACOS_PPCF128,
Results);
4582 ExpandFPLibCall(
Node, RTLIB::ATAN_F32, RTLIB::ATAN_F64, RTLIB::ATAN_F80,
4583 RTLIB::ATAN_F128, RTLIB::ATAN_PPCF128,
Results);
4587 ExpandFPLibCall(
Node, RTLIB::SINH_F32, RTLIB::SINH_F64, RTLIB::SINH_F80,
4588 RTLIB::SINH_F128, RTLIB::SINH_PPCF128,
Results);
4592 ExpandFPLibCall(
Node, RTLIB::COSH_F32, RTLIB::COSH_F64, RTLIB::COSH_F80,
4593 RTLIB::COSH_F128, RTLIB::COSH_PPCF128,
Results);
4597 ExpandFPLibCall(
Node, RTLIB::TANH_F32, RTLIB::TANH_F64, RTLIB::TANH_F80,
4598 RTLIB::TANH_F128, RTLIB::TANH_PPCF128,
Results);
4606 ExpandFPLibCall(
Node, RTLIB::LOG_F32, RTLIB::LOG_F64, RTLIB::LOG_F80,
4607 RTLIB::LOG_F128, RTLIB::LOG_PPCF128,
Results);
4611 ExpandFPLibCall(
Node, RTLIB::LOG2_F32, RTLIB::LOG2_F64, RTLIB::LOG2_F80,
4612 RTLIB::LOG2_F128, RTLIB::LOG2_PPCF128,
Results);
4616 ExpandFPLibCall(
Node, RTLIB::LOG10_F32, RTLIB::LOG10_F64, RTLIB::LOG10_F80,
4617 RTLIB::LOG10_F128, RTLIB::LOG10_PPCF128,
Results);