32#define DEBUG_TYPE "legalize-types"
42void DAGTypeLegalizer::PromoteIntegerResult(
SDNode *
N,
unsigned ResNo) {
47 if (CustomLowerNode(
N,
N->getValueType(ResNo),
true)) {
52 switch (
N->getOpcode()) {
55 dbgs() <<
"PromoteIntegerResult #" << ResNo <<
": ";
56 N->dump(&DAG);
dbgs() <<
"\n";
64 case ISD::BSWAP: Res = PromoteIntRes_BSWAP(
N);
break;
68 case ISD::CTLZ: Res = PromoteIntRes_CTLZ(
N);
break;
69 case ISD::CTLS: Res = PromoteIntRes_CTLS(
N);
break;
71 case ISD::CTPOP: Res = PromoteIntRes_CTPOP_PARITY(
N);
break;
73 case ISD::CTTZ: Res = PromoteIntRes_CTTZ(
N);
break;
76 case ISD::VP_CTTZ_ELTS_ZERO_POISON:
77 case ISD::VP_CTTZ_ELTS:
78 Res = PromoteIntRes_VP_CttzElements(
N);
81 Res = PromoteIntRes_EXTRACT_VECTOR_ELT(
N);
break;
91 Res = PromoteIntRes_VECTOR_COMPRESS(
N);
96 Res = PromoteIntRes_Select(
N);
101 case ISD::SETCC: Res = PromoteIntRes_SETCC(
N);
break;
103 case ISD::SMAX: Res = PromoteIntRes_SExtIntBinOp(
N);
break;
105 case ISD::UMAX: Res = PromoteIntRes_UMINUMAX(
N);
break;
107 case ISD::SHL: Res = PromoteIntRes_SHL(
N);
break;
109 Res = PromoteIntRes_SIGN_EXTEND_INREG(
N);
break;
110 case ISD::SRA: Res = PromoteIntRes_SRA(
N);
break;
111 case ISD::SRL: Res = PromoteIntRes_SRL(
N);
break;
114 case ISD::UNDEF: Res = PromoteIntRes_UNDEF(
N);
break;
115 case ISD::VAARG: Res = PromoteIntRes_VAARG(
N);
break;
119 Res = PromoteIntRes_EXTRACT_SUBVECTOR(
N);
break;
121 Res = PromoteIntRes_INSERT_SUBVECTOR(
N);
break;
123 Res = PromoteIntRes_VECTOR_REVERSE(
N);
break;
125 Res = PromoteIntRes_VECTOR_SHUFFLE(
N);
break;
128 Res = PromoteIntRes_VECTOR_SPLICE(
N);
131 Res = PromoteIntRes_VECTOR_REPEAT(
N);
135 Res = PromoteIntRes_VECTOR_INTERLEAVE_DEINTERLEAVE(
N);
138 Res = PromoteIntRes_INSERT_VECTOR_ELT(
N);
break;
140 Res = PromoteIntRes_BUILD_VECTOR(
N);
144 Res = PromoteIntRes_ScalarOp(
N);
148 Res = PromoteIntRes_CONCAT_VECTORS(
N);
break;
153 Res = PromoteIntRes_EXTEND_VECTOR_INREG(
N);
break;
156 Res = PromoteIntRes_VECTOR_FIND_LAST_ACTIVE(
N);
160 Res = PromoteIntRes_GET_ACTIVE_LANE_MASK(
N);
163 Res = PromoteIntRes_MASK_BEFOREFIRST(
N);
166 Res = PromoteIntRes_VECTOR_MATCH(
N);
172 Res = PromoteIntRes_PARTIAL_REDUCE_MLA(
N);
186 Res = PromoteIntRes_FP_TO_XINT_SAT(
N);
break;
190 Res = PromoteIntRes_FP_TO_FP16_BF16(
N);
193 Res = PromoteIntRes_CONVERT_TO_ARBITRARY_FP(
N);
197 Res = PromoteIntRes_STRICT_FP_TO_FP16_BF16(
N);
206 case ISD::MUL: Res = PromoteIntRes_SimpleIntBinOp(
N);
break;
214 case ISD::VP_SREM: Res = PromoteIntRes_SExtIntBinOp(
N);
break;
222 case ISD::VP_UREM: Res = PromoteIntRes_ZExtIntBinOp(
N);
break;
226 Res = PromoteIntRes_ZExtMaskedIntBinOp(
N);
230 Res = PromoteIntRes_SExtMaskedIntBinOp(
N);
234 case ISD::SSUBO: Res = PromoteIntRes_SADDSUBO(
N, ResNo);
break;
236 case ISD::USUBO: Res = PromoteIntRes_UADDSUBO(
N, ResNo);
break;
238 case ISD::UMULO: Res = PromoteIntRes_XMULO(
N, ResNo);
break;
254 Res = PromoteIntRes_ADDSUBSHLSAT(
N);
259 Res = PromoteIntRes_CMP(
N);
274 Res = PromoteIntRes_ABS(
N);
308 Res = PromoteIntRes_VECREDUCE(
N);
311 case ISD::VP_REDUCE_ADD:
312 case ISD::VP_REDUCE_MUL:
313 case ISD::VP_REDUCE_AND:
314 case ISD::VP_REDUCE_OR:
315 case ISD::VP_REDUCE_XOR:
316 case ISD::VP_REDUCE_SMAX:
317 case ISD::VP_REDUCE_SMIN:
318 case ISD::VP_REDUCE_UMAX:
319 case ISD::VP_REDUCE_UMIN:
320 Res = PromoteIntRes_VP_REDUCE(
N);
325 Res = PromoteIntRes_LOOP_DEPENDENCE_MASK(
N);
329 Res = PromoteIntRes_FREEZE(
N);
334 Res = PromoteIntRes_Rotate(
N);
339 Res = PromoteIntRes_FunnelShift(
N);
345 Res = PromoteIntRes_CLMUL(
N);
349 Res = PromoteIntRes_PEXT(
N);
353 Res = PromoteIntRes_PDEP(
N);
358 Res = PromoteIntRes_MULH(
N);
362 Res = PromoteIntRes_IS_FPCLASS(
N);
365 Res = PromoteIntRes_FFREXP(
N);
370 Res = PromoteIntRes_XRINT(
N);
374 Res = PromoteIntRes_PATCHPOINT(
N);
377 Res = PromoteIntRes_READ_REGISTER(
N);
383 SetPromotedInteger(
SDValue(
N, ResNo), Res);
388 SDValue
Op = DisintegrateMERGE_VALUES(
N, ResNo);
389 return GetPromotedInteger(
Op);
392SDValue DAGTypeLegalizer::PromoteIntRes_LOOP_DEPENDENCE_MASK(
SDNode *
N) {
394 EVT NewVT = TLI.getTypeToTransformTo(*DAG.getContext(), VT);
395 return DAG.getNode(
N->getOpcode(), SDLoc(
N), NewVT,
N->ops());
400 SDValue
Op = SExtPromotedInteger(
N->getOperand(0));
402 Op.getValueType(),
Op,
N->getOperand(1));
407 SDValue
Op = ZExtPromotedInteger(
N->getOperand(0));
409 Op.getValueType(),
Op,
N->getOperand(1));
413 EVT ResVT = TLI.getTypeToTransformTo(*DAG.getContext(),
N->getValueType(0));
416 switch (TLI.getExtendForAtomicOps()) {
432 DAG.getAtomicLoad(ExtType, SDLoc(
N),
N->getMemoryVT(), ResVT,
433 N->getChain(),
N->getBasePtr(),
N->getMemOperand());
437 ReplaceValueWith(SDValue(
N, 1), Res.
getValue(1));
443 switch (TLI.getExtendForAtomicRMWArg(
N->getOpcode())) {
445 Op2 = SExtPromotedInteger(Op2);
448 Op2 = ZExtPromotedInteger(Op2);
451 Op2 = GetPromotedInteger(Op2);
456 SDValue Res = DAG.getAtomic(
N->getOpcode(), SDLoc(
N),
458 N->getChain(),
N->getBasePtr(),
459 Op2,
N->getMemOperand());
462 ReplaceValueWith(SDValue(
N, 1), Res.
getValue(1));
470 EVT SVT = getSetCCResultType(
N->getOperand(2).getValueType());
471 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(),
N->getValueType(1));
475 if (!TLI.isTypeLegal(SVT))
478 SDVTList VTs = DAG.getVTList(
N->getValueType(0), SVT, MVT::Other);
479 SDValue Res = DAG.getAtomicCmpSwap(
481 N->getChain(),
N->getBasePtr(),
N->getOperand(2),
N->getOperand(3),
483 ReplaceValueWith(SDValue(
N, 0), Res.
getValue(0));
484 ReplaceValueWith(SDValue(
N, 2), Res.
getValue(2));
485 return DAG.getSExtOrTrunc(Res.
getValue(1), SDLoc(
N), NVT);
491 SDValue Op3 = GetPromotedInteger(
N->getOperand(3));
492 switch (TLI.getExtendForAtomicCmpSwapArg()) {
494 Op2 = SExtPromotedInteger(Op2);
497 Op2 = ZExtPromotedInteger(Op2);
500 Op2 = GetPromotedInteger(Op2);
507 DAG.getVTList(Op2.
getValueType(),
N->getValueType(1), MVT::Other);
508 SDValue Res = DAG.getAtomicCmpSwap(
509 N->getOpcode(), SDLoc(
N),
N->getMemoryVT(), VTs,
N->getChain(),
510 N->getBasePtr(), Op2, Op3,
N->getMemOperand());
512 for (
unsigned i = 1, NumResults =
N->getNumValues(); i < NumResults; ++i)
513 ReplaceValueWith(SDValue(
N, i), Res.
getValue(i));
520 EVT NInVT = TLI.getTypeToTransformTo(*DAG.getContext(), InVT);
521 EVT OutVT =
N->getValueType(0);
522 EVT NOutVT = TLI.getTypeToTransformTo(*DAG.getContext(), OutVT);
525 switch (getTypeAction(InVT)) {
531 return DAG.getNode(
ISD::BITCAST, dl, NOutVT, GetPromotedInteger(InOp));
535 return DAG.getNode(
ISD::ANY_EXTEND, dl, NOutVT, GetSoftenedFloat(InOp));
538 return DAG.getNode(
ISD::ANY_EXTEND, dl, NOutVT, GetSoftPromotedHalf(InOp));
546 BitConvertToInteger(GetScalarizedVector(InOp)));
555 GetSplitVector(
N->getOperand(0),
Lo,
Hi);
556 Lo = BitConvertToInteger(
Lo);
557 Hi = BitConvertToInteger(
Hi);
559 if (DAG.getDataLayout().isBigEndian())
565 JoinIntegers(
Lo,
Hi));
580 if (DAG.getDataLayout().isBigEndian()) {
584 DAG.getShiftAmountConstant(ShiftAmt, NOutVT, dl));
599 if (isTypeLegal(WideOutVT)) {
600 InOp = DAG.getBitcast(WideOutVT, GetWidenedVector(InOp));
602 DAG.getVectorIdxConstant(0, dl));
611 DAG.getDataLayout().isLittleEndian()) {
622 if (isTypeLegal(WideVecVT)) {
624 DAG.getUNDEF(WideVecVT), InOp,
625 DAG.getVectorIdxConstant(0, dl));
633 CreateStackStoreLoad(InOp, OutVT));
637 SDValue
V = GetPromotedInteger(
N->getOperand(0));
639 V.getValueType(), V);
643 SDValue
Op = GetPromotedInteger(
N->getOperand(0));
644 EVT OVT =
N->getValueType(0);
645 EVT NVT =
Op.getValueType();
653 !TLI.isOperationLegalOrCustomOrPromote(
ISD::BSWAP, NVT)) {
654 if (SDValue Res = TLI.expandBSWAP(
N, DAG))
659 SDValue ShAmt = DAG.getShiftAmountConstant(DiffBits, NVT, dl);
665 SDValue
Op = GetPromotedInteger(
N->getOperand(0));
666 EVT OVT =
N->getValueType(0);
667 EVT NVT =
Op.getValueType();
676 if (SDValue Res = TLI.expandBITREVERSE(
N, DAG))
681 SDValue ShAmt = DAG.getShiftAmountConstant(DiffBits, NVT, dl);
690 TLI.getTypeToTransformTo(*DAG.getContext(),
691 N->getValueType(0)), JoinIntegers(
N->getOperand(0),
696 EVT VT =
N->getValueType(0);
703 TLI.getTypeToTransformTo(*DAG.getContext(), VT),
710 EVT OVT =
N->getValueType(0);
711 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), OVT);
717 if (!OVT.
isVector() && TLI.isTypeLegal(NVT) &&
718 !TLI.isOperationLegalOrCustomOrPromote(
ISD::CTLZ, NVT) &&
720 if (SDValue Result = TLI.expandCTLZ(
N, DAG)) {
726 unsigned CtlzOpcode =
N->getOpcode();
729 SDValue ExtractLeadingBits = DAG.getConstant(
732 SDValue
Op = ZExtPromotedInteger(
N->getOperand(0));
736 return DAG.getNode(
ISD::SUB, dl, NVT,
737 DAG.getNode(
N->getOpcode(), dl, NVT,
Op),
742 SDValue
Op = GetPromotedInteger(
N->getOperand(0));
746 DAG.getShiftAmountConstant(SHLAmount,
Op.getValueType(), dl);
748 return DAG.getNode(CtlzOpcode, dl, NVT,
Op);
754 EVT OVT =
N->getValueType(0);
755 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), OVT);
758 SDValue ExtractLeadingBits = DAG.getConstant(
761 SDValue
Op = SExtPromotedInteger(
N->getOperand(0));
767 EVT OVT =
N->getValueType(0);
768 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), OVT);
776 !TLI.isOperationLegalOrCustomOrPromote(
ISD::CTPOP, NVT)) {
777 if (SDValue Result = TLI.expandCTPOP(
N, DAG)) {
784 SDValue
Op = ZExtPromotedInteger(
N->getOperand(0));
785 return DAG.getNode(
N->getOpcode(), SDLoc(
N),
Op.getValueType(),
Op);
789 SDValue
Op = GetPromotedInteger(
N->getOperand(0));
790 EVT OVT =
N->getValueType(0);
791 EVT NVT =
Op.getValueType();
798 if (!OVT.
isVector() && TLI.isTypeLegal(NVT) &&
799 !TLI.isOperationLegalOrCustomOrPromote(
ISD::CTTZ, NVT) &&
803 if (SDValue Result = TLI.expandCTTZ(
N, DAG)) {
809 unsigned NewOpc =
N->getOpcode();
816 Op = DAG.getNode(
ISD::OR, dl, NVT,
Op, DAG.getConstant(TopBit, dl, NVT));
819 return DAG.getNode(NewOpc, dl, NVT,
Op);
822SDValue DAGTypeLegalizer::PromoteIntRes_VP_CttzElements(
SDNode *
N) {
824 EVT NewVT = TLI.getTypeToTransformTo(*DAG.getContext(),
N->getValueType(0));
825 return DAG.getNode(
N->getOpcode(),
DL, NewVT,
N->ops());
828SDValue DAGTypeLegalizer::PromoteIntRes_EXTRACT_VECTOR_ELT(
SDNode *
N) {
830 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(),
N->getValueType(0));
832 SDValue Op0 =
N->getOperand(0);
833 SDValue Op1 =
N->getOperand(1);
837 if (TLI.getTypeAction(*DAG.getContext(), Op0.
getValueType())
839 SDValue
In = GetPromotedInteger(Op0);
843 EVT SVT =
In.getValueType().getScalarType();
846 return DAG.getAnyExtOrTrunc(Ext, dl, NVT);
854 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(),
N->getValueType(0));
856 TLI.getPreferredFPToIntOpcode(
N->getOpcode(),
N->getValueType(0), NVT);
860 if (
N->isStrictFPOpcode()) {
861 Res = DAG.
getNode(NewOpc, dl, {NVT, MVT::Other},
862 {
N->getOperand(0),
N->getOperand(1)});
865 ReplaceValueWith(SDValue(
N, 1), Res.
getValue(1));
867 Res = DAG.
getNode(NewOpc, dl, NVT,
N->getOperand(0));
882 DAG.getValueType(
N->getValueType(0).getScalarType()));
885SDValue DAGTypeLegalizer::PromoteIntRes_FP_TO_XINT_SAT(
SDNode *
N) {
887 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(),
N->getValueType(0));
889 return DAG.getNode(
N->getOpcode(), dl, NVT,
N->getOperand(0),
893SDValue DAGTypeLegalizer::PromoteIntRes_FP_TO_FP16_BF16(
SDNode *
N) {
894 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(),
N->getValueType(0));
897 return DAG.getNode(
N->getOpcode(), dl, NVT,
N->getOperand(0));
902SDValue DAGTypeLegalizer::PromoteIntRes_CONVERT_TO_ARBITRARY_FP(
SDNode *
N) {
903 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(),
N->getValueType(0));
907 N->getOperand(1),
N->getOperand(2),
N->getOperand(3));
910SDValue DAGTypeLegalizer::PromoteIntRes_STRICT_FP_TO_FP16_BF16(
SDNode *
N) {
911 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(),
N->getValueType(0));
914 SDValue Res = DAG.
getNode(
N->getOpcode(), dl, DAG.getVTList(NVT, MVT::Other),
915 N->getOperand(0),
N->getOperand(1));
916 ReplaceValueWith(SDValue(
N, 1), Res.
getValue(1));
921 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(),
N->getValueType(0));
923 return DAG.getNode(
N->getOpcode(), dl, NVT,
N->getOperand(0));
927 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(),
N->getValueType(0));
931 DAG.
getNode(
N->getOpcode(), dl, {NVT, MVT::Other},
N->getOperand(0));
935 ReplaceValueWith(SDValue(
N, 1), Res.
getValue(1));
940 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(),
N->getValueType(0));
943 if (getTypeAction(
N->getOperand(0).getValueType())
945 SDValue Res = GetPromotedInteger(
N->getOperand(0));
954 DAG.getValueType(
N->getOperand(0).getValueType()));
956 return DAG.getZeroExtendInReg(Res, dl,
N->getOperand(0).getValueType());
963 return DAG.getNode(
N->getOpcode(), dl, NVT,
N->getOperand(0));
968 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(),
N->getValueType(0));
972 SDValue Res = DAG.getExtLoad(ExtType, dl, NVT,
N->getChain(),
N->getBasePtr(),
973 N->getMemoryVT(),
N->getMemOperand());
977 ReplaceValueWith(SDValue(
N, 1), Res.
getValue(1));
982 assert(!
N->isIndexed() &&
"Indexed vp_load during type legalization!");
983 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(),
N->getValueType(0));
986 :
N->getExtensionType();
989 DAG.getExtLoadVP(ExtType, dl, NVT,
N->getChain(),
N->getBasePtr(),
990 N->getMask(),
N->getVectorLength(),
N->getMemoryVT(),
991 N->getMemOperand(),
N->isExpandingLoad());
994 ReplaceValueWith(SDValue(
N, 1), Res.
getValue(1));
999 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(),
N->getValueType(0));
1000 SDValue ExtPassThru = GetPromotedInteger(
N->getPassThru());
1007 SDValue Res = DAG.getMaskedLoad(NVT, dl,
N->getChain(),
N->getBasePtr(),
1008 N->getOffset(),
N->getMask(), ExtPassThru,
1009 N->getMemoryVT(),
N->getMemOperand(),
1010 N->getAddressingMode(), ExtType,
1011 N->isExpandingLoad());
1014 ReplaceValueWith(SDValue(
N, 1), Res.
getValue(1));
1019 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(),
N->getValueType(0));
1020 SDValue ExtPassThru = GetPromotedInteger(
N->getPassThru());
1022 "Gather result type and the passThru argument type should be the same");
1029 SDValue
Ops[] = {
N->getChain(), ExtPassThru,
N->getMask(),
N->getBasePtr(),
1030 N->getIndex(),
N->getScale() };
1031 SDValue Res = DAG.getMaskedGather(DAG.getVTList(NVT, MVT::Other),
1032 N->getMemoryVT(), dl,
Ops,
1033 N->getMemOperand(),
N->getIndexType(),
1037 ReplaceValueWith(SDValue(
N, 1), Res.
getValue(1));
1041SDValue DAGTypeLegalizer::PromoteIntRes_VECTOR_COMPRESS(
SDNode *
N) {
1042 SDValue Vec = GetPromotedInteger(
N->getOperand(0));
1043 SDValue Passthru = GetPromotedInteger(
N->getOperand(2));
1045 N->getOperand(1), Passthru);
1052 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(),
N->getValueType(1));
1053 EVT VT =
N->getValueType(0);
1054 EVT SVT = getSetCCResultType(VT);
1055 SDValue
Ops[3] = {
N->getOperand(0),
N->getOperand(1) };
1056 unsigned NumOps =
N->getNumOperands();
1059 Ops[2] = PromoteTargetBoolean(
N->getOperand(2), VT);
1062 SDValue Res = DAG.
getNode(
N->getOpcode(), dl, DAG.getVTList(VT, SVT),
1067 ReplaceValueWith(SDValue(
N, 0), Res);
1070 return DAG.getBoolExtOrTrunc(Res.
getValue(1), dl, NVT, VT);
1085 unsigned Opcode =
N->getOpcode();
1091 SExtOrZExtPromotedOperands(Op1, Op2);
1097 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), OVT);
1099 if (TLI.isSExtCheaperThanZExt(OVT, NVT)) {
1100 Op1 = SExtPromotedInteger(Op1);
1101 Op2 = SExtPromotedInteger(Op2);
1105 Op1 = ZExtPromotedInteger(Op1);
1106 Op2 = ZExtPromotedInteger(Op2);
1109 SDValue SatMax = DAG.getConstant(MaxVal, dl, NVT);
1110 SDValue
Add = DAG.getNode(
ISD::ADD, dl, NVT, Op1, Op2);
1118 Op1 = GetPromotedInteger(Op1);
1120 Op2 = ZExtPromotedInteger(Op2);
1122 Op1 = SExtPromotedInteger(Op1);
1123 Op2 = SExtPromotedInteger(Op2);
1130 if (IsShift || TLI.isOperationLegal(Opcode, PromotedType)) {
1143 "addition, subtraction or left shift");
1146 unsigned SHLAmount = NewBits - OldBits;
1147 SDValue ShiftAmount =
1148 DAG.getShiftAmountConstant(SHLAmount, PromotedType, dl);
1153 SDValue
Result = DAG.getNode(Opcode, dl, PromotedType, Op1, Op2);
1154 return DAG.getNode(ShiftOp, dl, PromotedType, Result, ShiftAmount);
1160 SDValue SatMin = DAG.getConstant(MinVal, dl, PromotedType);
1161 SDValue SatMax = DAG.getConstant(MaxVal, dl, PromotedType);
1162 SDValue
Result = DAG.getNode(AddOp, dl, PromotedType, Op1, Op2);
1171 SDValue Op1Promoted, Op2Promoted;
1177 Op1Promoted = SExtPromotedInteger(
N->getOperand(0));
1178 Op2Promoted = SExtPromotedInteger(
N->getOperand(1));
1180 Op1Promoted = ZExtPromotedInteger(
N->getOperand(0));
1181 Op2Promoted = ZExtPromotedInteger(
N->getOperand(1));
1183 EVT OldType =
N->getOperand(0).getValueType();
1195 DAG.getShiftAmountConstant(DiffSize, PromotedType, dl));
1196 SDValue
Result = DAG.getNode(
N->getOpcode(), dl, PromotedType, Op1Promoted,
1197 Op2Promoted,
N->getOperand(2));
1199 return DAG.getNode(ShiftOp, dl, PromotedType, Result,
1200 DAG.getShiftAmountConstant(DiffSize, PromotedType, dl));
1202 return DAG.getNode(
N->getOpcode(), dl, PromotedType, Op1Promoted, Op2Promoted,
1207 unsigned SatW,
bool Signed,
1210 EVT VT = V.getValueType();
1237 EVT VT =
LHS.getValueType();
1253 assert(Res &&
"Expanding DIVFIX with wide type failed?");
1259 "Tried to saturate to more than the original type?");
1268 SDValue Op1Promoted, Op2Promoted;
1274 Op1Promoted = SExtPromotedInteger(
N->getOperand(0));
1275 Op2Promoted = SExtPromotedInteger(
N->getOperand(1));
1277 Op1Promoted = ZExtPromotedInteger(
N->getOperand(0));
1278 Op2Promoted = ZExtPromotedInteger(
N->getOperand(1));
1281 unsigned Scale =
N->getConstantOperandVal(2);
1285 if (TLI.isTypeLegal(PromotedType)) {
1287 TLI.getFixedPointOperationAction(
N->getOpcode(), PromotedType, Scale);
1290 N->getValueType(0).getScalarSizeInBits();
1294 DAG.getShiftAmountConstant(Diff, PromotedType, dl));
1295 SDValue Res = DAG.
getNode(
N->getOpcode(), dl, PromotedType, Op1Promoted,
1296 Op2Promoted,
N->getOperand(2));
1299 DAG.getShiftAmountConstant(Diff, PromotedType, dl));
1305 if (SDValue Res = TLI.expandFixedPointDiv(
N->getOpcode(), dl, Op1Promoted,
1306 Op2Promoted, Scale, DAG)) {
1309 N->getValueType(0).getScalarSizeInBits(),
1317 N->getValueType(0).getScalarSizeInBits());
1320SDValue DAGTypeLegalizer::PromoteIntRes_SADDSUBO(
SDNode *
N,
unsigned ResNo) {
1322 return PromoteIntRes_Overflow(
N);
1326 SDValue
LHS = SExtPromotedInteger(
N->getOperand(0));
1327 SDValue
RHS = SExtPromotedInteger(
N->getOperand(1));
1328 EVT OVT =
N->getOperand(0).getValueType();
1329 EVT NVT =
LHS.getValueType();
1339 DAG.getValueType(OVT));
1341 Ofl = DAG.getSetCC(dl,
N->getValueType(1), Ofl, Res,
ISD::SETNE);
1344 ReplaceValueWith(SDValue(
N, 1), Ofl);
1350 EVT PromotedResultTy =
1351 TLI.getTypeToTransformTo(*DAG.getContext(),
N->getValueType(0));
1352 return DAG.
getNode(
N->getOpcode(), SDLoc(
N), PromotedResultTy,
1353 N->getOperand(0),
N->getOperand(1));
1357 SDValue
Mask =
N->getOperand(0);
1359 SDValue
LHS = GetPromotedInteger(
N->getOperand(1));
1360 SDValue
RHS = GetPromotedInteger(
N->getOperand(2));
1362 unsigned Opcode =
N->getOpcode();
1363 if (Opcode == ISD::VP_MERGE)
1364 return DAG.getNode(Opcode, SDLoc(
N),
LHS.getValueType(), Mask,
LHS,
RHS,
1366 return DAG.getNode(Opcode, SDLoc(
N),
LHS.getValueType(), Mask,
LHS,
RHS);
1370 SDValue
LHS = GetPromotedInteger(
N->getOperand(2));
1371 SDValue
RHS = GetPromotedInteger(
N->getOperand(3));
1373 LHS.getValueType(),
N->getOperand(0),
1374 N->getOperand(1),
LHS,
RHS,
N->getOperand(4));
1379 EVT InVT =
N->getOperand(OpNo).getValueType();
1380 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(),
N->getValueType(0));
1382 EVT SVT = getSetCCResultType(InVT);
1389 InVT = TLI.getTypeToTransformTo(*DAG.getContext(), InVT);
1390 SVT = getSetCCResultType(InVT);
1398 assert(SVT.
isVector() ==
N->getOperand(OpNo).getValueType().isVector() &&
1399 "Vector compare must return a vector result!");
1403 if (
N->isStrictFPOpcode()) {
1404 SDVTList VTs = DAG.getVTList({SVT, MVT::Other});
1405 SDValue Opers[] = {
N->getOperand(0),
N->getOperand(1),
1406 N->getOperand(2),
N->getOperand(3)};
1407 SetCC = DAG.
getNode(
N->getOpcode(), dl, VTs, Opers,
N->getFlags());
1410 ReplaceValueWith(SDValue(
N, 1), SetCC.
getValue(1));
1412 SetCC = DAG.
getNode(
N->getOpcode(), dl, SVT,
N->getOperand(0),
1413 N->getOperand(1),
N->getOperand(2),
N->getFlags());
1416 return DAG.getSExtOrTrunc(SetCC, dl, NVT);
1421 SDValue Arg =
N->getOperand(0);
1422 SDValue
Test =
N->getOperand(1);
1423 EVT NResVT = TLI.getTypeToTransformTo(*DAG.getContext(),
N->getValueType(0));
1428 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(),
N->getValueType(1));
1429 EVT VT =
N->getValueType(0);
1433 DAG.
getNode(
N->getOpcode(), dl, DAG.getVTList(VT, NVT),
N->getOperand(0));
1435 ReplaceValueWith(SDValue(
N, 0), Res);
1440 SDValue
LHS = GetPromotedInteger(
N->getOperand(0));
1441 SDValue
RHS =
N->getOperand(1);
1443 RHS = ZExtPromotedInteger(
RHS);
1444 return DAG.getNode(
N->getOpcode(), SDLoc(
N),
LHS.getValueType(),
LHS,
RHS);
1447SDValue DAGTypeLegalizer::PromoteIntRes_SIGN_EXTEND_INREG(
SDNode *
N) {
1448 SDValue
Op = GetPromotedInteger(
N->getOperand(0));
1450 Op.getValueType(),
Op,
N->getOperand(1));
1453SDValue DAGTypeLegalizer::PromoteIntRes_SimpleIntBinOp(
SDNode *
N) {
1457 SDValue
LHS = GetPromotedInteger(
N->getOperand(0));
1458 SDValue
RHS = GetPromotedInteger(
N->getOperand(1));
1459 return DAG.getNode(
N->getOpcode(), SDLoc(
N),
LHS.getValueType(),
LHS,
RHS);
1464 SDValue
LHS = SExtPromotedInteger(
N->getOperand(0));
1465 SDValue
RHS = SExtPromotedInteger(
N->getOperand(1));
1466 if (
N->getNumOperands() == 2)
1467 return DAG.getNode(
N->getOpcode(), SDLoc(
N),
LHS.getValueType(),
LHS,
RHS);
1468 assert(
N->getNumOperands() == 4 &&
"Unexpected number of operands!");
1469 assert((
N->getOpcode() == ISD::VP_SDIV ||
N->getOpcode() == ISD::VP_SREM) &&
1470 "Expected VP opcode");
1471 SDValue
Mask =
N->getOperand(2);
1472 SDValue EVL =
N->getOperand(3);
1473 return DAG.getNode(
N->getOpcode(), SDLoc(
N),
LHS.getValueType(),
LHS,
RHS,
1479 SDValue
LHS = ZExtPromotedInteger(
N->getOperand(0));
1480 SDValue
RHS = ZExtPromotedInteger(
N->getOperand(1));
1481 if (
N->getNumOperands() == 2)
1482 return DAG.getNode(
N->getOpcode(), SDLoc(
N),
LHS.getValueType(),
LHS,
RHS);
1483 assert(
N->getNumOperands() == 4 &&
"Unexpected number of operands!");
1484 assert((
N->getOpcode() == ISD::VP_UDIV ||
N->getOpcode() == ISD::VP_UREM) &&
1485 "Expected VP opcode");
1487 SDValue
Mask =
N->getOperand(2);
1493SDValue DAGTypeLegalizer::PromoteIntRes_ZExtMaskedIntBinOp(
SDNode *
N) {
1494 SDValue
LHS = ZExtPromotedInteger(
N->getOperand(0));
1495 SDValue
RHS = ZExtPromotedInteger(
N->getOperand(1));
1496 SDValue
Mask =
N->getOperand(2);
1497 return DAG.getNode(
N->getOpcode(), SDLoc(
N),
LHS.getValueType(),
LHS,
RHS,
1501SDValue DAGTypeLegalizer::PromoteIntRes_SExtMaskedIntBinOp(
SDNode *
N) {
1502 SDValue
LHS = SExtPromotedInteger(
N->getOperand(0));
1503 SDValue
RHS = SExtPromotedInteger(
N->getOperand(1));
1504 SDValue
Mask =
N->getOperand(2);
1505 return DAG.getNode(
N->getOpcode(), SDLoc(
N),
LHS.getValueType(),
LHS,
RHS,
1510 SDValue
LHS =
N->getOperand(0);
1511 SDValue
RHS =
N->getOperand(1);
1515 SExtOrZExtPromotedOperands(
LHS,
RHS);
1517 return DAG.getNode(
N->getOpcode(), SDLoc(
N),
1523 SDValue
LHS = SExtPromotedInteger(
N->getOperand(0));
1524 SDValue
RHS =
N->getOperand(1);
1526 RHS = ZExtPromotedInteger(
RHS);
1527 return DAG.getNode(
N->getOpcode(), SDLoc(
N),
LHS.getValueType(),
LHS,
RHS);
1531 SDValue
RHS =
N->getOperand(1);
1533 SDValue
LHS = ZExtPromotedInteger(
N->getOperand(0));
1535 RHS = ZExtPromotedInteger(
RHS);
1536 return DAG.getNode(
N->getOpcode(), SDLoc(
N),
LHS.getValueType(),
LHS,
RHS);
1541 EVT VT = TLI.getTypeToTransformTo(*DAG.getContext(), OldVT);
1542 SDValue Amt =
N->getOperand(1);
1543 unsigned Opcode =
N->getOpcode();
1554 !TLI.isOperationLegalOrCustom(Opcode, VT) &&
1557 SDValue Op0 = GetPromotedInteger(
N->getOperand(0));
1559 Amt = ZExtPromotedInteger(Amt);
1565 DAG.getConstant(OldBits,
DL, AmtVT));
1566 SDValue HiShift = DAG.getShiftAmountConstant(OldBits, VT,
DL);
1567 SDValue
Hi = DAG.getNode(
ISD::SHL,
DL, VT, Op0, HiShift);
1568 SDValue
Lo = DAG.getZeroExtendInReg(Op0,
DL, OldVT);
1580 SDValue Res = TLI.expandROT(
N,
true , DAG);
1581 ReplaceValueWith(SDValue(
N, 0), Res);
1586 SDValue
Hi = GetPromotedInteger(
N->getOperand(0));
1587 SDValue
Lo = GetPromotedInteger(
N->getOperand(1));
1590 Amt = ZExtPromotedInteger(Amt);
1594 EVT OldVT =
N->getOperand(0).getValueType();
1595 EVT VT =
Lo.getValueType();
1596 unsigned Opcode =
N->getOpcode();
1603 DAG.getConstant(OldBits,
DL, AmtVT));
1611 !TLI.isOperationLegalOrCustom(Opcode, VT)) {
1612 SDValue HiShift = DAG.getShiftAmountConstant(OldBits, VT,
DL);
1614 Lo = DAG.getZeroExtendInReg(
Lo,
DL, OldVT);
1624 DAG.getShiftAmountConstant(NewBits - OldBits, VT,
DL));
1630 DAG.getConstant(NewBits - OldBits,
DL, AmtVT));
1632 return DAG.getNode(Opcode,
DL, VT,
Hi,
Lo, Amt);
1636 unsigned Opcode =
N->getOpcode();
1639 EVT OldVT =
N->getOperand(0).getValueType();
1640 EVT VT = TLI.getTypeToTransformTo(*DAG.getContext(), OldVT);
1645 if (!TLI.isOperationLegalOrCustomOrPromote(
ISD::CLMUL, VT) &&
1647 TLI.isOperationLegalOrCustom(
1648 ISD::CLMUL, TLI.getRegisterType(*DAG.getContext(), VT)))) {
1649 if (SDValue Res = TLI.expandCLMUL(
N, DAG))
1652 SDValue
X = GetPromotedInteger(
N->getOperand(0));
1653 SDValue
Y = GetPromotedInteger(
N->getOperand(1));
1657 SDValue
X = ZExtPromotedInteger(
N->getOperand(0));
1658 SDValue
Y = ZExtPromotedInteger(
N->getOperand(1));
1662 if (NewBits < 2 * OldBits) {
1664 unsigned ShAmt = Opcode ==
ISD::CLMULH ? OldBits : OldBits - 1;
1666 DAG.getShiftAmountConstant(ShAmt, VT,
DL));
1668 ShAmt = Opcode ==
ISD::CLMULH ? NewBits - OldBits : NewBits - OldBits + 1;
1670 DAG.getShiftAmountConstant(ShAmt, VT,
DL));
1675 unsigned ShAmt = Opcode ==
ISD::CLMULH ? OldBits : OldBits - 1;
1677 DAG.getShiftAmountConstant(ShAmt, VT,
DL));
1682 EVT VT = TLI.getTypeToTransformTo(*DAG.getContext(),
N->getValueType(0));
1683 if (!TLI.isOperationLegalOrCustomOrPromote(
ISD::PEXT, VT)) {
1684 if (SDValue Res = TLI.expandPEXT(
N, DAG))
1689 SDValue
X = GetPromotedInteger(
N->getOperand(0));
1690 SDValue
Y = ZExtPromotedInteger(
N->getOperand(1));
1696 EVT VT = TLI.getTypeToTransformTo(*DAG.getContext(),
N->getValueType(0));
1697 if (!TLI.isOperationLegalOrCustomOrPromote(
ISD::PDEP, VT)) {
1698 if (SDValue Res = TLI.expandPDEP(
N, DAG))
1703 SDValue
X = GetPromotedInteger(
N->getOperand(0));
1704 SDValue
Y = GetPromotedInteger(
N->getOperand(1));
1710 EVT VT =
N->getValueType(0);
1711 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), VT);
1718 LHS = SExtPromotedInteger(
N->getOperand(0));
1719 RHS = SExtPromotedInteger(
N->getOperand(1));
1721 LHS = ZExtPromotedInteger(
N->getOperand(0));
1722 RHS = ZExtPromotedInteger(
N->getOperand(1));
1729 DAG.getShiftAmountConstant(BW, NVT, dl));
1733 DAG.getShiftAmountConstant(NBW - BW, NVT, dl));
1734 return DAG.getNode(
N->getOpcode(), dl, NVT,
LHS,
RHS);
1738 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(),
N->getValueType(0));
1750 Res = GetPromotedInteger(InOp);
1757 "Dst and Src must have the same number of elements");
1759 "Promoted vector type must be a power of two");
1762 GetSplitVector(InOp, EOp1, EOp2);
1771 SDValue WideInOp = GetWidenedVector(InOp);
1776 N->getValueType(0).getScalarType(), NumElem);
1777 SDValue WideTrunc = DAG.getNode(
ISD::TRUNCATE, dl, TruncVT, WideInOp);
1785 SDValue ZeroIdx = DAG.getVectorIdxConstant(0, dl);
1794SDValue DAGTypeLegalizer::PromoteIntRes_UADDSUBO(
SDNode *
N,
unsigned ResNo) {
1796 return PromoteIntRes_Overflow(
N);
1800 SDValue
LHS = ZExtPromotedInteger(
N->getOperand(0));
1801 SDValue
RHS = ZExtPromotedInteger(
N->getOperand(1));
1802 EVT OVT =
N->getOperand(0).getValueType();
1803 EVT NVT =
LHS.getValueType();
1812 SDValue Ofl = DAG.getZeroExtendInReg(Res, dl, OVT);
1814 Ofl = DAG.getSetCC(dl,
N->getValueType(1), Ofl, Res,
ISD::SETNE);
1817 ReplaceValueWith(SDValue(
N, 1), Ofl);
1828 return PromoteIntRes_Overflow(
N);
1840 SDValue
LHS = SExtPromotedInteger(
N->getOperand(0));
1841 SDValue
RHS = SExtPromotedInteger(
N->getOperand(1));
1843 EVT ValueVTs[] = {
LHS.getValueType(),
N->getValueType(1)};
1846 SDValue Res = DAG.
getNode(
N->getOpcode(), SDLoc(
N), DAG.getVTList(ValueVTs),
1850 ReplaceValueWith(SDValue(
N, 1), Res.
getValue(1));
1852 return SDValue(Res.
getNode(), 0);
1857 assert(ResNo == 1 &&
"Don't know how to promote other results yet.");
1858 return PromoteIntRes_Overflow(
N);
1862 EVT OVT =
N->getValueType(0);
1863 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), OVT);
1869 !TLI.isOperationLegalOrCustomOrPromote(
ISD::ABS, NVT) &&
1871 !TLI.isOperationLegal(
ISD::SMAX, NVT)) {
1872 if (SDValue Res = TLI.expandABS(
N, DAG))
1876 SDValue Op0 = SExtPromotedInteger(
N->getOperand(0));
1880SDValue DAGTypeLegalizer::PromoteIntRes_XMULO(
SDNode *
N,
unsigned ResNo) {
1883 return PromoteIntRes_Overflow(
N);
1885 SDValue
LHS =
N->getOperand(0),
RHS =
N->getOperand(1);
1887 EVT SmallVT =
LHS.getValueType();
1894 LHS = SExtPromotedInteger(
LHS);
1895 RHS = SExtPromotedInteger(
RHS);
1897 LHS = ZExtPromotedInteger(
LHS);
1898 RHS = ZExtPromotedInteger(
RHS);
1900 SDVTList VTs = DAG.getVTList(
LHS.getValueType(),
N->getValueType(1));
1901 SDValue
Mul = DAG.getNode(
N->getOpcode(),
DL, VTs,
LHS,
RHS);
1912 DAG.getShiftAmountConstant(Shift,
Mul.getValueType(),
DL));
1913 Overflow = DAG.getSetCC(
DL,
N->getValueType(1),
Hi,
1914 DAG.getConstant(0,
DL,
Hi.getValueType()),
1919 Mul, DAG.getValueType(SmallVT));
1926 SDValue(
Mul.getNode(), 1));
1929 ReplaceValueWith(SDValue(
N, 1), Overflow);
1934 return DAG.getUNDEF(TLI.getTypeToTransformTo(*DAG.getContext(),
1935 N->getValueType(0)));
1939 EVT VT = TLI.getTypeToTransformTo(*DAG.getContext(),
N->getValueType(0));
1941 const APInt &MulImm =
N->getConstantOperandAPInt(0);
1948 EVT VT =
N->getValueType(0);
1951 MVT RegVT = TLI.getRegisterType(*DAG.getContext(), VT);
1952 unsigned NumRegs = TLI.getNumRegisters(*DAG.getContext(), VT);
1956 for (
unsigned i = 0; i < NumRegs; ++i) {
1957 Parts[i] = DAG.getVAArg(RegVT, dl, Chain, Ptr,
N->getOperand(2),
1958 N->getConstantOperandVal(3));
1963 if (DAG.getDataLayout().isBigEndian())
1964 std::reverse(Parts.begin(), Parts.end());
1967 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(),
N->getValueType(0));
1969 for (
unsigned i = 1; i < NumRegs; ++i) {
1974 DAG.getShiftAmountConstant(i * RegVT.
getSizeInBits(), NVT, dl));
1980 ReplaceValueWith(SDValue(
N, 1), Chain);
1993bool DAGTypeLegalizer::PromoteIntegerOperand(
SDNode *
N,
unsigned OpNo) {
1995 SDValue Res = SDValue();
1996 if (CustomLowerNode(
N,
N->getOperand(OpNo).getValueType(),
false)) {
2001 switch (
N->getOpcode()) {
2004 dbgs() <<
"PromoteIntegerOperand Op #" << OpNo <<
": ";
2005 N->dump(&DAG);
dbgs() <<
"\n";
2011 Res = PromoteIntOp_ANY_EXTEND_VECTOR_INREG(
N);
2017 case ISD::BR_CC: Res = PromoteIntOp_BR_CC(
N, OpNo);
break;
2018 case ISD::BRCOND: Res = PromoteIntOp_BRCOND(
N, OpNo);
break;
2023 Res = PromoteIntOp_COND_LOOP(
N, OpNo);
2027 Res = PromoteIntOp_FAKE_USE(
N);
2030 Res = PromoteIntOp_INSERT_VECTOR_ELT(
N, OpNo);
2034 Res = PromoteIntOp_ScalarOp(
N);
2037 case ISD::SELECT: Res = PromoteIntOp_SELECT(
N, OpNo);
break;
2039 case ISD::SETCC: Res = PromoteIntOp_SETCC(
N, OpNo);
break;
2057 Res = PromoteIntOp_VECTOR_COMPRESS(
N, OpNo);
2064 Res = PromoteIntOp_CONVERT_FROM_ARBITRARY_FP(
N);
2079 Res = PromoteIntOp_Shift(
N);
2083 case ISD::UCMP: Res = PromoteIntOp_CMP(
N);
break;
2086 case ISD::FSHR: Res = PromoteIntOp_FunnelShift(
N);
break;
2112 case ISD::VP_REDUCE_ADD:
2113 case ISD::VP_REDUCE_MUL:
2114 case ISD::VP_REDUCE_AND:
2115 case ISD::VP_REDUCE_OR:
2116 case ISD::VP_REDUCE_XOR:
2117 case ISD::VP_REDUCE_SMAX:
2118 case ISD::VP_REDUCE_SMIN:
2119 case ISD::VP_REDUCE_UMAX:
2120 case ISD::VP_REDUCE_UMIN:
2121 Res = PromoteIntOp_VP_REDUCE(
N, OpNo);
2126 Res = PromoteIntOp_STACKMAP(
N, OpNo);
2129 Res = PromoteIntOp_PATCHPOINT(
N, OpNo);
2132 Res = PromoteIntOp_WRITE_REGISTER(
N, OpNo);
2134 case ISD::EXPERIMENTAL_VP_STRIDED_LOAD:
2135 case ISD::EXPERIMENTAL_VP_STRIDED_STORE:
2136 Res = PromoteIntOp_VP_STRIDED(
N, OpNo);
2138 case ISD::EXPERIMENTAL_VP_SPLICE:
2139 Res = PromoteIntOp_VP_SPLICE(
N, OpNo);
2142 Res = PromoteIntOp_VECTOR_HISTOGRAM(
N, OpNo);
2147 Res = PromoteIntOp_UnaryBooleanVectorOp(
N, OpNo);
2150 Res = PromoteIntOp_GET_ACTIVE_LANE_MASK(
N);
2153 Res = PromoteIntOp_VECTOR_MATCH(
N, OpNo);
2159 Res = PromoteIntOp_MaskedBinOp(
N, OpNo);
2164 Res = PromoteIntOp_PARTIAL_REDUCE_MLA(
N);
2167 Res = PromoteIntOp_VECTOR_REPEAT(
N);
2171 Res = PromoteIntOp_LOOP_DEPENDENCE_MASK(
N);
2176 if (!Res.
getNode())
return false;
2183 const bool IsStrictFp =
N->isStrictFPOpcode();
2185 N->getNumValues() == (IsStrictFp ? 2 : 1) &&
2186 "Invalid operand expansion");
2190 ReplaceValueWith(SDValue(
N, 0), Res);
2192 ReplaceValueWith(SDValue(
N, 1), SDValue(Res.
getNode(), 1));
2201 SDValue OpL = GetPromotedInteger(
LHS);
2202 SDValue OpR = GetPromotedInteger(
RHS);
2204 if (TLI.isSExtCheaperThanZExt(
LHS.getValueType(), OpL.
getValueType())) {
2208 unsigned OpLEffectiveBits =
2209 DAG.computeKnownBits(OpL).countMaxActiveBits();
2210 unsigned OpREffectiveBits =
2211 DAG.computeKnownBits(OpR).countMaxActiveBits();
2212 if (OpLEffectiveBits <=
LHS.getScalarValueSizeInBits() &&
2213 OpREffectiveBits <=
RHS.getScalarValueSizeInBits()) {
2220 LHS = SExtPromotedInteger(
LHS);
2221 RHS = SExtPromotedInteger(
RHS);
2230 unsigned OpLEffectiveBits = DAG.ComputeMaxSignificantBits(OpL);
2231 unsigned OpREffectiveBits = DAG.ComputeMaxSignificantBits(OpR);
2232 if (OpLEffectiveBits <=
LHS.getScalarValueSizeInBits() &&
2233 OpREffectiveBits <=
RHS.getScalarValueSizeInBits()) {
2240 LHS = ZExtPromotedInteger(
LHS);
2241 RHS = ZExtPromotedInteger(
RHS);
2255 LHS = SExtPromotedInteger(
LHS);
2256 RHS = SExtPromotedInteger(
RHS);
2261 "Unknown integer comparison!");
2263 SExtOrZExtPromotedOperands(
LHS,
RHS);
2267 SDValue
Op = GetPromotedInteger(
N->getOperand(0));
2271SDValue DAGTypeLegalizer::PromoteIntOp_ANY_EXTEND_VECTOR_INREG(
SDNode *
N) {
2272 SDValue
Op = GetPromotedInteger(
N->getOperand(0));
2273 EVT ResVT =
N->getValueType(0);
2274 EVT OpVT =
Op.getValueType();
2277 Op = DAG.getExtractSubvector(SDLoc(
Op), NewVT,
Op, 0);
2282 SDValue Op1 = GetPromotedInteger(
N->getOperand(1));
2283 return DAG.getAtomic(
N->getOpcode(), SDLoc(
N),
N->getMemoryVT(),
2284 N->getChain(), Op1,
N->getBasePtr(),
N->getMemOperand());
2288 EVT OutVT =
N->getValueType(0);
2291 EVT NInVT = TLI.getTypeToTransformTo(*DAG.getContext(), InVT);
2294 switch (getTypeAction(InVT)) {
2298 DAG.getDataLayout().isLittleEndian()) {
2308 if (isTypeLegal(WideVecVT)) {
2309 SDValue Promoted = GetPromotedInteger(InOp);
2310 SDValue Cast = DAG.getNode(
ISD::BITCAST, dl, WideVecVT, Promoted);
2312 DAG.getVectorIdxConstant(0, dl));
2325 return CreateStackStoreLoad(InOp, OutVT);
2328SDValue DAGTypeLegalizer::PromoteIntOp_BR_CC(
SDNode *
N,
unsigned OpNo) {
2329 assert(OpNo == 2 &&
"Don't know how to promote this operand!");
2331 SDValue
LHS =
N->getOperand(2);
2332 SDValue
RHS =
N->getOperand(3);
2337 return SDValue(DAG.UpdateNodeOperands(
N,
N->getOperand(0),
2338 N->getOperand(1),
LHS,
RHS,
N->getOperand(4)),
2342SDValue DAGTypeLegalizer::PromoteIntOp_BRCOND(
SDNode *
N,
unsigned OpNo) {
2343 assert(OpNo == 1 &&
"only know how to promote condition");
2346 SDValue
Cond = PromoteTargetBoolean(
N->getOperand(1), MVT::Other);
2349 return SDValue(DAG.UpdateNodeOperands(
N,
N->getOperand(0),
Cond,
2350 N->getOperand(2)), 0);
2353SDValue DAGTypeLegalizer::PromoteIntOp_COND_LOOP(
SDNode *
N,
unsigned OpNo) {
2354 assert(OpNo == 1 &&
"only know how to promote condition");
2357 SDValue
Cond = PromoteTargetBoolean(
N->getOperand(1), MVT::Other);
2360 return SDValue(DAG.UpdateNodeOperands(
N,
N->getOperand(0),
Cond), 0);
2365 EVT OVT =
N->getOperand(0).getValueType();
2366 SDValue
Lo = ZExtPromotedInteger(
N->getOperand(0));
2367 SDValue
Hi = GetPromotedInteger(
N->getOperand(1));
2368 assert(
Lo.getValueType() ==
N->getValueType(0) &&
"Operand over promoted?");
2373 DAG.getShiftAmountConstant(OVT.
getSizeInBits(),
N->getValueType(0), dl));
2374 return DAG.getNode(
ISD::OR, dl,
N->getValueType(0),
Lo,
Hi);
2383 assert(!((NumElts & 1) && (!TLI.isTypeLegal(VecVT))) &&
2384 "Legal vector of one illegal element?");
2389 assert(
N->getOperand(0).getValueSizeInBits() >=
2390 N->getValueType(0).getScalarSizeInBits() &&
2391 "Type of inserted value narrower than vector element type!");
2394 for (
unsigned i = 0; i < NumElts; ++i)
2395 NewOps.
push_back(GetPromotedInteger(
N->getOperand(i)));
2397 return SDValue(DAG.UpdateNodeOperands(
N, NewOps), 0);
2400SDValue DAGTypeLegalizer::PromoteIntOp_INSERT_VECTOR_ELT(
SDNode *
N,
2407 assert(
N->getOperand(1).getValueSizeInBits() >=
2408 N->getValueType(0).getScalarSizeInBits() &&
2409 "Type of inserted value narrower than vector element type!");
2410 return SDValue(DAG.UpdateNodeOperands(
N,
N->getOperand(0),
2411 GetPromotedInteger(
N->getOperand(1)),
2416 assert(OpNo == 2 &&
"Different operand and result vector types?");
2419 SDValue
Idx = DAG.getZExtOrTrunc(
N->getOperand(2), SDLoc(
N),
2420 TLI.getVectorIdxTy(DAG.getDataLayout()));
2421 return SDValue(DAG.UpdateNodeOperands(
N,
N->getOperand(0),
2422 N->getOperand(1), Idx), 0);
2426 SDValue
Op = GetPromotedInteger(
N->getOperand(0));
2430 return SDValue(DAG.UpdateNodeOperands(
N,
Op), 0);
2433SDValue DAGTypeLegalizer::PromoteIntOp_SELECT(
SDNode *
N,
unsigned OpNo) {
2434 assert(OpNo == 0 &&
"Only know how to promote the condition!");
2435 SDValue
Cond =
N->getOperand(0);
2436 EVT OpTy =
N->getOperand(1).getValueType();
2439 if (SDValue Res = WidenVSELECTMask(
N))
2440 return DAG.getNode(
N->getOpcode(), SDLoc(
N),
N->getValueType(0),
2441 Res,
N->getOperand(1),
N->getOperand(2));
2445 Cond = PromoteTargetBoolean(
Cond, OpVT);
2447 return SDValue(DAG.UpdateNodeOperands(
N,
Cond,
N->getOperand(1),
2448 N->getOperand(2)), 0);
2451SDValue DAGTypeLegalizer::PromoteIntOp_SELECT_CC(
SDNode *
N,
unsigned OpNo) {
2452 assert(OpNo == 0 &&
"Don't know how to promote this operand!");
2454 SDValue
LHS =
N->getOperand(0);
2455 SDValue
RHS =
N->getOperand(1);
2459 return SDValue(DAG.UpdateNodeOperands(
N,
LHS,
RHS,
N->getOperand(2),
2460 N->getOperand(3),
N->getOperand(4)), 0);
2463SDValue DAGTypeLegalizer::PromoteIntOp_SETCC(
SDNode *
N,
unsigned OpNo) {
2464 assert(OpNo == 0 &&
"Don't know how to promote this operand!");
2466 SDValue
LHS =
N->getOperand(0);
2467 SDValue
RHS =
N->getOperand(1);
2471 return SDValue(DAG.UpdateNodeOperands(
N,
LHS,
RHS,
N->getOperand(2)), 0);
2475 return SDValue(DAG.UpdateNodeOperands(
N,
N->getOperand(0),
2476 ZExtPromotedInteger(
N->getOperand(1))), 0);
2480 SDValue
LHS =
N->getOperand(0);
2481 SDValue
RHS =
N->getOperand(1);
2484 LHS = SExtPromotedInteger(
LHS);
2485 RHS = SExtPromotedInteger(
RHS);
2487 SExtOrZExtPromotedOperands(
LHS,
RHS);
2490 return SDValue(DAG.UpdateNodeOperands(
N,
LHS,
RHS), 0);
2494 return SDValue(DAG.UpdateNodeOperands(
N,
N->getOperand(0),
N->getOperand(1),
2495 ZExtPromotedInteger(
N->getOperand(2))), 0);
2499 SDValue
Op = GetPromotedInteger(
N->getOperand(0));
2503 Op, DAG.getValueType(
N->getOperand(0).getValueType()));
2507 return SDValue(DAG.UpdateNodeOperands(
N,
2508 SExtPromotedInteger(
N->getOperand(0))), 0);
2511SDValue DAGTypeLegalizer::PromoteIntOp_STRICT_SINT_TO_FP(
SDNode *
N) {
2512 return SDValue(DAG.UpdateNodeOperands(
N,
N->getOperand(0),
2513 SExtPromotedInteger(
N->getOperand(1))), 0);
2518 SDValue Ch =
N->getChain(), Ptr =
N->getBasePtr();
2521 SDValue Val = GetPromotedInteger(
N->getValue());
2524 return DAG.getTruncStore(Ch, dl, Val, Ptr,
2525 N->getMemoryVT(),
N->getMemOperand());
2531 assert(OpNo == 1 &&
"Unexpected operand for promotion");
2532 assert(!
N->isIndexed() &&
"expecting unindexed vp_store!");
2534 SDValue DataOp = GetPromotedInteger(
N->getValue());
2535 return DAG.getTruncStoreVP(
N->getChain(), SDLoc(
N), DataOp,
N->getBasePtr(),
2536 N->getMask(),
N->getVectorLength(),
2537 N->getMemoryVT(),
N->getMemOperand(),
2538 N->isCompressingStore());
2543 SDValue DataOp =
N->getValue();
2544 SDValue
Mask =
N->getMask();
2549 Mask = PromoteTargetBoolean(Mask, DataVT);
2552 return SDValue(DAG.UpdateNodeOperands(
N, NewOps), 0);
2555 assert(OpNo == 1 &&
"Unexpected operand for promotion");
2556 DataOp = GetPromotedInteger(DataOp);
2558 return DAG.getMaskedStore(
N->getChain(), SDLoc(
N), DataOp,
N->getBasePtr(),
2559 N->getOffset(), Mask,
N->getMemoryVT(),
2560 N->getMemOperand(),
N->getAddressingMode(),
2561 true,
N->isCompressingStore());
2566 assert(OpNo == 3 &&
"Only know how to promote the mask!");
2567 EVT DataVT =
N->getValueType(0);
2568 SDValue
Mask = PromoteTargetBoolean(
N->getOperand(OpNo), DataVT);
2570 NewOps[OpNo] =
Mask;
2571 SDNode *Res = DAG.UpdateNodeOperands(
N, NewOps);
2573 return SDValue(Res, 0);
2576 ReplaceValueWith(SDValue(
N, 0), SDValue(Res, 0));
2577 ReplaceValueWith(SDValue(
N, 1), SDValue(Res, 1));
2587 EVT DataVT =
N->getValueType(0);
2588 NewOps[OpNo] = PromoteTargetBoolean(
N->getOperand(OpNo), DataVT);
2589 }
else if (OpNo == 4) {
2591 if (
N->isIndexSigned())
2593 NewOps[OpNo] = SExtPromotedInteger(
N->getOperand(OpNo));
2595 NewOps[OpNo] = ZExtPromotedInteger(
N->getOperand(OpNo));
2597 NewOps[OpNo] = GetPromotedInteger(
N->getOperand(OpNo));
2599 SDNode *Res = DAG.UpdateNodeOperands(
N, NewOps);
2601 return SDValue(Res, 0);
2604 ReplaceValueWith(SDValue(
N, 0), SDValue(Res, 0));
2605 ReplaceValueWith(SDValue(
N, 1), SDValue(Res, 1));
2611 bool TruncateStore =
N->isTruncatingStore();
2616 EVT DataVT =
N->getValue().getValueType();
2617 NewOps[OpNo] = PromoteTargetBoolean(
N->getOperand(OpNo), DataVT);
2618 }
else if (OpNo == 4) {
2620 if (
N->isIndexSigned())
2622 NewOps[OpNo] = SExtPromotedInteger(
N->getOperand(OpNo));
2624 NewOps[OpNo] = ZExtPromotedInteger(
N->getOperand(OpNo));
2626 NewOps[OpNo] = GetPromotedInteger(
N->getOperand(OpNo));
2627 TruncateStore =
true;
2630 return DAG.getMaskedScatter(DAG.getVTList(MVT::Other),
N->getMemoryVT(),
2631 SDLoc(
N), NewOps,
N->getMemOperand(),
2632 N->getIndexType(), TruncateStore);
2637 assert(OpNo == 1 &&
"Can only promote VECTOR_COMPRESS mask.");
2641 SDValue
Mask = PromoteTargetBoolean(
N->getOperand(1), VT);
2646 SDValue
Op = GetPromotedInteger(
N->getOperand(0));
2651 return SDValue(DAG.UpdateNodeOperands(
N,
2652 ZExtPromotedInteger(
N->getOperand(0))), 0);
2655SDValue DAGTypeLegalizer::PromoteIntOp_CONVERT_FROM_ARBITRARY_FP(
SDNode *
N) {
2656 return SDValue(DAG.UpdateNodeOperands(
N, GetPromotedInteger(
N->getOperand(0)),
2661SDValue DAGTypeLegalizer::PromoteIntOp_STRICT_UINT_TO_FP(
SDNode *
N) {
2662 return SDValue(DAG.UpdateNodeOperands(
N,
N->getOperand(0),
2663 ZExtPromotedInteger(
N->getOperand(1))), 0);
2668 SDValue Src =
N->getOperand(0);
2669 SDValue
Op = GetPromotedInteger(Src);
2670 EVT VT =
N->getValueType(0);
2675 if (
N->getFlags().hasNonNeg() &&
Op.getValueType() == VT &&
2676 TLI.isSExtCheaperThanZExt(Src.getValueType(), VT)) {
2677 unsigned OpEffectiveBits = DAG.ComputeMaxSignificantBits(
Op);
2678 if (OpEffectiveBits <= Src.getScalarValueSizeInBits())
2683 return DAG.getZeroExtendInReg(
Op, dl, Src.getValueType());
2687 SDValue Op2 = ZExtPromotedInteger(
N->getOperand(2));
2689 DAG.UpdateNodeOperands(
N,
N->getOperand(0),
N->getOperand(1), Op2), 0);
2692SDValue DAGTypeLegalizer::PromoteIntOp_FRAMERETURNADDR(
SDNode *
N) {
2694 SDValue
Op = ZExtPromotedInteger(
N->getOperand(0));
2695 return SDValue(DAG.UpdateNodeOperands(
N,
Op), 0);
2700 SDValue Chain = IsStrict ?
N->getOperand(0) : SDValue();
2704 unsigned OpOffset = IsStrict ? 1 : 0;
2708 RTLIB::Libcall LC = IsPowI ? RTLIB::getPOWI(
N->getValueType(0))
2711 RTLIB::LibcallImpl LCImpl = DAG.getLibcalls().getLibcallImpl(LC);
2712 if (LCImpl == RTLIB::Unsupported) {
2718 if (IsPowI &&
N->getValueType(0).isVector())
2719 return DAG.UnrollVectorOp(
N);
2721 NewOps[1 + OpOffset] = SExtPromotedInteger(
N->getOperand(1 + OpOffset));
2722 return SDValue(DAG.UpdateNodeOperands(
N, NewOps), 0);
2734 if (
N->getOperand(1 + OpOffset).getScalarValueSizeInBits() >
2735 DAG.getLibInfo().getIntSize()) {
2736 const Function &Fn = DAG.getMachineFunction().getFunction();
2737 Fn.getContext().diagnose(DiagnosticInfoLegalizationFailure(
2738 Twine(IsPowI ?
"powi" :
"ldexp") +
2739 " exponent does not match sizeof(int)",
2740 Fn, N->getDebugLoc()));
2742 ReplaceValueWith(SDValue(N, 1), Chain);
2743 ReplaceValueWith(SDValue(N, 0), DAG.getPOISON(N->getValueType(0)));
2747 TargetLowering::MakeLibCallOptions CallOptions;
2748 CallOptions.setIsSigned(
true);
2749 SDValue
Ops[2] = {N->getOperand(0 + OpOffset), N->getOperand(1 + OpOffset)};
2750 std::pair<SDValue, SDValue> Tmp = TLI.makeLibCall(
2751 DAG, LCImpl,
N->getValueType(0),
Ops, CallOptions, SDLoc(
N), Chain);
2752 ReplaceValueWith(SDValue(
N, 0), Tmp.first);
2754 ReplaceValueWith(SDValue(
N, 1), Tmp.second);
2759 switch (
N->getOpcode()) {
2767 case ISD::VP_REDUCE_ADD:
2768 case ISD::VP_REDUCE_MUL:
2769 case ISD::VP_REDUCE_AND:
2770 case ISD::VP_REDUCE_OR:
2771 case ISD::VP_REDUCE_XOR:
2775 case ISD::VP_REDUCE_SMAX:
2776 case ISD::VP_REDUCE_SMIN:
2780 case ISD::VP_REDUCE_UMAX:
2781 case ISD::VP_REDUCE_UMIN:
2791 return GetPromotedInteger(V);
2793 return SExtPromotedInteger(V);
2795 return ZExtPromotedInteger(V);
2801 SDValue
Op = PromoteIntOpVectorReduction(
N,
N->getOperand(0));
2803 EVT OrigEltVT =
N->getOperand(0).getValueType().getVectorElementType();
2804 EVT InVT =
Op.getValueType();
2806 EVT ResVT =
N->getValueType(0);
2807 unsigned Opcode =
N->getOpcode();
2824 switch (TLI.getBooleanContents(InVT)) {
2827 Op = ZExtPromotedInteger(
N->getOperand(0));
2830 Op = SExtPromotedInteger(
N->getOperand(0));
2843 switch (TLI.getBooleanContents(InVT)) {
2846 Op = ZExtPromotedInteger(
N->getOperand(0));
2849 Op = SExtPromotedInteger(
N->getOperand(0));
2855 return DAG.getNode(Opcode, SDLoc(
N), ResVT,
Op);
2859 SDValue Reduce = DAG.getNode(Opcode, dl, EltVT,
Op);
2863SDValue DAGTypeLegalizer::PromoteIntOp_VP_REDUCE(
SDNode *
N,
unsigned OpNo) {
2865 SDValue
Op =
N->getOperand(OpNo);
2870 NewOps[2] = PromoteTargetBoolean(
Op,
N->getOperand(1).getValueType());
2871 return SDValue(DAG.UpdateNodeOperands(
N, NewOps), 0);
2874 assert(OpNo == 1 &&
"Unexpected operand for promotion");
2876 Op = PromoteIntOpVectorReduction(
N,
Op);
2880 EVT VT =
N->getValueType(0);
2881 EVT EltVT =
Op.getValueType().getScalarType();
2884 return DAG.getNode(
N->getOpcode(), SDLoc(
N), VT, NewOps);
2891 SDValue Reduce = DAG.
getNode(
N->getOpcode(),
DL, EltVT, NewOps);
2896 SDValue
Op = ZExtPromotedInteger(
N->getOperand(1));
2897 return SDValue(DAG.UpdateNodeOperands(
N,
N->getOperand(0),
Op), 0);
2900SDValue DAGTypeLegalizer::PromoteIntOp_STACKMAP(
SDNode *
N,
unsigned OpNo) {
2903 NewOps[OpNo] = GetPromotedInteger(NewOps[OpNo]);
2904 return SDValue(DAG.UpdateNodeOperands(
N, NewOps), 0);
2907SDValue DAGTypeLegalizer::PromoteIntOp_PATCHPOINT(
SDNode *
N,
unsigned OpNo) {
2910 NewOps[OpNo] = GetPromotedInteger(NewOps[OpNo]);
2911 return SDValue(DAG.UpdateNodeOperands(
N, NewOps), 0);
2916 const Function &Fn = DAG.getMachineFunction().getFunction();
2918 "cannot use llvm.write_register with illegal type", Fn,
2920 return N->getOperand(0);
2923SDValue DAGTypeLegalizer::PromoteIntOp_VP_STRIDED(
SDNode *
N,
unsigned OpNo) {
2924 assert((
N->getOpcode() == ISD::EXPERIMENTAL_VP_STRIDED_LOAD && OpNo == 3) ||
2925 (
N->getOpcode() == ISD::EXPERIMENTAL_VP_STRIDED_STORE && OpNo == 4));
2928 NewOps[OpNo] = SExtPromotedInteger(
N->getOperand(OpNo));
2929 SDNode *Res = DAG.UpdateNodeOperands(
N, NewOps);
2931 return SDValue(Res, 0);
2934 ReplaceValueWith(SDValue(
N, 0), SDValue(Res, 0));
2935 ReplaceValueWith(SDValue(
N, 1), SDValue(Res, 1));
2939SDValue DAGTypeLegalizer::PromoteIntOp_VP_SPLICE(
SDNode *
N,
unsigned OpNo) {
2943 NewOps[OpNo] = SExtPromotedInteger(
N->getOperand(OpNo));
2944 return SDValue(DAG.UpdateNodeOperands(
N, NewOps), 0);
2947 assert((OpNo == 4 || OpNo == 5) &&
"Unexpected operand for promotion");
2949 NewOps[OpNo] = ZExtPromotedInteger(
N->getOperand(OpNo));
2950 return SDValue(DAG.UpdateNodeOperands(
N, NewOps), 0);
2953SDValue DAGTypeLegalizer::PromoteIntOp_VECTOR_HISTOGRAM(
SDNode *
N,
2955 assert(OpNo == 1 &&
"Unexpected operand for promotion");
2957 NewOps[1] = GetPromotedInteger(
N->getOperand(1));
2958 return SDValue(DAG.UpdateNodeOperands(
N, NewOps), 0);
2961SDValue DAGTypeLegalizer::PromoteIntOp_UnaryBooleanVectorOp(
SDNode *
N,
2963 assert(OpNo == 0 &&
"Unexpected operand for promotion");
2964 SDValue
Op =
N->getOperand(0);
2967 if (TLI.getBooleanContents(
Op.getValueType()) ==
2969 NewOp = SExtPromotedInteger(
Op);
2971 NewOp = ZExtPromotedInteger(
Op);
2973 return SDValue(DAG.UpdateNodeOperands(
N, NewOp), 0);
2976SDValue DAGTypeLegalizer::PromoteIntOp_GET_ACTIVE_LANE_MASK(
SDNode *
N) {
2978 NewOps[0] = ZExtPromotedInteger(
N->getOperand(0));
2979 NewOps[1] = ZExtPromotedInteger(
N->getOperand(1));
2980 return SDValue(DAG.UpdateNodeOperands(
N, NewOps), 0);
2983SDValue DAGTypeLegalizer::PromoteIntOp_VECTOR_MATCH(
SDNode *
N,
unsigned OpNo) {
2984 assert(OpNo < 3 &&
"Unexpected operand for promotion");
2986 return TLI.expandVectorMatch(
N, DAG);
2989 NewOps[2] = PromoteTargetBoolean(
N->getOperand(2),
N->getValueType(0));
2990 return SDValue(DAG.UpdateNodeOperands(
N, NewOps), 0);
2993SDValue DAGTypeLegalizer::PromoteIntOp_MaskedBinOp(
SDNode *
N,
unsigned OpNo) {
2996 NewOps[2] = PromoteTargetBoolean(NewOps[2],
N->getValueType(0));
2997 return SDValue(DAG.UpdateNodeOperands(
N, NewOps), 0);
3000SDValue DAGTypeLegalizer::PromoteIntOp_PARTIAL_REDUCE_MLA(
SDNode *
N) {
3002 switch (
N->getOpcode()) {
3004 NewOps[1] = SExtPromotedInteger(
N->getOperand(1));
3005 NewOps[2] = SExtPromotedInteger(
N->getOperand(2));
3008 NewOps[1] = ZExtPromotedInteger(
N->getOperand(1));
3009 NewOps[2] = ZExtPromotedInteger(
N->getOperand(2));
3012 NewOps[1] = SExtPromotedInteger(
N->getOperand(1));
3013 NewOps[2] = ZExtPromotedInteger(
N->getOperand(2));
3018 return SDValue(DAG.UpdateNodeOperands(
N, NewOps), 0);
3021SDValue DAGTypeLegalizer::PromoteIntOp_LOOP_DEPENDENCE_MASK(
SDNode *
N) {
3023 NewOps[0] = ZExtPromotedInteger(
N->getOperand(0));
3024 NewOps[1] = ZExtPromotedInteger(
N->getOperand(1));
3025 NewOps[2] = ZExtPromotedInteger(
N->getOperand(2));
3027 return SDValue(DAG.UpdateNodeOperands(
N, NewOps), 0);
3032 SDValue Src = GetPromotedInteger(
N->getOperand(0));
3033 EVT SrcVT = Src.getValueType();
3034 EVT OrigVT =
N->getValueType(0);
3049void DAGTypeLegalizer::ExpandIntegerResult(
SDNode *
N,
unsigned ResNo) {
3052 Lo =
Hi = SDValue();
3055 if (CustomLowerNode(
N,
N->getValueType(ResNo),
true))
3058 switch (
N->getOpcode()) {
3061 dbgs() <<
"ExpandIntegerResult #" << ResNo <<
": ";
3062 N->dump(&DAG);
dbgs() <<
"\n";
3091 ExpandIntRes_ABS(
N,
Lo,
Hi);
3143 std::pair<SDValue, SDValue> Tmp = ExpandAtomic(
N);
3144 SplitInteger(Tmp.first,
Lo,
Hi);
3145 ReplaceValueWith(SDValue(
N, 1), Tmp.second);
3150 SDVTList VTs = DAG.getVTList(
N->getValueType(0), MVT::Other);
3151 SDValue Tmp = DAG.getAtomicCmpSwap(
3153 N->getOperand(0),
N->getOperand(1),
N->getOperand(2),
N->getOperand(3),
3159 SDValue
Success = DAG.getSetCC(SDLoc(
N),
N->getValueType(1), Tmp,
3162 SplitInteger(Tmp,
Lo,
Hi);
3163 ReplaceValueWith(SDValue(
N, 1),
Success);
3164 ReplaceValueWith(SDValue(
N, 2), Tmp.
getValue(1));
3241 ExpandIntRes_Rotate(
N,
Lo,
Hi);
3246 ExpandIntRes_FunnelShift(
N,
Lo,
Hi);
3252 ExpandIntRes_CLMUL(
N,
Lo,
Hi);
3256 ExpandIntRes_PEXT(
N,
Lo,
Hi);
3260 ExpandIntRes_PDEP(
N,
Lo,
Hi);
3265 ExpandIntRes_MULH(
N,
Lo,
Hi);
3269 ExpandIntRes_VSCALE(
N,
Lo,
Hi);
3273 ExpandIntRes_READ_REGISTER(
N,
Lo,
Hi);
3278 ExpandIntRes_CTTZ_ELTS(
N,
Lo,
Hi);
3284 SetExpandedInteger(SDValue(
N, ResNo),
Lo,
Hi);
3288std::pair <SDValue, SDValue> DAGTypeLegalizer::ExpandAtomic(
SDNode *Node) {
3289 unsigned Opc =
Node->getOpcode();
3295 EVT RetVT =
Node->getValueType(0);
3296 TargetLowering::MakeLibCallOptions CallOptions;
3299 RTLIB::LibcallImpl LCImpl = DAG.getLibcalls().getLibcallImpl(LC);
3300 if (LCImpl != RTLIB::Unsupported) {
3302 Ops.push_back(
Node->getOperand(1));
3305 assert(LC != RTLIB::UNKNOWN_LIBCALL &&
3306 "Unexpected atomic op or value type!");
3308 LCImpl = DAG.getLibcalls().getLibcallImpl(LC);
3310 return TLI.makeLibCall(DAG, LCImpl, RetVT,
Ops, CallOptions, SDLoc(Node),
3311 Node->getOperand(0));
3316void DAGTypeLegalizer::ExpandShiftByConstant(
SDNode *
N,
const APInt &Amt,
3321 GetExpandedInteger(
N->getOperand(0), InL, InH);
3336 if (Amt.
uge(VTBits)) {
3337 Lo =
Hi = DAG.getConstant(0,
DL, NVT);
3338 }
else if (Amt.
ugt(NVTBits)) {
3339 Lo = DAG.getConstant(0,
DL, NVT);
3341 DAG.getShiftAmountConstant(Amt - NVTBits, NVT,
DL));
3342 }
else if (Amt == NVTBits) {
3343 Lo = DAG.getConstant(0,
DL, NVT);
3347 DAG.getShiftAmountConstant(Amt, NVT,
DL));
3349 if (TLI.isOperationLegal(
ISD::FSHL, NVT)) {
3351 DAG.getShiftAmountConstant(Amt, NVT,
DL));
3356 DAG.getShiftAmountConstant(Amt, NVT,
DL)),
3358 DAG.getShiftAmountConstant(-Amt + NVTBits, NVT,
DL)));
3365 if (Amt.
uge(VTBits)) {
3366 Lo =
Hi = DAG.getConstant(0,
DL, NVT);
3367 }
else if (Amt.
ugt(NVTBits)) {
3369 DAG.getShiftAmountConstant(Amt - NVTBits, NVT,
DL));
3370 Hi = DAG.getConstant(0,
DL, NVT);
3371 }
else if (Amt == NVTBits) {
3373 Hi = DAG.getConstant(0,
DL, NVT);
3376 if (TLI.isOperationLegal(
ISD::FSHR, NVT)) {
3378 DAG.getShiftAmountConstant(Amt, NVT,
DL));
3383 DAG.getShiftAmountConstant(Amt, NVT,
DL)),
3385 DAG.getShiftAmountConstant(-Amt + NVTBits, NVT,
DL)));
3388 DAG.getShiftAmountConstant(Amt, NVT,
DL));
3394 if (Amt.
uge(VTBits)) {
3396 DAG.getShiftAmountConstant(NVTBits - 1, NVT,
DL));
3397 }
else if (Amt.
ugt(NVTBits)) {
3399 DAG.getShiftAmountConstant(Amt - NVTBits, NVT,
DL));
3401 DAG.getShiftAmountConstant(NVTBits - 1, NVT,
DL));
3402 }
else if (Amt == NVTBits) {
3405 DAG.getShiftAmountConstant(NVTBits - 1, NVT,
DL));
3408 if (TLI.isOperationLegal(
ISD::FSHR, NVT)) {
3410 DAG.getShiftAmountConstant(Amt, NVT,
DL));
3415 DAG.getShiftAmountConstant(Amt, NVT,
DL)),
3417 DAG.getShiftAmountConstant(-Amt + NVTBits, NVT,
DL)));
3420 DAG.getShiftAmountConstant(Amt, NVT,
DL));
3428bool DAGTypeLegalizer::
3430 unsigned Opc =
N->getOpcode();
3431 SDValue
In =
N->getOperand(0);
3432 SDValue Amt =
N->getOperand(1);
3433 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(),
N->getValueType(0));
3438 "Expanded integer type size not a power of two!");
3442 KnownBits
Known = DAG.computeKnownBits(Amt);
3445 if (((
Known.Zero |
Known.One) & HighBitMask) == 0)
3450 GetExpandedInteger(In, InL, InH);
3454 if (
Known.One.intersects(HighBitMask)) {
3457 DAG.getConstant(~HighBitMask, dl, ShTy));
3462 Lo = DAG.getConstant(0, dl, NVT);
3463 Hi = DAG.getNode(
ISD::SHL, dl, NVT, InL, Amt);
3466 Hi = DAG.getConstant(0, dl, NVT);
3467 Lo = DAG.getNode(
ISD::SRL, dl, NVT, InH, Amt);
3471 DAG.getConstant(NVTBits - 1, dl, ShTy));
3472 Lo = DAG.getNode(
ISD::SRA, dl, NVT, InH, Amt);
3483 SDValue Amt2 = DAG.getNode(
ISD::XOR, dl, ShTy, Amt,
3484 DAG.getConstant(NVTBits - 1, dl, ShTy));
3500 SDValue Sh1 = DAG.getNode(Op2, dl, NVT, InL, DAG.getConstant(1, dl, ShTy));
3502 SDValue Sh2 = DAG.getNode(Op2, dl, NVT, Sh1, Amt2);
3504 Lo = DAG.getNode(
Opc, dl, NVT, InL, Amt);
3505 Hi = DAG.getNode(
ISD::OR, dl, NVT, DAG.getNode(Op1, dl, NVT, InH, Amt),Sh2);
3517bool DAGTypeLegalizer::
3520 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(),
N->getValueType(0));
3524 "Expanded integer type size not a power of two!");
3529 GetExpandedInteger(
N->getOperand(0), InL, InH);
3531 SDValue NVBitsNode = DAG.getConstant(NVTBits, dl, ShTy);
3532 SDValue AmtExcess = DAG.getNode(
ISD::SUB, dl, ShTy, Amt, NVBitsNode);
3533 SDValue AmtLack = DAG.getNode(
ISD::SUB, dl, ShTy, NVBitsNode, Amt);
3534 SDValue isShort = DAG.getSetCC(dl, getSetCCResultType(ShTy),
3536 SDValue
isZero = DAG.getSetCC(dl, getSetCCResultType(ShTy),
3537 Amt, DAG.getConstant(0, dl, ShTy),
3540 SDValue LoS, HiS, LoL, HiL;
3541 switch (
N->getOpcode()) {
3547 DAG.getNode(
ISD::SHL, dl, NVT, InH, Amt),
3548 DAG.getNode(
ISD::SRL, dl, NVT, InL, AmtLack));
3551 LoL = DAG.getConstant(0, dl, NVT);
3554 Lo = DAG.getSelect(dl, NVT, isShort, LoS, LoL);
3555 Hi = DAG.getSelect(dl, NVT,
isZero, InH,
3556 DAG.getSelect(dl, NVT, isShort, HiS, HiL));
3562 DAG.getNode(
ISD::SRL, dl, NVT, InL, Amt),
3565 DAG.getNode(
ISD::SHL, dl, NVT, InH, AmtLack));
3568 HiL = DAG.getConstant(0, dl, NVT);
3571 Lo = DAG.getSelect(dl, NVT,
isZero, InL,
3572 DAG.getSelect(dl, NVT, isShort, LoS, LoL));
3573 Hi = DAG.getSelect(dl, NVT, isShort, HiS, HiL);
3579 DAG.getNode(
ISD::SRL, dl, NVT, InL, Amt),
3580 DAG.getNode(
ISD::SHL, dl, NVT, InH, AmtLack));
3584 DAG.getConstant(NVTBits - 1, dl, ShTy));
3587 Lo = DAG.getSelect(dl, NVT,
isZero, InL,
3588 DAG.getSelect(dl, NVT, isShort, LoS, LoL));
3589 Hi = DAG.getSelect(dl, NVT, isShort, HiS, HiL);
3612 SDValue
LHS =
N->getOperand(0);
3613 SDValue
RHS =
N->getOperand(1);
3614 EVT NewVT = getSetCCResultType(
LHS.getValueType());
3619 Res = DAG.getBoolExtOrTrunc(Res,
DL,
N->getValueType(0), NewVT);
3620 SplitInteger(Res,
Lo,
Hi);
3623void DAGTypeLegalizer::ExpandIntRes_MINMAX(
SDNode *
N,
3627 SDValue
LHS =
N->getOperand(0);
3628 SDValue
RHS =
N->getOperand(1);
3632 unsigned NumBits =
N->getValueType(0).getScalarSizeInBits();
3633 unsigned NumHalfBits = NumBits / 2;
3634 if (DAG.ComputeNumSignBits(
LHS) > NumHalfBits &&
3635 DAG.ComputeNumSignBits(
RHS) > NumHalfBits) {
3636 SDValue LHSL, LHSH, RHSL, RHSH;
3637 GetExpandedInteger(
LHS, LHSL, LHSH);
3638 GetExpandedInteger(
RHS, RHSL, RHSH);
3641 Lo = DAG.getNode(
N->getOpcode(),
DL, NVT, LHSL, RHSL);
3643 DAG.getShiftAmountConstant(NumHalfBits - 1, NVT,
DL));
3651 SDValue LHSL, LHSH, RHSL, RHSH;
3652 GetExpandedInteger(
LHS, LHSL, LHSH);
3653 GetExpandedInteger(
RHS, RHSL, RHSH);
3655 EVT CCT = getSetCCResultType(NVT);
3658 DAG.getSetCC(
DL, CCT, LHSH, DAG.getConstant(0,
DL, NVT),
ISD::SETLT);
3660 Lo = DAG.getSelect(
DL, NVT, HiNeg, LHSL, DAG.getAllOnesConstant(
DL, NVT));
3662 Lo = DAG.getSelect(
DL, NVT, HiNeg, DAG.getConstant(0,
DL, NVT), LHSL);
3664 Hi = DAG.getNode(
N->getOpcode(),
DL, NVT, {LHSH, RHSH});
3668 const APInt *RHSVal =
nullptr;
3670 RHSVal = &RHSConst->getAPIntValue();
3677 SDValue LHSL, LHSH, RHSL, RHSH;
3678 GetExpandedInteger(
LHS, LHSL, LHSH);
3679 GetExpandedInteger(
RHS, RHSL, RHSH);
3681 EVT CCT = getSetCCResultType(NVT);
3687 Hi = DAG.getNode(
N->getOpcode(),
DL, NVT, {LHSH, RHSH});
3690 SDValue IsHiLeft = DAG.getSetCC(
DL, CCT, LHSH, RHSH, CondC);
3691 SDValue IsHiEq = DAG.getSetCC(
DL, CCT, LHSH, RHSH,
ISD::SETEQ);
3694 SDValue LoCmp = DAG.getSelect(
DL, NVT, IsHiLeft, LHSL, RHSL);
3697 SDValue LoMinMax = DAG.getNode(LoOpc,
DL, NVT, {LHSL, RHSL});
3699 Lo = DAG.getSelect(
DL, NVT, IsHiEq, LoMinMax, LoCmp);
3706 switch (
N->getOpcode()) {
3733 EVT VT =
N->getValueType(0);
3734 EVT CCT = getSetCCResultType(VT);
3737 SplitInteger(Result,
Lo,
Hi);
3741 SDValue ExpandedCMP = TLI.expandCMP(
N, DAG);
3742 SplitInteger(ExpandedCMP,
Lo,
Hi);
3745void DAGTypeLegalizer::ExpandIntRes_ADDSUB(
SDNode *
N,
3749 SDValue LHSL, LHSH, RHSL, RHSH;
3750 GetExpandedInteger(
N->getOperand(0), LHSL, LHSH);
3751 GetExpandedInteger(
N->getOperand(1), RHSL, RHSH);
3754 SDValue LoOps[2] = { LHSL, RHSL };
3755 SDValue HiOps[3] = { LHSH, RHSH };
3757 bool HasOpCarry = TLI.isOperationLegalOrCustom(
3759 TLI.getTypeToExpandTo(*DAG.getContext(), NVT));
3761 SDVTList VTList = DAG.getVTList(NVT, getSetCCResultType(NVT));
3765 Hi = DAG.computeKnownBits(HiOps[2]).isZero()
3771 Hi = DAG.computeKnownBits(HiOps[2]).isZero()
3784 TLI.isOperationLegalOrCustom(
N->getOpcode() ==
ISD::ADD ?
3786 TLI.getTypeToExpandTo(*DAG.getContext(), NVT));
3789 SDVTList VTList = DAG.getVTList(NVT, MVT::Glue);
3803 TLI.isOperationLegalOrCustom(
N->getOpcode() ==
ISD::ADD ?
3805 TLI.getTypeToExpandTo(*DAG.getContext(), NVT));
3809 EVT OvfVT = getSetCCResultType(NVT);
3810 SDVTList VTList = DAG.getVTList(NVT, OvfVT);
3821 SDValue OVF =
Lo.getValue(1);
3825 OVF = DAG.
getNode(
ISD::AND, dl, OvfVT, DAG.getConstant(1, dl, OvfVT), OVF);
3828 OVF = DAG.getZExtOrTrunc(OVF, dl, NVT);
3832 OVF = DAG.getSExtOrTrunc(OVF, dl, NVT);
3844 Cmp = DAG.getSetCC(dl, getSetCCResultType(NVT),
Lo,
3848 Cmp = DAG.getSetCC(dl, getSetCCResultType(NVT), LoOps[0],
3851 Cmp = DAG.getSetCC(dl, getSetCCResultType(NVT), LoOps[0],
3854 Cmp = DAG.getSetCC(dl, getSetCCResultType(NVT),
Lo, LoOps[0],
3859 Carry = DAG.getZExtOrTrunc(Cmp, dl, NVT);
3861 Carry = DAG.getSelect(dl, NVT, Cmp, DAG.getConstant(1, dl, NVT),
3862 DAG.getConstant(0, dl, NVT));
3865 Hi = DAG.getNode(
ISD::SUB, dl, NVT, HiOps[0], Carry);
3874 DAG.getSetCC(dl, getSetCCResultType(LoOps[0].
getValueType()),
3879 Borrow = DAG.getZExtOrTrunc(Cmp, dl, NVT);
3881 Borrow = DAG.getSelect(dl, NVT, Cmp, DAG.getConstant(1, dl, NVT),
3882 DAG.getConstant(0, dl, NVT));
3888void DAGTypeLegalizer::ExpandIntRes_ADDSUBC(
SDNode *
N,
3891 SDValue LHSL, LHSH, RHSL, RHSH;
3893 GetExpandedInteger(
N->getOperand(0), LHSL, LHSH);
3894 GetExpandedInteger(
N->getOperand(1), RHSL, RHSH);
3895 SDVTList VTList = DAG.getVTList(LHSL.
getValueType(), MVT::Glue);
3896 SDValue LoOps[2] = { LHSL, RHSL };
3897 SDValue HiOps[3] = { LHSH, RHSH };
3911 ReplaceValueWith(SDValue(
N, 1),
Hi.getValue(1));
3914void DAGTypeLegalizer::ExpandIntRes_ADDSUBE(
SDNode *
N,
3917 SDValue LHSL, LHSH, RHSL, RHSH;
3919 GetExpandedInteger(
N->getOperand(0), LHSL, LHSH);
3920 GetExpandedInteger(
N->getOperand(1), RHSL, RHSH);
3921 SDVTList VTList = DAG.getVTList(LHSL.
getValueType(), MVT::Glue);
3922 SDValue LoOps[3] = { LHSL, RHSL,
N->
getOperand(2) };
3923 SDValue HiOps[3] = { LHSH, RHSH };
3925 Lo = DAG.
getNode(
N->getOpcode(), dl, VTList, LoOps);
3927 Hi = DAG.
getNode(
N->getOpcode(), dl, VTList, HiOps);
3931 ReplaceValueWith(SDValue(
N, 1),
Hi.getValue(1));
3934void DAGTypeLegalizer::ExpandIntRes_UADDSUBO(
SDNode *
N,
3936 SDValue
LHS =
N->getOperand(0);
3937 SDValue
RHS =
N->getOperand(1);
3942 unsigned CarryOp, NoCarryOp;
3944 switch(
N->getOpcode()) {
3959 bool HasCarryOp = TLI.isOperationLegalOrCustom(
3960 CarryOp, TLI.getTypeToExpandTo(*DAG.getContext(),
LHS.getValueType()));
3964 SDValue LHSL, LHSH, RHSL, RHSH;
3965 GetExpandedInteger(
LHS, LHSL, LHSH);
3966 GetExpandedInteger(
RHS, RHSL, RHSH);
3967 SDVTList VTList = DAG.getVTList(LHSL.
getValueType(),
N->getValueType(1));
3968 SDValue LoOps[2] = { LHSL, RHSL };
3969 SDValue HiOps[3] = { LHSH, RHSH };
3971 Lo = DAG.
getNode(
N->getOpcode(), dl, VTList, LoOps);
3973 Hi = DAG.
getNode(CarryOp, dl, VTList, HiOps);
3979 SDValue Sum = DAG.getNode(NoCarryOp, dl,
LHS.getValueType(),
LHS,
RHS);
3980 SplitInteger(Sum,
Lo,
Hi);
3986 Ovf = DAG.getSetCC(dl,
N->getValueType(1),
Or,
3987 DAG.getConstant(0, dl,
Lo.getValueType()),
ISD::SETEQ);
3991 DAG.getSetCC(dl,
N->getValueType(1),
LHS,
3996 Ovf = DAG.getSetCC(dl,
N->getValueType(1), Sum,
LHS,
Cond);
4002 ReplaceValueWith(SDValue(
N, 1), Ovf);
4008 SDValue LHSL, LHSH, RHSL, RHSH;
4010 GetExpandedInteger(
N->getOperand(0), LHSL, LHSH);
4011 GetExpandedInteger(
N->getOperand(1), RHSL, RHSH);
4012 SDVTList VTList = DAG.getVTList(LHSL.
getValueType(),
N->getValueType(1));
4013 SDValue LoOps[3] = { LHSL, RHSL,
N->
getOperand(2) };
4014 SDValue HiOps[3] = { LHSH, RHSH, SDValue() };
4016 Lo = DAG.
getNode(
N->getOpcode(), dl, VTList, LoOps);
4018 Hi = DAG.
getNode(
N->getOpcode(), dl, VTList, HiOps);
4022 ReplaceValueWith(SDValue(
N, 1),
Hi.getValue(1));
4025void DAGTypeLegalizer::ExpandIntRes_SADDSUBO_CARRY(
SDNode *
N,
4028 SDValue LHSL, LHSH, RHSL, RHSH;
4030 GetExpandedInteger(
N->getOperand(0), LHSL, LHSH);
4031 GetExpandedInteger(
N->getOperand(1), RHSL, RHSH);
4032 SDVTList VTList = DAG.getVTList(LHSL.
getValueType(),
N->getValueType(1));
4037 Lo = DAG.getNode(CarryOp, dl, VTList, { LHSL, RHSL,
N->
getOperand(2) });
4038 Hi = DAG.getNode(
N->getOpcode(), dl, VTList, { LHSH, RHSH, Lo.getValue(1) });
4042 ReplaceValueWith(SDValue(
N, 1),
Hi.getValue(1));
4045void DAGTypeLegalizer::ExpandIntRes_ANY_EXTEND(
SDNode *
N,
4047 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(),
N->getValueType(0));
4049 SDValue
Op =
N->getOperand(0);
4050 if (
Op.getValueType().bitsLE(NVT)) {
4053 Hi = DAG.getUNDEF(NVT);
4057 assert(getTypeAction(
Op.getValueType()) ==
4059 "Only know how to promote this result!");
4060 SDValue Res = GetPromotedInteger(
Op);
4062 "Operand over promoted?");
4064 SplitInteger(Res,
Lo,
Hi);
4068void DAGTypeLegalizer::ExpandIntRes_AssertSext(
SDNode *
N,
4071 GetExpandedInteger(
N->getOperand(0),
Lo,
Hi);
4072 EVT NVT =
Lo.getValueType();
4077 if (NVTBits < EVTBits) {
4080 EVTBits - NVTBits)));
4085 DAG.getShiftAmountConstant(NVTBits - 1, NVT, dl));
4089void DAGTypeLegalizer::ExpandIntRes_AssertZext(
SDNode *
N,
4092 GetExpandedInteger(
N->getOperand(0),
Lo,
Hi);
4093 EVT NVT =
Lo.getValueType();
4098 if (NVTBits < EVTBits) {
4101 EVTBits - NVTBits)));
4105 Hi = DAG.getConstant(0, dl, NVT);
4109void DAGTypeLegalizer::ExpandIntRes_BITREVERSE(
SDNode *
N,
4112 GetExpandedInteger(
N->getOperand(0),
Hi,
Lo);
4117void DAGTypeLegalizer::ExpandIntRes_BSWAP(
SDNode *
N,
4120 GetExpandedInteger(
N->getOperand(0),
Hi,
Lo);
4129 GetExpandedInteger(
N->getOperand(0),
Lo,
Hi);
4130 EVT NVT =
Lo.getValueType();
4133 Hi = DAG.getConstant(0, dl, NVT);
4136void DAGTypeLegalizer::ExpandIntRes_Constant(
SDNode *
N,
4138 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(),
N->getValueType(0));
4141 const APInt &Cst =
Constant->getAPIntValue();
4142 bool IsTarget =
Constant->isTargetOpcode();
4143 bool IsOpaque =
Constant->isOpaque();
4145 Lo = DAG.getConstant(Cst.
trunc(NBitWidth), dl, NVT, IsTarget, IsOpaque);
4146 Hi = DAG.getConstant(Cst.
lshr(NBitWidth).
trunc(NBitWidth), dl, NVT, IsTarget,
4153 SDValue N0 =
N->getOperand(0);
4154 GetExpandedInteger(N0,
Lo,
Hi);
4155 EVT NVT =
Lo.getValueType();
4160 unsigned NumSignBits = DAG.ComputeNumSignBits(N0);
4165 Lo = DAG.getNode(AbsOpc, dl, NVT,
Lo);
4166 Hi = DAG.getConstant(0, dl, NVT);
4176 bool HasSubCarry = TLI.isOperationLegalOrCustom(
4179 SDValue Sign = DAG.getNode(
4181 DAG.getShiftAmountConstant(NVT.
getSizeInBits() - 1, NVT, dl));
4182 SDVTList VTList = DAG.getVTList(NVT, getSetCCResultType(NVT));
4191 EVT VT =
N->getValueType(0);
4192 SDValue Neg = DAG.getNode(
ISD::SUB, dl, VT,
4193 DAG.getConstant(0, dl, VT), N0);
4194 SDValue NegLo, NegHi;
4195 SplitInteger(Neg, NegLo, NegHi);
4197 SDValue HiIsNeg = DAG.getSetCC(dl, getSetCCResultType(NVT),
Hi,
4199 Lo = DAG.getSelect(dl, NVT, HiIsNeg, NegLo,
Lo);
4200 Hi = DAG.getSelect(dl, NVT, HiIsNeg, NegHi,
Hi);
4203void DAGTypeLegalizer::ExpandIntRes_CTLZ(
SDNode *
N,
4207 GetExpandedInteger(
N->getOperand(0),
Lo,
Hi);
4208 EVT NVT =
Lo.getValueType();
4210 SDValue HiNotZero = DAG.getSetCC(dl, getSetCCResultType(NVT),
Hi,
4213 SDValue LoLZ = DAG.getNode(
N->getOpcode(), dl, NVT,
Lo);
4216 Lo = DAG.getSelect(dl, NVT, HiNotZero, HiLZ,
4217 DAG.getNode(
ISD::ADD, dl, NVT, LoLZ,
4220 Hi = DAG.getConstant(0, dl, NVT);
4228 GetExpandedInteger(
N->getOperand(0),
Lo,
Hi);
4229 EVT NVT =
Lo.getValueType();
4232 SDValue Constant0 = DAG.getConstant(0, dl, NVT);
4233 SDValue ConstantBWM1 = DAG.getConstant(NVTBits - 1, dl, NVT);
4235 SDValue HiCTLS = DAG.getNode(
ISD::CTLS, dl, NVT,
Hi);
4236 SDValue IsAllSignBits = DAG.getSetCC(dl, getSetCCResultType(NVT), HiCTLS,
4238 SDValue IsNegative =
4239 DAG.getSetCC(dl, getSetCCResultType(NVT),
Hi, Constant0,
ISD::SETLT);
4240 SDValue AdjustedLo =
4241 DAG.getSelect(dl, NVT, IsNegative, DAG.getNOT(dl,
Lo, NVT),
Lo);
4242 SDValue LoCLZ = DAG.getNode(
ISD::CTLZ, dl, NVT, AdjustedLo);
4243 Lo = DAG.getSelect(dl, NVT, IsAllSignBits,
4244 DAG.getNode(
ISD::ADD, dl, NVT, LoCLZ, ConstantBWM1),
4246 Hi = DAG.getConstant(0, dl, NVT);
4250 SDValue
Result = TLI.expandABD(
N, DAG);
4251 SplitInteger(Result,
Lo,
Hi);
4255 SDValue
Op =
N->getOperand(0);
4256 EVT VT =
N->getValueType(0);
4261 assert(LC != RTLIB::UNKNOWN_LIBCALL &&
4262 "LibCall explicitly requested, but not available");
4264 if (RTLIB::LibcallImpl LCImpl = DAG.getLibcalls().getLibcallImpl(LC)) {
4265 TargetLowering::MakeLibCallOptions CallOptions;
4269 TLI.makeLibCall(DAG, LCImpl, IntVT,
Op, CallOptions,
DL).first;
4270 SplitInteger(DAG.getSExtOrTrunc(Res,
DL, VT),
Lo,
Hi);
4278 GetExpandedInteger(
Op,
Lo,
Hi);
4279 EVT NVT =
Lo.getValueType();
4282 Hi = DAG.getConstant(0,
DL, NVT);
4285void DAGTypeLegalizer::ExpandIntRes_CTTZ(
SDNode *
N,
4289 GetExpandedInteger(
N->getOperand(0),
Lo,
Hi);
4290 EVT NVT =
Lo.getValueType();
4292 SDValue LoNotZero = DAG.getSetCC(dl, getSetCCResultType(NVT),
Lo,
4296 SDValue HiLZ = DAG.
getNode(
N->getOpcode(), dl, NVT,
Hi);
4298 Lo = DAG.getSelect(dl, NVT, LoNotZero, LoLZ,
4299 DAG.getNode(
ISD::ADD, dl, NVT, HiLZ,
4302 Hi = DAG.getConstant(0, dl, NVT);
4308 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(),
N->getValueType(0));
4315 DAG.getShiftAmountConstant(NBitWidth - 1, NVT, dl));
4319 ReplaceValueWith(SDValue(
N, 1), Chain);
4327 Chain =
Op.getValue(1);
4336 EVT VT =
N->getValueType(0);
4340 bool IsStrict =
N->isStrictFPOpcode();
4341 SDValue Chain = IsStrict ?
N->getOperand(0) : SDValue();
4342 SDValue
Op =
N->getOperand(IsStrict ? 1 : 0);
4346 Op.getValueType() == MVT::bf16) {
4352 EVT OpVT =
Op.getValueType();
4356 assert(LC != RTLIB::UNKNOWN_LIBCALL &&
"Unexpected fp-to-xint conversion!");
4357 TargetLowering::MakeLibCallOptions CallOptions;
4362 std::pair<SDValue, SDValue> Tmp = TLI.makeLibCall(DAG, LC, VT,
Op,
4363 CallOptions, dl, Chain);
4364 SplitInteger(Tmp.first,
Lo,
Hi);
4367 ReplaceValueWith(SDValue(
N, 1), Tmp.second);
4372 SDValue Res = TLI.expandFP_TO_INT_SAT(
N, DAG);
4373 SplitInteger(Res,
Lo,
Hi);
4379 bool IsStrict =
N->isStrictFPOpcode();
4380 SDValue
Op =
N->getOperand(IsStrict ? 1 : 0);
4381 SDValue Chain = IsStrict ?
N->getOperand(0) : SDValue();
4383 EVT VT =
Op.getValueType();
4385 if (VT == MVT::f16) {
4391 RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL;
4394 LC = RTLIB::getLROUND(VT);
4395 assert(LC != RTLIB::UNKNOWN_LIBCALL &&
"Unexpected lround input type!");
4398 LC = RTLIB::getLRINT(VT);
4399 assert(LC != RTLIB::UNKNOWN_LIBCALL &&
"Unexpected lrint input type!");
4402 LC = RTLIB::getLLROUND(VT);
4403 assert(LC != RTLIB::UNKNOWN_LIBCALL &&
"Unexpected llround input type!");
4406 LC = RTLIB::getLLRINT(VT);
4407 assert(LC != RTLIB::UNKNOWN_LIBCALL &&
"Unexpected llrint input type!");
4411 EVT RetVT =
N->getValueType(0);
4413 RTLIB::LibcallImpl LCImpl = DAG.getLibcalls().getLibcallImpl(LC);
4414 if (LCImpl == RTLIB::Unsupported) {
4415 DAG.getContext()->emitError(Twine(
"no libcall available for ") +
4416 N->getOperationName(&DAG));
4417 SDValue
Poison = DAG.getPOISON(
N->getValueType(0));
4418 SplitInteger(Poison,
Lo,
Hi);
4419 if (
N->isStrictFPOpcode())
4420 ReplaceValueWith(SDValue(
N, 1),
N->getOperand(0));
4424 TargetLowering::MakeLibCallOptions CallOptions;
4426 std::pair<SDValue, SDValue> Tmp =
4427 TLI.makeLibCall(DAG, LCImpl, RetVT,
Op, CallOptions, dl, Chain);
4428 SplitInteger(Tmp.first,
Lo,
Hi);
4430 if (
N->isStrictFPOpcode())
4431 ReplaceValueWith(SDValue(
N, 1), Tmp.second);
4434void DAGTypeLegalizer::ExpandIntRes_LOAD(
LoadSDNode *
N,
4436 assert(!
N->isAtomic() &&
"Should have been a ATOMIC_LOAD?");
4439 ExpandRes_NormalLoad(
N,
Lo,
Hi);
4445 EVT VT =
N->getValueType(0);
4446 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), VT);
4447 SDValue Ch =
N->getChain();
4448 SDValue Ptr =
N->getBasePtr();
4451 MMOMetadata
Metadata =
N->getMMOMetadataForSubAccess();
4456 if (
N->getMemoryVT().bitsLE(NVT)) {
4457 EVT MemVT =
N->getMemoryVT();
4459 Lo = DAG.getExtLoad(ExtType, dl, NVT, Ch, Ptr,
N->getPointerInfo(), MemVT,
4468 unsigned LoSize =
Lo.getValueSizeInBits();
4470 DAG.getShiftAmountConstant(LoSize - 1, NVT, dl));
4473 Hi = DAG.getConstant(0, dl, NVT);
4477 Hi = DAG.getUNDEF(NVT);
4479 }
else if (DAG.getDataLayout().isLittleEndian()) {
4481 Lo = DAG.getLoad(NVT, dl, Ch, Ptr,
N->getPointerInfo(),
N->getBaseAlign(),
4484 unsigned ExcessBits =
4491 Hi = DAG.getExtLoad(ExtType, dl, NVT, Ch, Ptr,
4492 N->getPointerInfo().getWithOffset(IncrementSize), NEVT,
4502 EVT MemVT =
N->getMemoryVT();
4505 unsigned ExcessBits = (EBytes - IncrementSize)*8;
4508 Hi = DAG.getExtLoad(ExtType, dl, NVT, Ch, Ptr,
N->getPointerInfo(),
4517 N->getPointerInfo().getWithOffset(IncrementSize),
4531 DAG.getShiftAmountConstant(ExcessBits, NVT, dl)));
4535 DAG.getShiftAmountConstant(
4542 ReplaceValueWith(SDValue(
N, 1), Ch);
4545void DAGTypeLegalizer::ExpandIntRes_Logical(
SDNode *
N,
4548 SDValue LL, LH, RL, RH;
4549 GetExpandedInteger(
N->getOperand(0), LL, LH);
4550 GetExpandedInteger(
N->getOperand(1), RL, RH);
4554 Flags.setDisjoint(
N->getFlags().hasDisjoint());
4556 Lo = DAG.getNode(
N->getOpcode(), dl, LL.
getValueType(), LL, RL, Flags);
4557 Hi = DAG.getNode(
N->getOpcode(), dl, LL.
getValueType(), LH, RH, Flags);
4560void DAGTypeLegalizer::ExpandIntRes_MUL(
SDNode *
N,
4562 EVT VT =
N->getValueType(0);
4563 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), VT);
4566 SDValue LL, LH, RL, RH;
4567 GetExpandedInteger(
N->getOperand(0), LL, LH);
4568 GetExpandedInteger(
N->getOperand(1), RL, RH);
4570 if (TLI.expandMUL(
N,
Lo,
Hi, NVT, DAG,
4577 RTLIB::LibcallImpl LCImpl = DAG.getLibcalls().getLibcallImpl(LC);
4578 if (LCImpl == RTLIB::Unsupported) {
4581 TLI.forceExpandMultiply(DAG, dl,
false,
Lo,
Hi, LL, RL, LH, RH);
4587 SDValue
Ops[2] = {
N->getOperand(0),
N->getOperand(1) };
4588 TargetLowering::MakeLibCallOptions CallOptions;
4590 SplitInteger(TLI.makeLibCall(DAG, LCImpl, VT,
Ops, CallOptions, dl).first,
Lo,
4597 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(),
N->getValueType(0));
4598 SDVTList VTs = DAG.getVTList(NVT, NVT, MVT::Other);
4599 SDValue
R = DAG.getNode(
N->getOpcode(),
DL, VTs,
N->getOperand(0));
4602 ReplaceValueWith(SDValue(
N, 1),
R.getValue(2));
4606 SDValue
Result = TLI.expandAVG(
N, DAG);
4607 SplitInteger(Result,
Lo,
Hi);
4612 SDValue
Result = TLI.expandAddSubSat(
N, DAG);
4613 SplitInteger(Result,
Lo,
Hi);
4618 SDValue
Result = TLI.expandShlSat(
N, DAG);
4619 SplitInteger(Result,
Lo,
Hi);
4630 EVT VT =
N->getValueType(0);
4632 SDValue
LHS =
N->getOperand(0);
4633 SDValue
RHS =
N->getOperand(1);
4634 uint64_t Scale =
N->getConstantOperandVal(2);
4646 EVT BoolVT = getSetCCResultType(VT);
4648 Result = DAG.getNode(MulOp, dl, DAG.getVTList(VT, BoolVT),
LHS,
RHS);
4649 SDValue Product =
Result.getValue(0);
4650 SDValue Overflow =
Result.getValue(1);
4654 SDValue SatMin = DAG.getConstant(MinVal, dl, VT);
4655 SDValue SatMax = DAG.getConstant(MaxVal, dl, VT);
4656 SDValue
Zero = DAG.getConstant(0, dl, VT);
4660 SDValue ProdNeg = DAG.getSetCC(dl, BoolVT,
Xor, Zero,
ISD::SETLT);
4661 Result = DAG.getSelect(dl, VT, ProdNeg, SatMin, SatMax);
4662 Result = DAG.getSelect(dl, VT, Overflow, Result, Product);
4667 SDValue SatMax = DAG.getConstant(MaxVal, dl, VT);
4668 Result = DAG.getSelect(dl, VT, Overflow, SatMax, Product);
4671 SplitInteger(Result,
Lo,
Hi);
4677 assert(Scale <= VTSize &&
"Scale can't be larger than the value type size.");
4679 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), VT);
4680 SDValue LL, LH, RL, RH;
4681 GetExpandedInteger(
LHS, LL, LH);
4682 GetExpandedInteger(
RHS, RL, RH);
4686 if (!TLI.expandMUL_LOHI(LoHiOp, VT, dl,
LHS,
RHS, Result, NVT, DAG,
4692 SDValue LoTmp, HiTmp;
4693 TLI.forceExpandWideMUL(DAG, dl,
Signed,
LHS,
RHS, LoTmp, HiTmp);
4694 SplitInteger(LoTmp, Result[0], Result[1]);
4695 SplitInteger(HiTmp, Result[2], Result[3]);
4697 assert(
Result.size() == 4 &&
"Unexpected number of partlets in the result");
4700 assert((VTSize == NVTSize * 2) &&
"Expected the new value type to be half "
4701 "the size of the current value type");
4723 if (Scale % NVTSize) {
4724 SDValue ShiftAmount = DAG.getShiftAmountConstant(Scale % NVTSize, NVT, dl);
4727 Hi = DAG.getNode(
ISD::FSHR, dl, NVT, Result[Part0 + 2], Result[Part0 + 1],
4739 if (Scale == VTSize)
4754 SDValue ResultHL =
Result[2];
4755 SDValue ResultHH =
Result[3];
4757 SDValue SatMax, SatMin;
4758 SDValue NVTZero = DAG.getConstant(0, dl, NVT);
4759 SDValue NVTNeg1 = DAG.getAllOnesConstant(dl, NVT);
4760 EVT BoolNVT = getSetCCResultType(NVT);
4763 if (Scale < NVTSize) {
4765 SDValue HLAdjusted =
4766 DAG.getNode(
ISD::SRL, dl, NVT, ResultHL,
4767 DAG.getShiftAmountConstant(Scale, NVT, dl));
4768 SDValue Tmp = DAG.getNode(
ISD::OR, dl, NVT, HLAdjusted, ResultHH);
4769 SatMax = DAG.getSetCC(dl, BoolNVT, Tmp, NVTZero,
ISD::SETNE);
4770 }
else if (Scale == NVTSize) {
4772 SatMax = DAG.getSetCC(dl, BoolNVT, ResultHH, NVTZero,
ISD::SETNE);
4773 }
else if (Scale < VTSize) {
4775 SDValue HLAdjusted =
4777 DAG.getShiftAmountConstant(Scale - NVTSize, NVT, dl));
4778 SatMax = DAG.getSetCC(dl, BoolNVT, HLAdjusted, NVTZero,
ISD::SETNE);
4781 "(and saturation can't happen with Scale==VTSize).");
4783 Hi = DAG.getSelect(dl, NVT, SatMax, NVTNeg1,
Hi);
4784 Lo = DAG.getSelect(dl, NVT, SatMax, NVTNeg1,
Lo);
4788 if (Scale < NVTSize) {
4793 unsigned OverflowBits = VTSize - Scale + 1;
4794 assert(OverflowBits <= VTSize && OverflowBits > NVTSize &&
4795 "Extent of overflow bits must start within HL");
4796 SDValue HLHiMask = DAG.getConstant(
4798 SDValue HLLoMask = DAG.getConstant(
4801 SDValue HHGT0 = DAG.getSetCC(dl, BoolNVT, ResultHH, NVTZero,
ISD::SETGT);
4802 SDValue HHEQ0 = DAG.getSetCC(dl, BoolNVT, ResultHH, NVTZero,
ISD::SETEQ);
4803 SDValue HLUGT = DAG.getSetCC(dl, BoolNVT, ResultHL, HLLoMask,
ISD::SETUGT);
4805 DAG.getNode(
ISD::AND, dl, BoolNVT, HHEQ0, HLUGT));
4807 SDValue HHLT = DAG.getSetCC(dl, BoolNVT, ResultHH, NVTNeg1,
ISD::SETLT);
4808 SDValue HHEQ = DAG.getSetCC(dl, BoolNVT, ResultHH, NVTNeg1,
ISD::SETEQ);
4809 SDValue HLULT = DAG.getSetCC(dl, BoolNVT, ResultHL, HLHiMask,
ISD::SETULT);
4811 DAG.getNode(
ISD::AND, dl, BoolNVT, HHEQ, HLULT));
4812 }
else if (Scale == NVTSize) {
4814 SDValue HHGT0 = DAG.getSetCC(dl, BoolNVT, ResultHH, NVTZero,
ISD::SETGT);
4815 SDValue HHEQ0 = DAG.getSetCC(dl, BoolNVT, ResultHH, NVTZero,
ISD::SETEQ);
4816 SDValue HLNeg = DAG.getSetCC(dl, BoolNVT, ResultHL, NVTZero,
ISD::SETLT);
4818 DAG.getNode(
ISD::AND, dl, BoolNVT, HHEQ0, HLNeg));
4820 SDValue HHLT = DAG.getSetCC(dl, BoolNVT, ResultHH, NVTNeg1,
ISD::SETLT);
4821 SDValue HHEQ = DAG.getSetCC(dl, BoolNVT, ResultHH, NVTNeg1,
ISD::SETEQ);
4822 SDValue HLPos = DAG.getSetCC(dl, BoolNVT, ResultHL, NVTZero,
ISD::SETGE);
4824 DAG.getNode(
ISD::AND, dl, BoolNVT, HHEQ, HLPos));
4825 }
else if (Scale < VTSize) {
4828 unsigned OverflowBits = VTSize - Scale + 1;
4829 SDValue HHHiMask = DAG.getConstant(
4831 SDValue HHLoMask = DAG.getConstant(
4833 SatMax = DAG.getSetCC(dl, BoolNVT, ResultHH, HHLoMask,
ISD::SETGT);
4834 SatMin = DAG.getSetCC(dl, BoolNVT, ResultHH, HHHiMask,
ISD::SETLT);
4841 Hi = DAG.getSelect(dl, NVT, SatMax, DAG.getConstant(MaxHi, dl, NVT),
Hi);
4842 Lo = DAG.getSelect(dl, NVT, SatMax, DAG.getConstant(MaxLo, dl, NVT),
Lo);
4845 Hi = DAG.getSelect(dl, NVT, SatMin, DAG.getConstant(MinHi, dl, NVT),
Hi);
4846 Lo = DAG.getSelect(dl, NVT, SatMin, NVTZero,
Lo);
4853 SDValue Res = TLI.expandFixedPointDiv(
N->getOpcode(), dl,
N->getOperand(0),
4855 N->getConstantOperandVal(2), DAG);
4859 N->getConstantOperandVal(2), TLI, DAG);
4860 SplitInteger(Res,
Lo,
Hi);
4863void DAGTypeLegalizer::ExpandIntRes_SADDSUBO(
SDNode *Node,
4866 "Node has unexpected Opcode");
4867 SDValue
LHS =
Node->getOperand(0);
4868 SDValue
RHS =
Node->getOperand(1);
4876 bool HasCarryOp = TLI.isOperationLegalOrCustom(
4877 CarryOp, TLI.getTypeToExpandTo(*DAG.getContext(),
LHS.getValueType()));
4881 SDValue LHSL, LHSH, RHSL, RHSH;
4882 GetExpandedInteger(
LHS, LHSL, LHSH);
4883 GetExpandedInteger(
RHS, RHSL, RHSH);
4884 SDVTList VTList = DAG.getVTList(LHSL.
getValueType(),
Node->getValueType(1));
4887 Hi = DAG.getNode(CarryOp, dl, VTList, { LHSH, RHSH,
Lo.
getValue(1) });
4896 SplitInteger(Sum,
Lo,
Hi);
4921 EVT VT =
LHS.getValueType();
4924 SignsMatch = DAG.getNOT(dl, SignsMatch, VT);
4928 EVT OType =
Node->getValueType(1);
4929 Ovf = DAG.getSetCC(dl, OType, Ovf, DAG.getConstant(0, dl, VT),
ISD::SETLT);
4933 ReplaceValueWith(SDValue(Node, 1), Ovf);
4936void DAGTypeLegalizer::ExpandIntRes_SDIV(
SDNode *
N,
4938 EVT VT =
N->getValueType(0);
4940 SDValue
Ops[2] = {
N->getOperand(0),
N->getOperand(1) };
4949 assert(LC != RTLIB::UNKNOWN_LIBCALL &&
"Unsupported SDIV!");
4951 TargetLowering::MakeLibCallOptions CallOptions;
4953 SplitInteger(TLI.makeLibCall(DAG, LC, VT,
Ops, CallOptions, dl).first,
Lo,
Hi);
4956void DAGTypeLegalizer::ExpandIntRes_ShiftThroughStack(
SDNode *
N,
SDValue &
Lo,
4959 SDValue Shiftee =
N->getOperand(0);
4961 SDValue ShAmt =
N->getOperand(1);
4966 LoadVT = TLI.getTypeToTransformTo(*DAG.getContext(), LoadVT);
4967 }
while (!TLI.isTypeLegal(LoadVT));
4972 "Shifting unit is not a a power of two!");
4974 const bool IsOneStepShift =
4975 DAG.computeKnownBits(ShAmt).countMinTrailingZeros() >=
4980 if (!IsOneStepShift)
4981 ShAmt = DAG.getFreeze(ShAmt);
4984 assert(VTBitWidth % 8 == 0 &&
"Shifting a not byte multiple value?");
4985 unsigned VTByteWidth = VTBitWidth / 8;
4987 "Shiftee type size is not a power of two!");
4988 unsigned StackSlotByteWidth = 2 * VTByteWidth;
4989 unsigned StackSlotBitWidth = 8 * StackSlotByteWidth;
4994 Align StackAlign = DAG.getReducedAlign(StackSlotVT,
false);
4996 DAG.CreateStackTemporary(StackSlotVT.
getStoreSize(), StackAlign);
4997 EVT PtrTy =
StackPtr.getValueType();
4998 SDValue Ch = DAG.getEntryNode();
5001 DAG.getMachineFunction(),
5007 unsigned WideningOpc =
5009 Init = DAG.
getNode(WideningOpc, dl, StackSlotVT, Shiftee);
5012 SDValue AllZeros = DAG.getConstant(0, dl, VT);
5016 Ch = DAG.getStore(Ch, dl, Init, StackPtr, StackPtrInfo, StackAlign);
5022 Flags.setExact(IsOneStepShift);
5023 SDValue SrlTmp = DAG.getNode(
5025 DAG.getConstant(
Log2_32(ShiftUnitInBits), dl, ShAmtVT), Flags);
5027 DAG.getNode(
ISD::SHL, dl, ShAmtVT, SrlTmp,
5028 DAG.getConstant(
Log2_32(ShiftUnitInBits), dl, ShAmtVT));
5030 SDValue ByteOffset =
5031 DAG.getNode(
ISD::SRL, dl, ShAmtVT, BitOffset,
5036 DAG.getConstant(VTByteWidth - 1, dl, ShAmtVT));
5043 if (DAG.getDataLayout().isBigEndian())
5044 WillIndexUpwards = !WillIndexUpwards;
5046 SDValue AdjStackPtr;
5047 if (WillIndexUpwards) {
5050 AdjStackPtr = DAG.getMemBasePlusOffset(
5051 StackPtr, DAG.getConstant(VTByteWidth, dl, PtrTy), dl);
5052 ByteOffset = DAG.getNegative(ByteOffset, dl, ShAmtVT);
5056 ByteOffset = DAG.getSExtOrTrunc(ByteOffset, dl, PtrTy);
5057 AdjStackPtr = DAG.getMemBasePlusOffset(AdjStackPtr, ByteOffset, dl);
5061 DAG.getLoad(VT, dl, Ch, AdjStackPtr,
5066 if (!IsOneStepShift) {
5068 DAG.getNode(
ISD::AND, dl, ShAmtVT, ShAmt,
5069 DAG.getConstant(ShiftUnitInBits - 1, dl, ShAmtVT));
5070 Res = DAG.
getNode(
N->getOpcode(), dl, VT, Res, ShAmtRem);
5074 SplitInteger(Res,
Lo,
Hi);
5077void DAGTypeLegalizer::ExpandIntRes_Shift(
SDNode *
N,
5079 EVT VT =
N->getValueType(0);
5080 unsigned Opc =
N->getOpcode();
5086 return ExpandShiftByConstant(
N, CN->getAPIntValue(),
Lo,
Hi);
5090 if (ExpandShiftWithKnownAmountBit(
N,
Lo,
Hi))
5107 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), VT);
5109 const bool LegalOrCustom =
5113 unsigned ExpansionFactor = 1;
5115 for (EVT TmpVT = NVT;;) {
5116 EVT NewTMPVT = TLI.getTypeToTransformTo(*DAG.getContext(), TmpVT);
5117 if (NewTMPVT == TmpVT)
5124 TLI.preferredShiftLegalizationStrategy(DAG,
N, ExpansionFactor);
5127 return ExpandIntRes_ShiftThroughStack(
N,
Lo,
Hi);
5129 if (LegalOrCustom &&
5133 GetExpandedInteger(
N->getOperand(0), LHSL, LHSH);
5139 SDValue ShiftOp =
N->getOperand(1);
5140 EVT ShiftTy = TLI.getShiftAmountTy(VT, DAG.getDataLayout());
5142 ShiftOp = DAG.getZExtOrTrunc(ShiftOp, dl, ShiftTy);
5144 SDValue
Ops[] = { LHSL, LHSH, ShiftOp };
5145 Lo = DAG.
getNode(PartsOpc, dl, DAG.getVTList(VT, VT),
Ops);
5146 Hi =
Lo.getValue(1);
5151 RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL;
5165 if (RTLIB::LibcallImpl LibcallImpl = DAG.getLibcalls().getLibcallImpl(LC)) {
5168 SDValue ShAmt = DAG.getZExtOrTrunc(
N->getOperand(1), dl, ShAmtTy);
5169 SDValue
Ops[2] = {
N->getOperand(0), ShAmt};
5170 TargetLowering::MakeLibCallOptions CallOptions;
5173 TLI.makeLibCall(DAG, LibcallImpl, VT,
Ops, CallOptions, dl).first,
Lo,
5178 if (!ExpandShiftWithUnknownAmountBit(
N,
Lo,
Hi))
5182void DAGTypeLegalizer::ExpandIntRes_SIGN_EXTEND(
SDNode *
N,
5184 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(),
N->getValueType(0));
5186 SDValue
Op =
N->getOperand(0);
5187 if (
Op.getValueType().bitsLE(NVT)) {
5193 DAG.getShiftAmountConstant(LoSize - 1, NVT, dl));
5197 assert(getTypeAction(
Op.getValueType()) ==
5199 "Only know how to promote this result!");
5200 SDValue Res = GetPromotedInteger(
Op);
5202 "Operand over promoted?");
5204 SplitInteger(Res,
Lo,
Hi);
5212void DAGTypeLegalizer::
5215 GetExpandedInteger(
N->getOperand(0),
Lo,
Hi);
5218 if (EVT.
bitsLE(
Lo.getValueType())) {
5226 DAG.getShiftAmountConstant(
Hi.getValueSizeInBits() - 1,
5227 Hi.getValueType(), dl));
5238void DAGTypeLegalizer::ExpandIntRes_SREM(
SDNode *
N,
5240 EVT VT =
N->getValueType(0);
5242 SDValue
Ops[2] = {
N->getOperand(0),
N->getOperand(1) };
5251 assert(LC != RTLIB::UNKNOWN_LIBCALL &&
"Unsupported SREM!");
5253 TargetLowering::MakeLibCallOptions CallOptions;
5255 SplitInteger(TLI.makeLibCall(DAG, LC, VT,
Ops, CallOptions, dl).first,
Lo,
Hi);
5258void DAGTypeLegalizer::ExpandIntRes_TRUNCATE(
SDNode *
N,
5260 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(),
N->getValueType(0));
5270void DAGTypeLegalizer::ExpandIntRes_XMULO(
SDNode *
N,
5272 EVT VT =
N->getValueType(0);
5290 SDValue
LHS =
N->getOperand(0),
RHS =
N->getOperand(1);
5291 SDValue LHSHigh, LHSLow, RHSHigh, RHSLow;
5292 GetExpandedInteger(
LHS, LHSLow, LHSHigh);
5293 GetExpandedInteger(
RHS, RHSLow, RHSHigh);
5295 EVT BitVT =
N->getValueType(1);
5296 SDVTList VTHalfWithO = DAG.getVTList(HalfVT, BitVT);
5298 SDValue HalfZero = DAG.getConstant(0, dl, HalfVT);
5300 DAG.getSetCC(dl, BitVT, LHSHigh, HalfZero,
ISD::SETNE),
5301 DAG.getSetCC(dl, BitVT, RHSHigh, HalfZero,
ISD::SETNE));
5303 SDValue One = DAG.getNode(
ISD::UMULO, dl, VTHalfWithO, LHSHigh, RHSLow);
5306 SDValue Two = DAG.getNode(
ISD::UMULO, dl, VTHalfWithO, RHSHigh, LHSLow);
5309 SDValue HighSum = DAG.getNode(
ISD::ADD, dl, HalfVT, One, Two);
5317 SDValue Three = DAG.getNode(
ISD::MUL, dl, VT,
5320 SplitInteger(Three,
Lo,
Hi);
5324 ReplaceValueWith(SDValue(
N, 1), Overflow);
5329 EVT PtrVT = TLI.getPointerTy(DAG.getDataLayout());
5334 RTLIB::LibcallImpl LCImpl = DAG.getLibcalls().getLibcallImpl(LC);
5338 if (LCImpl == RTLIB::Unsupported ||
5340 DAG.getMachineFunction().getName()) {
5342 SDValue MulLo, MulHi;
5343 TLI.forceExpandWideMUL(DAG, dl,
true,
N->getOperand(0),
5344 N->getOperand(1), MulLo, MulHi);
5345 SDValue
SRA = DAG.getNode(
5349 DAG.getSetCC(dl,
N->getValueType(1), MulHi, SRA,
ISD::SETNE);
5350 SplitInteger(MulLo,
Lo,
Hi);
5351 ReplaceValueWith(SDValue(
N, 1), Overflow);
5355 SDValue Temp = DAG.CreateStackTemporary(PtrVT);
5358 DAG.getStore(DAG.getEntryNode(), dl, DAG.getConstant(0, dl, PtrVT), Temp,
5359 MachinePointerInfo());
5362 for (
const SDValue &
Op :
N->op_values()) {
5363 EVT ArgVT =
Op.getValueType();
5365 TargetLowering::ArgListEntry
Entry(
Op, ArgTy);
5366 Entry.IsSExt =
true;
5367 Entry.IsZExt =
false;
5368 Args.push_back(Entry);
5372 TargetLowering::ArgListEntry
Entry(
5374 Entry.IsSExt =
true;
5375 Entry.IsZExt =
false;
5376 Args.push_back(Entry);
5378 SDValue
Func = DAG.getExternalSymbol(LCImpl, PtrVT);
5380 TargetLowering::CallLoweringInfo CLI(DAG);
5383 .setLibCallee(DAG.getLibcalls().getLibcallImplCallingConv(LCImpl), RetTy,
5384 Func, std::move(Args))
5387 std::pair<SDValue, SDValue> CallInfo = TLI.LowerCallTo(CLI);
5389 SplitInteger(CallInfo.first,
Lo,
Hi);
5391 DAG.getLoad(PtrVT, dl, CallInfo.second, Temp, MachinePointerInfo());
5392 SDValue Ofl = DAG.getSetCC(dl,
N->getValueType(1), Temp2,
5393 DAG.getConstant(0, dl, PtrVT),
5396 ReplaceValueWith(SDValue(
N, 1), Ofl);
5399void DAGTypeLegalizer::ExpandIntRes_UDIV(
SDNode *
N,
5401 EVT VT =
N->getValueType(0);
5403 SDValue
Ops[2] = {
N->getOperand(0),
N->getOperand(1) };
5413 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(),
N->getValueType(0));
5415 if (isTypeLegal(NVT)) {
5417 GetExpandedInteger(
N->getOperand(0), InL, InH);
5419 if (TLI.expandDIVREMByConstant(
N, Result, NVT, DAG, InL, InH)) {
5428 assert(LC != RTLIB::UNKNOWN_LIBCALL &&
"Unsupported UDIV!");
5430 TargetLowering::MakeLibCallOptions CallOptions;
5431 SplitInteger(TLI.makeLibCall(DAG, LC, VT,
Ops, CallOptions, dl).first,
Lo,
Hi);
5434void DAGTypeLegalizer::ExpandIntRes_UREM(
SDNode *
N,
5436 EVT VT =
N->getValueType(0);
5438 SDValue
Ops[2] = {
N->getOperand(0),
N->getOperand(1) };
5448 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(),
N->getValueType(0));
5450 if (isTypeLegal(NVT)) {
5452 GetExpandedInteger(
N->getOperand(0), InL, InH);
5454 if (TLI.expandDIVREMByConstant(
N, Result, NVT, DAG, InL, InH)) {
5463 assert(LC != RTLIB::UNKNOWN_LIBCALL &&
"Unsupported UREM!");
5465 TargetLowering::MakeLibCallOptions CallOptions;
5466 SplitInteger(TLI.makeLibCall(DAG, LC, VT,
Ops, CallOptions, dl).first,
Lo,
Hi);
5469void DAGTypeLegalizer::ExpandIntRes_ZERO_EXTEND(
SDNode *
N,
5471 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(),
N->getValueType(0));
5473 SDValue
Op =
N->getOperand(0);
5474 if (
Op.getValueType().bitsLE(NVT)) {
5477 Hi = DAG.getConstant(0, dl, NVT);
5481 assert(getTypeAction(
Op.getValueType()) ==
5483 "Only know how to promote this result!");
5484 SDValue Res = GetPromotedInteger(
Op);
5486 "Operand over promoted?");
5488 SplitInteger(Res,
Lo,
Hi);
5490 Hi = DAG.getZeroExtendInReg(
Hi, dl,
5496void DAGTypeLegalizer::ExpandIntRes_ATOMIC_LOAD(
SDNode *
N,
5500 SDVTList VTs = DAG.getVTList(VT, MVT::i1, MVT::Other);
5501 SDValue
Zero = DAG.getConstant(0, dl, VT);
5502 SDValue
Swap = DAG.getAtomicCmpSwap(
5507 ReplaceValueWith(SDValue(
N, 0),
Swap.getValue(0));
5508 ReplaceValueWith(SDValue(
N, 1),
Swap.getValue(2));
5511void DAGTypeLegalizer::ExpandIntRes_VECREDUCE(
SDNode *
N,
5515 SDValue Res = TLI.expandVecReduce(
N, DAG);
5516 SplitInteger(Res,
Lo,
Hi);
5519void DAGTypeLegalizer::ExpandIntRes_Rotate(
SDNode *
N,
5524 SDValue Res = DAG.
getNode(Opcode,
DL,
N->getValueType(0),
N->getOperand(0),
5525 N->getOperand(0),
N->getOperand(1));
5526 SplitInteger(Res,
Lo,
Hi);
5532 SDValue In1, In2, In3, In4;
5533 GetExpandedInteger(
N->getOperand(0), In3, In4);
5534 GetExpandedInteger(
N->getOperand(1), In1, In2);
5538 unsigned Opc =
N->getOpcode();
5541 EVT ShAmtCCVT = getSetCCResultType(ShAmtVT);
5545 SDValue AndNode = DAG.getNode(
ISD::AND,
DL, ShAmtVT, ShAmt,
5546 DAG.getConstant(HalfVTBits,
DL, ShAmtVT));
5548 DAG.getSetCC(
DL, ShAmtCCVT, AndNode, DAG.getConstant(0,
DL, ShAmtVT),
5552 EVT NewShAmtVT = TLI.getShiftAmountTy(HalfVT, DAG.getDataLayout());
5553 SDValue NewShAmt = DAG.getAnyExtOrTrunc(ShAmt,
DL, NewShAmtVT);
5558 Lo = DAG.getNode(
Opc,
DL, HalfVT, Select2, Select1, NewShAmt);
5559 Hi = DAG.getNode(
Opc,
DL, HalfVT, Select3, Select2, NewShAmt);
5564 SDValue Res = TLI.expandCLMUL(
N, DAG);
5565 return SplitInteger(Res,
Lo,
Hi);
5568 SDValue LL, LH, RL, RH;
5569 GetExpandedInteger(
N->getOperand(0), LL, LH);
5570 GetExpandedInteger(
N->getOperand(1), RL, RH);
5581 SDValue HiLoCross1 = DAG.getNode(
ISD::CLMUL,
DL, HalfVT, LL, RH);
5582 SDValue HiLoCross2 = DAG.getNode(
ISD::CLMUL,
DL, HalfVT, LH, RL);
5583 SDValue HiLoCross = DAG.getNode(
ISD::XOR,
DL, HalfVT, HiLoCross1, HiLoCross2);
5584 Hi = DAG.getNode(
ISD::XOR,
DL, HalfVT, LoH, HiLoCross);
5588 SDValue Res = TLI.expandPEXT(
N, DAG);
5589 SplitInteger(Res,
Lo,
Hi);
5593 SDValue Res = TLI.expandPDEP(
N, DAG);
5594 SplitInteger(Res,
Lo,
Hi);
5598 SDValue Res = TLI.expandMULH(
N, DAG);
5599 SplitInteger(Res,
Lo,
Hi);
5604 EVT VT =
N->getValueType(0);
5611 SDValue VScaleBase = DAG.getVScale(dl, HalfVT, One);
5614 SplitInteger(Res,
Lo,
Hi);
5621 "cannot use llvm.read_register with illegal type", Fn,
N->getDebugLoc()));
5622 ReplaceValueWith(SDValue(
N, 1),
N->getOperand(0));
5624 std::tie(LoVT, HiVT) = DAG.GetSplitDestVTs(
N->getValueType(0));
5625 Lo = DAG.getPOISON(LoVT);
5626 Hi = DAG.getPOISON(HiVT);
5633 EVT VT =
N->getSimpleValueType(0);
5634 EVT IdxVT = TLI.getVectorIdxTy(DAG.getDataLayout());
5636 "VectorIdxTy should be smaller than type to be expanded?");
5638 SDValue Res = DAG.
getNode(
N->getOpcode(), SDLoc(
N), IdxVT,
N->getOperand(0));
5640 SplitInteger(Res,
Lo,
Hi);
5651bool DAGTypeLegalizer::ExpandIntegerOperand(
SDNode *
N,
unsigned OpNo) {
5653 SDValue Res = SDValue();
5655 if (CustomLowerNode(
N,
N->getOperand(OpNo).getValueType(),
false))
5658 switch (
N->getOpcode()) {
5661 dbgs() <<
"ExpandIntegerOperand Op #" << OpNo <<
": ";
5662 N->dump(&DAG);
dbgs() <<
"\n";
5667 case ISD::BR_CC: Res = ExpandIntOp_BR_CC(
N);
break;
5671 Res = ExpandOp_FAKE_USE(
N);
5675 Res = TLI.expandLoopDependenceMask(
N, DAG);
5681 case ISD::SETCC: Res = ExpandIntOp_SETCC(
N);
break;
5694 case ISD::ROTR: Res = ExpandIntOp_Shift(
N);
break;
5699 case ISD::UCMP: Res = ExpandIntOp_CMP(
N);
break;
5703 Res = ExpandIntOp_STACKMAP(
N, OpNo);
5706 Res = ExpandIntOp_PATCHPOINT(
N, OpNo);
5708 case ISD::EXPERIMENTAL_VP_STRIDED_LOAD:
5709 case ISD::EXPERIMENTAL_VP_STRIDED_STORE:
5710 Res = ExpandIntOp_VP_STRIDED(
N, OpNo);
5713 Res = ExpandIntOp_WRITE_REGISTER(
N, OpNo);
5718 if (!Res.
getNode())
return false;
5726 "Invalid operand expansion");
5728 ReplaceValueWith(SDValue(
N, 0), Res);
5734void DAGTypeLegalizer::IntegerExpandSetCCOperands(
SDValue &NewLHS,
5738 SDValue LHSLo, LHSHi, RHSLo, RHSHi;
5739 GetExpandedInteger(NewLHS, LHSLo, LHSHi);
5740 GetExpandedInteger(NewRHS, RHSLo, RHSHi);
5753 NewRHS = DAG.getConstant(0, dl, NewLHS.
getValueType());
5760 if ((CCCode ==
ISD::SETLT && CST->isZero()) ||
5761 (CCCode ==
ISD::SETGT && CST->isAllOnes())) {
5789 SDValue LoCmp, HiCmp;
5791 LoCmp = TLI.SimplifySetCC(getSetCCResultType(LHSLo.
getValueType()), LHSLo,
5792 RHSLo, LowCC,
false, DagCombineInfo, dl);
5794 LoCmp = DAG.getSetCC(dl, getSetCCResultType(LHSLo.
getValueType()), LHSLo,
5797 HiCmp = TLI.SimplifySetCC(getSetCCResultType(LHSHi.
getValueType()), LHSHi,
5798 RHSHi, CCCode,
false, DagCombineInfo, dl);
5802 LHSHi, RHSHi, DAG.getCondCode(CCCode));
5811 if ((EqAllowed && (HiCmpC && HiCmpC->
isZero())) ||
5813 ((HiCmpC && HiCmpC->
isOne()) || (LoCmpC && LoCmpC->
isZero())))) {
5822 if (LHSHi == RHSHi) {
5831 EVT ExpandVT = TLI.getTypeToExpandTo(*DAG.getContext(), HiVT);
5832 bool HasSETCCCARRY = TLI.isOperationLegalOrCustom(
ISD::SETCCCARRY, ExpandVT);
5835 if (HasSETCCCARRY) {
5838 bool FlipOperands =
false;
5855 SDVTList VTList = DAG.getVTList(LoVT, getSetCCResultType(LoVT));
5856 SDValue LowCmp = DAG.getNode(
ISD::USUBO, dl, VTList, LHSLo, RHSLo);
5859 DAG.getCondCode(CCCode));
5865 NewLHS = TLI.SimplifySetCC(getSetCCResultType(HiVT), LHSHi, RHSHi,
ISD::SETEQ,
5866 false, DagCombineInfo, dl);
5869 DAG.getSetCC(dl, getSetCCResultType(HiVT), LHSHi, RHSHi,
ISD::SETEQ);
5870 NewLHS = DAG.getSelect(dl, LoCmp.
getValueType(), NewLHS, LoCmp, HiCmp);
5877 IntegerExpandSetCCOperands(NewLHS, NewRHS, CCCode, SDLoc(
N));
5882 NewRHS = DAG.getConstant(0, SDLoc(
N), NewLHS.
getValueType());
5887 return SDValue(DAG.UpdateNodeOperands(
N,
N->getOperand(0),
5888 DAG.getCondCode(CCCode), NewLHS, NewRHS,
5889 N->getOperand(4)), 0);
5895 IntegerExpandSetCCOperands(NewLHS, NewRHS, CCCode, SDLoc(
N));
5900 NewRHS = DAG.getConstant(0, SDLoc(
N), NewLHS.
getValueType());
5905 return SDValue(DAG.UpdateNodeOperands(
N, NewLHS, NewRHS,
5906 N->getOperand(2),
N->getOperand(3),
5907 DAG.getCondCode(CCCode)), 0);
5913 IntegerExpandSetCCOperands(NewLHS, NewRHS, CCCode, SDLoc(
N));
5918 "Unexpected setcc expansion!");
5924 DAG.UpdateNodeOperands(
N, NewLHS, NewRHS, DAG.getCondCode(CCCode)), 0);
5928 SDValue
LHS =
N->getOperand(0);
5929 SDValue
RHS =
N->getOperand(1);
5931 SDValue
Cond =
N->getOperand(3);
5932 SDLoc dl = SDLoc(
N);
5934 SDValue LHSLo, LHSHi, RHSLo, RHSHi;
5935 GetExpandedInteger(
LHS, LHSLo, LHSHi);
5936 GetExpandedInteger(
RHS, RHSLo, RHSHi);
5949 GetExpandedInteger(
N->getOperand(0),
Lo,
Hi);
5959 GetExpandedInteger(
N->getOperand(1),
Lo,
Hi);
5960 return SDValue(DAG.UpdateNodeOperands(
N,
N->getOperand(0),
Lo), 0);
5964 return TLI.expandCMP(
N, DAG);
5972 GetExpandedInteger(
N->getOperand(0),
Lo,
Hi);
5973 return SDValue(DAG.UpdateNodeOperands(
N,
Lo), 0);
5977 bool IsStrict =
N->isStrictFPOpcode();
5980 SDValue Chain = IsStrict ?
N->getOperand(0) : SDValue();
5981 SDValue
Op =
N->getOperand(IsStrict ? 1 : 0);
5982 EVT DstVT =
N->getValueType(0);
5985 assert(LC != RTLIB::UNKNOWN_LIBCALL &&
5986 "Don't know how to expand this XINT_TO_FP!");
5987 TargetLowering::MakeLibCallOptions CallOptions;
5989 std::pair<SDValue, SDValue> Tmp =
5990 TLI.makeLibCall(DAG, LC, DstVT,
Op, CallOptions, SDLoc(
N), Chain);
5995 ReplaceValueWith(SDValue(
N, 1), Tmp.second);
5996 ReplaceValueWith(SDValue(
N, 0), Tmp.first);
6001 assert(!
N->isAtomic() &&
"Should have been a ATOMIC_STORE?");
6004 return ExpandOp_NormalStore(
N, OpNo);
6007 assert(OpNo == 1 &&
"Can only expand the stored value so far");
6009 EVT VT =
N->getOperand(1).getValueType();
6010 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), VT);
6011 SDValue Ch =
N->getChain();
6012 SDValue Ptr =
N->getBasePtr();
6014 MMOMetadata
Metadata =
N->getMMOMetadataForSubAccess();
6020 if (
N->getMemoryVT().bitsLE(NVT)) {
6021 GetExpandedInteger(
N->getValue(),
Lo,
Hi);
6022 return DAG.getTruncStore(Ch, dl,
Lo, Ptr,
N->getPointerInfo(),
6023 N->getMemoryVT(),
N->getBaseAlign(), MMOFlags,
6027 if (DAG.getDataLayout().isLittleEndian()) {
6029 GetExpandedInteger(
N->getValue(),
Lo,
Hi);
6031 Lo = DAG.getStore(Ch, dl,
Lo, Ptr,
N->getPointerInfo(),
N->getBaseAlign(),
6034 unsigned ExcessBits =
6041 Hi = DAG.getTruncStore(Ch, dl,
Hi, Ptr,
6042 N->getPointerInfo().getWithOffset(IncrementSize),
6043 NEVT,
N->getBaseAlign(), MMOFlags,
Metadata);
6049 GetExpandedInteger(
N->getValue(),
Lo,
Hi);
6051 EVT ExtVT =
N->getMemoryVT();
6054 unsigned ExcessBits = (EBytes - IncrementSize)*8;
6062 DAG.getShiftAmountConstant(NVT.
getSizeInBits() - ExcessBits, NVT, dl));
6066 DAG.getShiftAmountConstant(ExcessBits, NVT, dl)));
6070 Hi = DAG.getTruncStore(Ch, dl,
Hi, Ptr,
N->getPointerInfo(), HiVT,
6076 Lo = DAG.getTruncStore(Ch, dl,
Lo, Ptr,
6077 N->getPointerInfo().getWithOffset(IncrementSize),
6085 GetExpandedInteger(
N->getOperand(0), InL, InH);
6094 N->getOperand(0),
N->getOperand(2),
N->getOperand(1),
6096 return Swap.getValue(1);
6099SDValue DAGTypeLegalizer::ExpandIntOp_VP_STRIDED(
SDNode *
N,
unsigned OpNo) {
6100 assert((
N->getOpcode() == ISD::EXPERIMENTAL_VP_STRIDED_LOAD && OpNo == 3) ||
6101 (
N->getOpcode() == ISD::EXPERIMENTAL_VP_STRIDED_STORE && OpNo == 4));
6105 GetExpandedInteger(NewOps[OpNo], NewOps[OpNo],
Hi);
6107 return SDValue(DAG.UpdateNodeOperands(
N, NewOps), 0);
6110SDValue DAGTypeLegalizer::ExpandIntOp_WRITE_REGISTER(
SDNode *
N,
unsigned OpNo) {
6113 "cannot use llvm.write_register with illegal type", Fn,
6116 return N->getOperand(0);
6119SDValue DAGTypeLegalizer::PromoteIntRes_VECTOR_SPLICE(
SDNode *
N) {
6122 SDValue
V0 = GetPromotedInteger(
N->getOperand(0));
6123 SDValue
V1 = GetPromotedInteger(
N->getOperand(1));
6124 EVT OutVT =
V0.getValueType();
6126 return DAG.getNode(
N->getOpcode(), dl, OutVT, V0,
V1,
N->getOperand(2));
6129SDValue DAGTypeLegalizer::PromoteIntRes_VECTOR_REPEAT(
SDNode *
N) {
6132 EVT OutVT =
N->getValueType(0);
6133 EVT NOutVT = TLI.getTypeToTransformTo(*DAG.getContext(), OutVT);
6138 return DAG.getNode(
N->getOpcode(),
DL, NOutVT,
Op);
6141SDValue DAGTypeLegalizer::PromoteIntRes_VECTOR_INTERLEAVE_DEINTERLEAVE(
SDNode *
N) {
6143 unsigned Factor =
N->getNumOperands();
6146 for (
unsigned i = 0; i != Factor; i++)
6147 Ops[i] = GetPromotedInteger(
N->getOperand(i));
6150 SDValue Res = DAG.
getNode(
N->getOpcode(),
DL, DAG.getVTList(ResVTs),
Ops);
6152 for (
unsigned i = 0; i != Factor; i++)
6153 SetPromotedInteger(SDValue(
N, i), Res.
getValue(i));
6158SDValue DAGTypeLegalizer::PromoteIntRes_EXTRACT_SUBVECTOR(
SDNode *
N) {
6160 EVT OutVT =
N->getValueType(0);
6161 EVT NOutVT = TLI.getTypeToTransformTo(*DAG.getContext(), OutVT);
6162 assert(NOutVT.
isVector() &&
"This type must be promoted to a vector type");
6166 SDValue BaseIdx =
N->getOperand(1);
6171 SDValue InOp0 =
N->getOperand(0);
6183 DAG.getConstant(
alignDown(IdxVal, NElts), dl,
6185 SDValue Step2 = DAG.getNode(
6187 DAG.getConstant(IdxVal % NElts, dl, BaseIdx.
getValueType()));
6193 SDValue
Ops[] = {GetWidenedVector(InOp0), BaseIdx};
6202 SDValue
Ops[] = { GetPromotedInteger(InOp0), BaseIdx };
6206 "Promoted operand has an element type greater than result");
6219 InOp0 = GetPromotedInteger(InOp0);
6226 Ops.reserve(OutNumElems);
6227 for (
unsigned i = 0; i != OutNumElems; ++i) {
6232 N->getOperand(0), Index);
6233 SDValue
Op = DAG.getAnyExtOrTrunc(Ext, dl, NOutVTElem);
6238 return DAG.getBuildVector(NOutVT, dl,
Ops);
6241SDValue DAGTypeLegalizer::PromoteIntRes_INSERT_SUBVECTOR(
SDNode *
N) {
6242 EVT OutVT =
N->getValueType(0);
6243 EVT NOutVT = TLI.getTypeToTransformTo(*DAG.getContext(), OutVT);
6244 assert(NOutVT.
isVector() &&
"This type must be promoted to a vector type");
6249 SDValue
Idx =
N->getOperand(2);
6256 Vec = GetPromotedInteger(Vec);
6262SDValue DAGTypeLegalizer::PromoteIntRes_VECTOR_REVERSE(
SDNode *
N) {
6265 SDValue
V0 = GetPromotedInteger(
N->getOperand(0));
6266 EVT OutVT =
V0.getValueType();
6271SDValue DAGTypeLegalizer::PromoteIntRes_VECTOR_SHUFFLE(
SDNode *
N) {
6273 EVT VT =
N->getValueType(0);
6278 SDValue
V0 = GetPromotedInteger(
N->getOperand(0));
6279 SDValue
V1 = GetPromotedInteger(
N->getOperand(1));
6280 EVT OutVT =
V0.getValueType();
6282 return DAG.getVectorShuffle(OutVT, dl, V0,
V1, NewMask);
6286 EVT OutVT =
N->getValueType(0);
6287 EVT NOutVT = TLI.getTypeToTransformTo(*DAG.getContext(), OutVT);
6288 assert(NOutVT.
isVector() &&
"This type must be promoted to a vector type");
6289 unsigned NumElems =
N->getNumOperands();
6296 Ops.reserve(NumElems);
6297 for (
unsigned i = 0; i != NumElems; ++i) {
6298 SDValue
Op =
N->getOperand(i);
6299 EVT OpVT =
Op.getValueType();
6304 if (OpVT.
bitsLT(NOutVTElem)) {
6310 ExtOpc = NOutExtOpc;
6311 Op = DAG.getNode(ExtOpc, dl, NOutVTElem,
Op);
6316 return DAG.getBuildVector(NOutVT, dl,
Ops);
6323 assert(!
N->getOperand(0).getValueType().isVector() &&
6324 "Input must be a scalar");
6326 EVT OutVT =
N->getValueType(0);
6327 EVT NOutVT = TLI.getTypeToTransformTo(*DAG.getContext(), OutVT);
6328 assert(NOutVT.
isVector() &&
"This type must be promoted to a vector type");
6332 return DAG.getNode(
N->getOpcode(), dl, NOutVT,
Op);
6337 EVT OutVT =
N->getValueType(0);
6338 EVT NOutVT = TLI.getTypeToTransformTo(*DAG.getContext(), OutVT);
6340 "Type must be promoted to a scalable vector type");
6341 const APInt &StepVal =
N->getConstantOperandAPInt(0);
6342 return DAG.getStepVector(dl, NOutVT,
6346SDValue DAGTypeLegalizer::PromoteIntRes_CONCAT_VECTORS(
SDNode *
N) {
6349 EVT OutVT =
N->getValueType(0);
6350 EVT NOutVT = TLI.getTypeToTransformTo(*DAG.getContext(), OutVT);
6351 assert(NOutVT.
isVector() &&
"This type must be promoted to a vector type");
6353 unsigned NumOperands =
N->getNumOperands();
6357 EVT OpVT =
N->getOperand(0).getValueType();
6362 "Unhandled legalization type");
6368 for (
unsigned I = 0;
I < NumOperands; ++
I) {
6369 SDValue
Op =
N->getOperand(
I);
6371 Op = GetPromotedInteger(
Op);
6380 *DAG.getContext(),
Ops[0].getValueType().getVectorElementType());
6381 return DAG.getAnyExtOrTrunc(
6385 unsigned NumElem =
N->getOperand(0).getValueType().getVectorNumElements();
6386 assert(NumElem * NumOperands == NumOutElem &&
6387 "Unexpected number of elements");
6391 for (
unsigned i = 0; i < NumOperands; ++i) {
6392 SDValue
Op =
N->getOperand(i);
6394 Op = GetPromotedInteger(
Op);
6395 EVT SclrTy =
Op.getValueType().getVectorElementType();
6396 assert(NumElem ==
Op.getValueType().getVectorNumElements() &&
6397 "Unexpected number of elements");
6399 for (
unsigned j = 0;
j < NumElem; ++
j) {
6401 DAG.getVectorIdxConstant(j, dl));
6402 Ops[i * NumElem +
j] = DAG.getAnyExtOrTrunc(Ext, dl, OutElemTy);
6406 return DAG.getBuildVector(NOutVT, dl,
Ops);
6409SDValue DAGTypeLegalizer::PromoteIntRes_EXTEND_VECTOR_INREG(
SDNode *
N) {
6410 EVT VT =
N->getValueType(0);
6411 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), VT);
6412 assert(NVT.
isVector() &&
"This type must be promoted to a vector type");
6420 if (getTypeAction(
N->getOperand(0).getValueType())
6424 switch(
N->getOpcode()) {
6426 Promoted = SExtPromotedInteger(
N->getOperand(0));
6429 Promoted = ZExtPromotedInteger(
N->getOperand(0));
6432 Promoted = GetPromotedInteger(
N->getOperand(0));
6444 DAG.getVectorIdxConstant(0, dl));
6446 return DAG.getNode(
N->getOpcode(), dl, NVT, Promoted);
6450 return DAG.getNode(
N->getOpcode(), dl, NVT,
N->getOperand(0));
6453SDValue DAGTypeLegalizer::PromoteIntRes_VECTOR_FIND_LAST_ACTIVE(
SDNode *
N) {
6454 EVT VT =
N->getValueType(0);
6455 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), VT);
6459SDValue DAGTypeLegalizer::PromoteIntRes_GET_ACTIVE_LANE_MASK(
SDNode *
N) {
6460 EVT VT =
N->getValueType(0);
6461 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), VT);
6465SDValue DAGTypeLegalizer::PromoteIntRes_MASK_BEFOREFIRST(
SDNode *
N) {
6466 EVT VT =
N->getValueType(0);
6467 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), VT);
6468 SDValue
Op = PromoteTargetBoolean(
N->getOperand(0), NVT);
6473 EVT VT =
N->getValueType(0);
6474 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), VT);
6476 NewOps[2] = PromoteTargetBoolean(
N->getOperand(2), NVT);
6480SDValue DAGTypeLegalizer::PromoteIntRes_PARTIAL_REDUCE_MLA(
SDNode *
N) {
6482 EVT VT =
N->getValueType(0);
6483 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), VT);
6484 SDValue ExtAcc = GetPromotedInteger(
N->getOperand(0));
6485 return DAG.getNode(
N->getOpcode(),
DL, NVT, ExtAcc,
N->getOperand(1),
6489SDValue DAGTypeLegalizer::PromoteIntRes_INSERT_VECTOR_ELT(
SDNode *
N) {
6490 EVT OutVT =
N->getValueType(0);
6491 EVT NOutVT = TLI.getTypeToTransformTo(*DAG.getContext(), OutVT);
6492 assert(NOutVT.
isVector() &&
"This type must be promoted to a vector type");
6497 SDValue
V0 = GetPromotedInteger(
N->getOperand(0));
6500 NOutVTElem,
N->getOperand(1));
6502 V0, ConvElem,
N->getOperand(2));
6509 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(),
N->getValueType(0));
6510 return DAG.getNode(
N->getOpcode(), dl, NVT,
N->ops());
6518 SDValue
Start = PromoteIntOpVectorReduction(
N,
N->getOperand(0));
6519 return DAG.getNode(
N->getOpcode(),
DL,
Start.getValueType(), Start,
6520 N->getOperand(1),
N->getOperand(2),
N->getOperand(3));
6524 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(),
N->getValueType(0));
6527 assert(
N->getNumValues() == 3 &&
"Expected 3 values for PATCHPOINT");
6528 SDVTList VTList = DAG.getVTList({NVT, MVT::Other, MVT::Glue});
6534 SDValue From[] = {SDValue(
N, 1), SDValue(
N, 2)};
6536 DAG.ReplaceAllUsesOfValuesWith(From, To, 2);
6541SDValue DAGTypeLegalizer::PromoteIntRes_READ_REGISTER(
SDNode *
N) {
6544 "cannot use llvm.read_register with illegal type", Fn,
N->getDebugLoc()));
6546 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(),
N->getValueType(0));
6547 ReplaceValueWith(SDValue(
N, 1),
N->getOperand(0));
6548 return DAG.getPOISON(NVT);
6551SDValue DAGTypeLegalizer::PromoteIntOp_EXTRACT_VECTOR_ELT(
SDNode *
N) {
6553 SDValue
V0 = GetPromotedInteger(
N->getOperand(0));
6554 SDValue
V1 = DAG.getZExtOrTrunc(
N->getOperand(1), dl,
6555 TLI.getVectorIdxTy(DAG.getDataLayout()));
6557 V0->getValueType(0).getScalarType(), V0,
V1);
6562 return DAG.getAnyExtOrTrunc(Ext, dl,
N->getValueType(0));
6565SDValue DAGTypeLegalizer::PromoteIntOp_INSERT_SUBVECTOR(
SDNode *
N) {
6569 SDValue
V0 =
N->getOperand(0);
6570 SDValue
V1 = GetPromotedInteger(
N->getOperand(1));
6571 SDValue
Idx =
N->getOperand(2);
6573 V1.getValueType().getVectorElementType(),
6574 V0.getValueType().getVectorElementCount());
6575 V0 = DAG.getAnyExtOrTrunc(V0, dl, PromVT);
6577 return DAG.getAnyExtOrTrunc(Ext, dl,
N->getValueType(0));
6584 SDValue
V0 =
N->getOperand(0);
6585 SDValue
V1 =
N->getOperand(1);
6586 EVT InVT1 =
V1.getValueType();
6589 TLI.getTypeToTransformTo(*DAG.getContext(), InVT1),
V1);
6590 return DAG.getNode(
N->getOpcode(), dl,
N->getValueType(0), V0, VPromoted);
6593SDValue DAGTypeLegalizer::PromoteIntOp_EXTRACT_SUBVECTOR(
SDNode *
N) {
6595 SDValue
V0 = GetPromotedInteger(
N->getOperand(0));
6596 MVT InVT =
V0.getValueType().getSimpleVT();
6603SDValue DAGTypeLegalizer::PromoteIntOp_CONCAT_VECTORS(
SDNode *
N) {
6606 EVT ResVT =
N->getValueType(0);
6607 unsigned NumElems =
N->getNumOperands();
6610 SDValue ResVec = DAG.getPOISON(ResVT);
6612 for (
unsigned OpIdx = 0; OpIdx < NumElems; ++OpIdx) {
6613 SDValue
Op =
N->getOperand(OpIdx);
6614 unsigned OpNumElts =
Op.getValueType().getVectorMinNumElements();
6616 DAG.getIntPtrConstant(OpIdx * OpNumElts, dl));
6628 for (
unsigned VecIdx = 0; VecIdx != NumElems; ++VecIdx) {
6629 SDValue Incoming = GetPromotedInteger(
N->getOperand(VecIdx));
6633 for (
unsigned i=0; i<NumElem; ++i) {
6636 DAG.getVectorIdxConstant(i, dl));
6642 return DAG.getBuildVector(
N->getValueType(0), dl, NewOps);
6645SDValue DAGTypeLegalizer::ExpandIntOp_STACKMAP(
SDNode *
N,
unsigned OpNo) {
6647 SDValue
Op =
N->getOperand(OpNo);
6658 for (
unsigned I = 0;
I < OpNo;
I++)
6661 EVT Ty =
Op.getValueType();
6662 SDLoc
DL = SDLoc(
N);
6665 DAG.getTargetConstant(StackMaps::ConstantOp,
DL, MVT::i64));
6673 for (
unsigned I = OpNo + 1;
I <
N->getNumOperands();
I++)
6676 SDValue
NewNode = DAG.getNode(
N->getOpcode(),
DL,
N->getVTList(), NewOps);
6678 for (
unsigned ResNum = 0; ResNum <
N->getNumValues(); ResNum++)
6679 ReplaceValueWith(SDValue(
N, ResNum),
NewNode.getValue(ResNum));
6684SDValue DAGTypeLegalizer::ExpandIntOp_PATCHPOINT(
SDNode *
N,
unsigned OpNo) {
6686 SDValue
Op =
N->getOperand(OpNo);
6697 for (
unsigned I = 0;
I < OpNo;
I++)
6700 EVT Ty =
Op.getValueType();
6701 SDLoc
DL = SDLoc(
N);
6704 DAG.getTargetConstant(StackMaps::ConstantOp,
DL, MVT::i64));
6712 for (
unsigned I = OpNo + 1;
I <
N->getNumOperands();
I++)
6715 SDValue
NewNode = DAG.getNode(
N->getOpcode(),
DL,
N->getVTList(), NewOps);
6717 for (
unsigned ResNum = 0; ResNum <
N->getNumValues(); ResNum++)
6718 ReplaceValueWith(SDValue(
N, ResNum),
NewNode.getValue(ResNum));
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static bool isSigned(unsigned Opcode)
const size_t AbstractManglingParser< Derived, Alloc >::NumOps
const AbstractManglingParser< Derived, Alloc >::OperatorInfo AbstractManglingParser< Derived, Alloc >::Ops[]
static SDValue SaturateWidenedDIVFIX(SDValue V, SDLoc &dl, unsigned SatW, bool Signed, const TargetLowering &TLI, SelectionDAG &DAG)
static SDValue fpExtendHelper(SDValue Op, SDValue &Chain, bool IsStrict, EVT VT, SDLoc DL, SelectionDAG &DAG)
static SDValue earlyExpandDIVFIX(SDNode *N, SDValue LHS, SDValue RHS, unsigned Scale, const TargetLowering &TLI, SelectionDAG &DAG, unsigned SatW=0)
static unsigned getExtendForIntVecReduction(SDNode *N)
static std::pair< ISD::CondCode, ISD::NodeType > getExpandedMinMaxOps(int Op)
static bool isZero(Value *V, const DataLayout &DL, DominatorTree *DT, AssumptionCache *AC)
const SmallVectorImpl< MachineOperand > & Cond
static TableGen::Emitter::Opt Y("gen-skeleton-entry", EmitSkeleton, "Generate example skeleton entry")
This file describes how to lower LLVM code to machine code.
Class for arbitrary precision integers.
static APInt getAllOnes(unsigned numBits)
Return an APInt of a specified width with all bits set.
unsigned getActiveBits() const
Compute the number of active bits in the value.
LLVM_ABI APInt trunc(unsigned width) const
Truncate to new width.
static APInt getMaxValue(unsigned numBits)
Gets maximum unsigned value of APInt for specific bit width.
unsigned countLeadingOnes() const
bool ugt(const APInt &RHS) const
Unsigned greater than comparison.
static APInt getSignedMaxValue(unsigned numBits)
Gets maximum signed value of APInt for a specific bit width.
static APInt getSignedMinValue(unsigned numBits)
Gets minimum signed value of APInt for a specific bit width.
unsigned countTrailingZeros() const
unsigned countLeadingZeros() const
LLVM_ABI APInt sext(unsigned width) const
Sign extend to a new width.
bool isSubsetOf(const APInt &RHS) const
This operation checks that all bits set in this APInt are also set in RHS.
static APInt getLowBitsSet(unsigned numBits, unsigned loBitsSet)
Constructs an APInt value that has the bottom loBitsSet bits set.
static APInt getHighBitsSet(unsigned numBits, unsigned hiBitsSet)
Constructs an APInt value that has the top hiBitsSet bits set.
unsigned countTrailingOnes() const
static APInt getOneBitSet(unsigned numBits, unsigned BitNo)
Return an APInt with exactly one bit set in the result.
APInt lshr(unsigned shiftAmt) const
Logical right-shift function.
bool uge(const APInt &RHS) const
Unsigned greater or equal comparison.
This is an SDNode representing atomic operations.
const APInt & getValue() const
Return the constant as an APInt value reference.
const ConstantInt * getConstantIntValue() const
uint64_t getZExtValue() const
@ NewNode
This is a new node, not before seen, that was created in the process of legalizing some other node.
const Function & getFunction() const
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function.
LLVM_ABI void diagnose(const DiagnosticInfo &DI)
Report a message to the currently installed diagnostic handler.
This class is used to represent ISD::LOAD nodes.
unsigned getVectorNumElements() const
TypeSize getSizeInBits() const
Returns the size of the specified MVT in bits.
static MVT getVectorVT(MVT VT, unsigned NumElements)
MVT getVectorElementType() const
Flags
Flags values. These may be or'd together.
This class is used to represent an MGATHER node.
This class is used to represent an MLOAD node.
This class is used to represent an MSCATTER node.
This class is used to represent an MSTORE node.
MachineMemOperand * getMemOperand() const
Return the unique MachineMemOperand object describing the memory reference performed by operation.
EVT getMemoryVT() const
Return the type of the in-memory value.
static PointerType * getUnqual(LLVMContext &C)
This constructs an opaque pointer to an object in the default address space (address space zero).
Wrapper class for IR location info (IR ordering and DebugLoc) to be passed into SDNode creation funct...
Represents one node in the SelectionDAG.
bool isStrictFPOpcode()
Test if this node is a strict floating point pseudo-op.
unsigned getOpcode() const
Return the SelectionDAG opcode value for this node.
SDNodeFlags getFlags() const
uint64_t getAsZExtVal() const
Helper method returns the zero-extended integer value of a ConstantSDNode.
const SDValue & getOperand(unsigned Num) const
EVT getValueType(unsigned ResNo) const
Return the type of a specified result.
Unlike LLVM values, Selection DAG nodes may return multiple values as the result of a computation.
SDNode * getNode() const
get the SDNode which holds the desired result
SDValue getValue(unsigned R) const
EVT getValueType() const
Return the ValueType of the referenced return value.
uint64_t getScalarValueSizeInBits() const
This is used to represent a portion of an LLVM function in a low-level Data Dependence DAG representa...
SDValue getExtOrTrunc(SDValue Op, const SDLoc &DL, EVT VT, unsigned Opcode)
Convert Op, which must be of integer type, to the integer type VT, by either any/sign/zero-extending ...
LLVM_ABI SDValue getConstant(uint64_t Val, const SDLoc &DL, EVT VT, bool isTarget=false, bool isOpaque=false)
Create a ConstantSDNode wrapping a constant value.
LLVM_ABI SDValue getNode(unsigned Opcode, const SDLoc &DL, EVT VT, ArrayRef< SDUse > Ops)
Gets or creates the specified node.
LLVM_ABI SDValue getZExtOrTrunc(SDValue Op, const SDLoc &DL, EVT VT)
Convert Op, which must be of integer type, to the integer type VT, by either zero-extending or trunca...
LLVMContext * getContext() const
void reserve(size_type N)
void push_back(const T &Elt)
This class is used to represent ISD::STORE nodes.
LegalizeAction
This enum indicates whether operations are valid for a target, and if not, what action should be used...
ShiftLegalizationStrategy
Return the preferred strategy to legalize tihs SHIFT instruction, with ExpansionFactor being the recu...
LegalizeTypeAction
This enum indicates whether a types are legal for a target, and if not, what action should be used to...
@ TypeScalarizeScalableVector
BooleanContent
Enum that describes how the target represents true/false values.
@ ZeroOrOneBooleanContent
@ UndefinedBooleanContent
@ ZeroOrNegativeOneBooleanContent
std::vector< ArgListEntry > ArgListTy
static ISD::NodeType getExtendForContent(BooleanContent Content)
This class defines information used to lower LLVM code to legal SelectionDAG operators that the targe...
SDValue expandFixedPointDiv(unsigned Opcode, const SDLoc &dl, SDValue LHS, SDValue RHS, unsigned Scale, SelectionDAG &DAG) const
Method for building the DAG expansion of ISD::[US]DIVFIX[SAT].
static constexpr TypeSize getFixed(ScalarTy ExactSize)
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
This class is used to represent a VP_LOAD node.
This class is used to represent a VP_STORE node.
constexpr bool hasKnownScalarFactor(const FixedOrScalableQuantity &RHS) const
Returns true if there exists a value X where RHS*X will result in a value whose quantity matches our ...
constexpr ScalarTy getKnownScalarFactor(const FixedOrScalableQuantity &RHS) const
Returns a value X where RHS*X will result in a value whose quantity matches our own.
constexpr ScalarTy getKnownMinValue() const
Returns the minimum value this quantity can represent.
constexpr LeafTy divideCoefficientBy(ScalarTy RHS) const
We do not provide the '/' operator here because division for polynomial types does not work in the sa...
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
constexpr std::underlying_type_t< E > Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
bool isNON_EXTLoad(const SDNode *N)
Returns true if the specified node is a non-extending load.
NodeType
ISD::NodeType enum - This enum defines the target-independent operators for a SelectionDAG.
@ SETCC
SetCC operator - This evaluates to a true value iff the condition is true.
@ MERGE_VALUES
MERGE_VALUES - This node takes multiple discrete operands and returns them all as its individual resu...
@ STRICT_FSETCC
STRICT_FSETCC/STRICT_FSETCCS - Constrained versions of SETCC, used for floating-point operands only.
@ POISON
POISON - A poison node.
@ PARTIAL_REDUCE_SMLA
PARTIAL_REDUCE_[U|S]MLA(Accumulator, Input1, Input2) The partial reduction nodes sign or zero extend ...
@ LOOP_DEPENDENCE_RAW_MASK
@ MASK_BEFOREFIRST
Has one mask vector operand.
@ COND_LOOP
COND_LOOP is a conditional branch to self, used for implementing efficient conditional traps.
@ MLOAD
Masked load and store - consecutive vector load and store operations with additional mask operand tha...
@ SMUL_LOHI
SMUL_LOHI/UMUL_LOHI - Multiply two integers of type iN, producing a signed/unsigned value of type i[2...
@ INSERT_SUBVECTOR
INSERT_SUBVECTOR(VECTOR1, VECTOR2, IDX) - Returns a vector with VECTOR2 inserted into VECTOR1.
@ BSWAP
Byte Swap and Counting operators.
@ SMULFIX
RESULT = [US]MULFIX(LHS, RHS, SCALE) - Perform fixed point multiplication on 2 integers with the same...
@ ATOMIC_STORE
OUTCHAIN = ATOMIC_STORE(INCHAIN, val, ptr) This corresponds to "store atomic" instruction.
@ ADDC
Carry-setting nodes for multiple precision addition and subtraction.
@ ADD
Simple integer binary arithmetic operators.
@ LOAD
LOAD and STORE have token chains as their first operand, then the same operands as an LLVM load/store...
@ SMULFIXSAT
Same as the corresponding unsaturated fixed point instructions, but the result is clamped between the...
@ ANY_EXTEND
ANY_EXTEND - Used for integer types. The high bits are undefined.
@ CTTZ_ELTS
Returns the number of number of trailing (least significant) zero elements in a vector.
@ VECTOR_FIND_LAST_ACTIVE
Finds the index of the last active mask element Operands: Mask.
@ ATOMIC_CMP_SWAP_WITH_SUCCESS
Val, Success, OUTCHAIN = ATOMIC_CMP_SWAP_WITH_SUCCESS(INCHAIN, ptr, cmp, swap) N.b.
@ SINT_TO_FP
[SU]INT_TO_FP - These operators convert integers (whose interpreted sign depends on the first letter)...
@ CONCAT_VECTORS
CONCAT_VECTORS(VECTOR0, VECTOR1, ...) - Given a number of values of vector type with the same length ...
@ ABS
ABS - Determine the unsigned absolute value of a signed integer value of the same bitwidth.
@ SIGN_EXTEND_VECTOR_INREG
SIGN_EXTEND_VECTOR_INREG(Vector) - This operator represents an in-register sign-extension of the low ...
@ SDIVREM
SDIVREM/UDIVREM - Divide two integers and produce both a quotient and remainder result.
@ FP16_TO_FP
FP16_TO_FP, FP_TO_FP16 - These operators are used to perform promotions and truncation for half-preci...
@ FAKE_USE
FAKE_USE represents a use of the operand but does not do anything.
@ BITCAST
BITCAST - This operator converts between integer, vector and FP values, as if the value was stored to...
@ BUILD_PAIR
BUILD_PAIR - This is the opposite of EXTRACT_ELEMENT in some ways.
@ CLMUL
Carry-less multiplication operations.
@ FLDEXP
FLDEXP - ldexp, inspired by libm (op0 * 2**op1).
@ SDIVFIX
RESULT = [US]DIVFIX(LHS, RHS, SCALE) - Perform fixed point division on 2 integers with the same width...
@ CONVERT_FROM_ARBITRARY_FP
CONVERT_FROM_ARBITRARY_FP - This operator converts from an arbitrary floating-point represented as an...
@ SET_ROUNDING
Set rounding mode.
@ SIGN_EXTEND
Conversion operators.
@ AVGCEILS
AVGCEILS/AVGCEILU - Rounding averaging add - Add two integers using an integer of type i[N+2],...
@ SCALAR_TO_VECTOR
SCALAR_TO_VECTOR(VAL) - This represents the operation of loading a scalar value into element 0 of the...
@ READSTEADYCOUNTER
READSTEADYCOUNTER - This corresponds to the readfixedcounter intrinsic.
@ SETCCCARRY
Like SetCC, ops #0 and #1 are the LHS and RHS operands to compare, but op #2 is a boolean indicating ...
@ BR_CC
BR_CC - Conditional branch.
@ SSUBO
Same for subtraction.
@ VECTOR_INTERLEAVE
VECTOR_INTERLEAVE(VEC1, VEC2, ...) - Returns N vectors from N input vectors, where N is the factor to...
@ STEP_VECTOR
STEP_VECTOR(IMM) - Returns a scalable vector whose lanes are comprised of a linear sequence of unsign...
@ IS_FPCLASS
Performs a check of floating point class property, defined by IEEE-754.
@ SSUBSAT
RESULT = [US]SUBSAT(LHS, RHS) - Perform saturation subtraction on 2 integers with the same bit width ...
@ SELECT
Select(COND, TRUEVAL, FALSEVAL).
@ ATOMIC_LOAD
Val, OUTCHAIN = ATOMIC_LOAD(INCHAIN, ptr) This corresponds to "load atomic" instruction.
@ UNDEF
UNDEF - An undefined node.
@ EXTRACT_ELEMENT
EXTRACT_ELEMENT - This is used to get the lower or upper (determined by a Constant,...
@ SPLAT_VECTOR
SPLAT_VECTOR(VAL) - Returns a vector with the scalar value VAL duplicated in all lanes.
@ GET_ACTIVE_LANE_MASK
GET_ACTIVE_LANE_MASK - this corrosponds to the llvm.get.active.lane.mask intrinsic.
@ SADDO
RESULT, BOOL = [SU]ADDO(LHS, RHS) - Overflow-aware nodes for addition.
@ ARITH_FENCE
ARITH_FENCE - This corresponds to a arithmetic fence intrinsic.
@ CTLS
Count leading redundant sign bits.
@ VECREDUCE_ADD
Integer reductions may have a result type larger than the vector element type.
@ GET_ROUNDING
Returns current rounding mode: -1 Undefined 0 Round to 0 1 Round to nearest, ties to even 2 Round to ...
@ MULHU
MULHU/MULHS - Multiply high - Multiply two integers of type iN, producing an unsigned/signed value of...
@ SHL
Shift and rotation operations.
@ VECTOR_SHUFFLE
VECTOR_SHUFFLE(VEC1, VEC2) - Returns a vector, of the same type as VEC1/VEC2.
@ EXTRACT_SUBVECTOR
EXTRACT_SUBVECTOR(VECTOR, IDX) - Returns a subvector from VECTOR.
@ READ_REGISTER
READ_REGISTER, WRITE_REGISTER - This node represents llvm.register on the DAG, which implements the n...
@ EXTRACT_VECTOR_ELT
EXTRACT_VECTOR_ELT(VECTOR, IDX) - Returns a single element from VECTOR identified by the (potentially...
@ ZERO_EXTEND
ZERO_EXTEND - Used for integer types, zeroing the new bits.
@ SELECT_CC
Select with condition operator - This selects between a true value and a false value (ops #2 and #3) ...
@ VSCALE
VSCALE(IMM) - Returns the runtime scaling factor used to calculate the number of elements within a sc...
@ ATOMIC_CMP_SWAP
Val, OUTCHAIN = ATOMIC_CMP_SWAP(INCHAIN, ptr, cmp, swap) For double-word atomic operations: ValLo,...
@ SSHLSAT
RESULT = [US]SHLSAT(LHS, RHS) - Perform saturation left shift.
@ PATCHPOINT
The llvm.experimental.patchpoint.
@ SMULO
Same for multiplication.
@ VECTOR_SPLICE_LEFT
VECTOR_SPLICE_LEFT(VEC1, VEC2, OFFSET) - Shifts CONCAT_VECTORS(VEC1, VEC2) left by OFFSET elements an...
@ ANY_EXTEND_VECTOR_INREG
ANY_EXTEND_VECTOR_INREG(Vector) - This operator represents an in-register any-extension of the low la...
@ SIGN_EXTEND_INREG
SIGN_EXTEND_INREG - This operator atomically performs a SHL/SRA pair to sign extend a small value in ...
@ SMIN
[US]{MIN/MAX} - Binary minimum or maximum of signed or unsigned integers.
@ MASKED_UDIV
Masked vector arithmetic that returns poison on disabled lanes.
@ VECTOR_REVERSE
VECTOR_REVERSE(VECTOR) - Returns a vector, of the same type as VECTOR, whose elements are shuffled us...
@ SDIVFIXSAT
Same as the corresponding unsaturated fixed point instructions, but the result is clamped between the...
@ FP_EXTEND
X = FP_EXTEND(Y) - Extend a smaller FP type into a larger FP type.
@ VSELECT
Select with a vector condition (op #0) and two vector operands (ops #1 and #2), returning a vector re...
@ UADDO_CARRY
Carry-using nodes for multiple precision addition and subtraction.
@ STRICT_SINT_TO_FP
STRICT_[US]INT_TO_FP - Convert a signed or unsigned integer to a floating point value.
@ MGATHER
Masked gather and scatter - load and store operations for a vector of random addresses with additiona...
@ BF16_TO_FP
BF16_TO_FP, FP_TO_BF16 - These operators are used to perform promotions and truncation for bfloat16.
@ FRAMEADDR
FRAMEADDR, RETURNADDR - These nodes represent llvm.frameaddress and llvm.returnaddress on the DAG.
@ PEXT
Parallel bit extract (compress) and parallel bit deposit (expand).
@ STRICT_FP_TO_SINT
STRICT_FP_TO_[US]INT - Convert a floating point value to a signed or unsigned integer.
@ FP_TO_SINT
FP_TO_[US]INT - Convert a floating point value to a signed or unsigned integer.
@ READCYCLECOUNTER
READCYCLECOUNTER - This corresponds to the readcyclecounter intrinsic.
@ STRICT_FP_EXTEND
X = STRICT_FP_EXTEND(Y) - Extend a smaller FP type into a larger FP type.
@ AND
Bitwise operators - logical and, logical or, logical xor.
@ SCMP
[US]CMP - 3-way comparison of signed or unsigned integers.
@ AVGFLOORS
AVGFLOORS/AVGFLOORU - Averaging add - Add two integers using an integer of type i[N+1],...
@ VECTOR_MATCH
VECTOR_MATCH - this corresponds to the llvm.experimental.vector.match intrinsic.
@ VECTOR_SPLICE_RIGHT
VECTOR_SPLICE_RIGHT(VEC1, VEC2, OFFSET) - Shifts CONCAT_VECTORS(VEC1,VEC2) right by OFFSET elements a...
@ ADDE
Carry-using nodes for multiple precision addition and subtraction.
@ STACKMAP
The llvm.experimental.stackmap intrinsic.
@ SPLAT_VECTOR_PARTS
SPLAT_VECTOR_PARTS(SCALAR1, SCALAR2, ...) - Returns a vector with the scalar values joined together a...
@ FREEZE
FREEZE - FREEZE(VAL) returns an arbitrary value if VAL is UNDEF (or is evaluated to UNDEF),...
@ INSERT_VECTOR_ELT
INSERT_VECTOR_ELT(VECTOR, VAL, IDX) - Returns VECTOR with the element at IDX replaced with VAL.
@ TokenFactor
TokenFactor - This node takes multiple tokens as input and produces a single token result.
@ ATOMIC_SWAP
Val, OUTCHAIN = ATOMIC_SWAP(INCHAIN, ptr, amt) Val, OUTCHAIN = ATOMIC_LOAD_[OpName](INCHAIN,...
@ CTTZ_ZERO_POISON
Bit counting operators with a poisoned result for zero inputs.
@ FFREXP
FFREXP - frexp, extract fractional and exponent component of a floating-point value.
@ VECTOR_COMPRESS
VECTOR_COMPRESS(Vec, Mask, Passthru) consecutively place vector elements based on mask e....
@ ZERO_EXTEND_VECTOR_INREG
ZERO_EXTEND_VECTOR_INREG(Vector) - This operator represents an in-register zero-extension of the low ...
@ EXPERIMENTAL_VECTOR_HISTOGRAM
Experimental vector histogram intrinsic Operands: Input Chain, Inc, Mask, Base, Index,...
@ FP_TO_SINT_SAT
FP_TO_[US]INT_SAT - Convert floating point value in operand 0 to a signed or unsigned scalar integer ...
@ TRUNCATE
TRUNCATE - Completely drop the high bits.
@ VAARG
VAARG - VAARG has four operands: an input chain, a pointer, a SRCVALUE, and the alignment.
@ BRCOND
BRCOND - Conditional branch.
@ CONVERT_TO_ARBITRARY_FP
CONVERT_TO_ARBITRARY_FP - Converts a native FP value to an arbitrary floating-point format,...
@ SHL_PARTS
SHL_PARTS/SRA_PARTS/SRL_PARTS - These operators are used for expanded integer shift operations.
@ AssertSext
AssertSext, AssertZext - These nodes record if a register contains a value that has already been zero...
@ SADDSAT
RESULT = [US]ADDSAT(LHS, RHS) - Perform saturation addition on 2 integers with the same bit width (W)...
@ VECTOR_REPEAT
VECTOR_REPEAT(FIXED_LENGTH_VECTOR) Repeatedly copies the elements of the source fixed-length vector t...
@ VECTOR_DEINTERLEAVE
VECTOR_DEINTERLEAVE(VEC1, VEC2, ...) - Returns N vectors from N input vectors, where N is the factor ...
@ ABDS
ABDS/ABDU - Absolute difference - Return the absolute difference between two numbers interpreted as s...
@ SADDO_CARRY
Carry-using overflow-aware nodes for multiple precision addition and subtraction.
@ ABS_MIN_POISON
ABS with a poison result for INT_MIN.
@ BUILD_VECTOR
BUILD_VECTOR(ELT0, ELT1, ELT2, ELT3,...) - Return a fixed-width vector with the specified,...
@ LOOP_DEPENDENCE_WAR_MASK
The llvm.loop.dependence.
bool isNormalStore(const SDNode *N)
Returns true if the specified node is a non-truncating and unindexed store.
bool isTrueWhenEqual(CondCode Cond)
Return true if the specified condition returns true if the two operands to the condition are equal.
bool isUNINDEXEDLoad(const SDNode *N)
Returns true if the specified node is an unindexed load.
bool isSignedIntSetCC(CondCode Code)
Return true if this is a setcc instruction that performs a signed comparison when used with integer o...
bool isUNINDEXEDStore(const SDNode *N)
Returns true if the specified node is an unindexed store.
CondCode
ISD::CondCode enum - These are ordered carefully to make the bitfields below work out,...
LoadExtType
LoadExtType enum - This enum defines the three variants of LOADEXT (load with extension).
bool isUnsignedIntSetCC(CondCode Code)
Return true if this is a setcc instruction that performs an unsigned comparison when used with intege...
bool isNormalLoad(const SDNode *N)
Returns true if the specified node is a non-extending and unindexed load.
bool isIntEqualitySetCC(CondCode Code)
Return true if this is a setcc instruction that performs an equality comparison when used with intege...
LLVM_ABI Libcall getSINTTOFP(EVT OpVT, EVT RetVT)
getSINTTOFP - Return the SINTTOFP_*_* value for the given types, or UNKNOWN_LIBCALL if there is none.
LLVM_ABI Libcall getUREM(EVT VT)
LLVM_ABI Libcall getSHL(EVT VT)
LLVM_ABI Libcall getSYNC(unsigned Opc, MVT VT)
Return the SYNC_FETCH_AND_* value for the given opcode and type, or UNKNOWN_LIBCALL if there is none.
LLVM_ABI Libcall getUINTTOFP(EVT OpVT, EVT RetVT)
getUINTTOFP - Return the UINTTOFP_*_* value for the given types, or UNKNOWN_LIBCALL if there is none.
LLVM_ABI Libcall getSDIV(EVT VT)
LLVM_ABI Libcall getSRL(EVT VT)
LLVM_ABI Libcall getSRA(EVT VT)
LLVM_ABI Libcall getUDIV(EVT VT)
LLVM_ABI Libcall getFPTOUINT(EVT OpVT, EVT RetVT)
getFPTOUINT - Return the FPTOUINT_*_* value for the given types, or UNKNOWN_LIBCALL if there is none.
LLVM_ABI Libcall getFPTOSINT(EVT OpVT, EVT RetVT)
getFPTOSINT - Return the FPTOSINT_*_* value for the given types, or UNKNOWN_LIBCALL if there is none.
LLVM_ABI Libcall getOUTLINE_ATOMIC(unsigned Opc, AtomicOrdering Order, MVT VT)
Return the outline atomics value for the given opcode, atomic ordering and type, or UNKNOWN_LIBCALL i...
LLVM_ABI Libcall getSREM(EVT VT)
LLVM_ABI Libcall getMUL(EVT VT)
LLVM_ABI Libcall getCTPOP(EVT VT)
LLVM_ABI Libcall getMULO(EVT VT)
NodeAddr< NodeBase * > Node
NodeAddr< FuncNode * > Func
Type * getValueType(Value *V, bool ReVec, bool LookThroughCmp)
Returns the "element type" of the given value/instruction V.
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI bool isNullConstant(SDValue V)
Returns true if V is a constant integer zero.
@ Known
Known to have no common set bits.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
constexpr T alignDown(U Value, V Align, W Skew=0)
Returns the largest unsigned integer less than or equal to Value and is Skew mod Align.
unsigned Log2_32(uint32_t Value)
Return the floor log base 2 of the specified value, -1 if the value is zero.
constexpr bool isPowerOf2_32(uint32_t Value)
Return true if the argument is a power of two > 0.
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
@ Success
The lock was released successfully.
AtomicOrdering
Atomic ordering for LLVM's memory model.
@ Or
Bitwise or logical OR of integers.
@ Mul
Product of integers.
@ Xor
Bitwise or logical XOR of integers.
DWARFExpression::Operation Op
ArrayRef(const T &OneElt) -> ArrayRef< T >
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
LLVM_ABI bool isOneConstant(SDValue V)
Returns true if V is a constant integer one.
Align commonAlignment(Align A, uint64_t Offset)
Returns the alignment that satisfies both alignments.
LLVM_ABI bool isAllOnesConstant(SDValue V)
Returns true if V is an integer constant with all bits set.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
TypeSize getStoreSize() const
Return the number of bytes overwritten by a store of the specified value type.
bool isSimple() const
Test if the given EVT is simple (as opposed to being extended).
static EVT getVectorVT(LLVMContext &Context, EVT VT, unsigned NumElements, bool IsScalable=false)
Returns the EVT that represents a vector NumElements in length, where each element is of type VT.
bool bitsLT(EVT VT) const
Return true if this has less bits than VT.
ElementCount getVectorElementCount() const
TypeSize getSizeInBits() const
Return the size of the specified value type in bits.
bool isByteSized() const
Return true if the bit size is a multiple of 8.
unsigned getVectorMinNumElements() const
Given a vector type, return the minimum number of elements it contains.
uint64_t getScalarSizeInBits() const
TypeSize getStoreSizeInBits() const
Return the number of bits overwritten by a store of the specified value type.
EVT changeVectorElementType(LLVMContext &Context, EVT EltVT) const
Return a VT for a vector type whose attributes match ourselves with the exception of the element type...
MVT getSimpleVT() const
Return the SimpleValueType held in the specified simple EVT.
static EVT getIntegerVT(LLVMContext &Context, unsigned BitWidth)
Returns the EVT that represents an integer with the given number of bits.
bool isVector() const
Return true if this is a vector value type.
EVT getScalarType() const
If this is a vector type, return the element type, otherwise return this.
bool bitsGE(EVT VT) const
Return true if this has no less bits than VT.
bool bitsEq(EVT VT) const
Return true if this has the same number of bits as VT.
LLVM_ABI Type * getTypeForEVT(LLVMContext &Context) const
This method returns an LLVM type corresponding to the specified EVT.
bool isScalableVector() const
Return true if this is a vector type where the runtime length is machine dependent.
EVT getVectorElementType() const
Given a vector type, return the type of each element.
EVT changeElementType(LLVMContext &Context, EVT EltVT) const
Return a VT for a type whose attributes match ourselves with the exception of the element type that i...
unsigned getVectorNumElements() const
Given a vector type, return the number of elements it contains.
bool bitsLE(EVT VT) const
Return true if this has no more bits than VT.
EVT getHalfNumVectorElementsVT(LLVMContext &Context) const
static LLVM_ABI MachinePointerInfo getUnknownStack(MachineFunction &MF)
Stack memory without other information.
static LLVM_ABI MachinePointerInfo getFixedStack(MachineFunction &MF, int FI, int64_t Offset=0)
Return a MachinePointerInfo record that refers to the specified FrameIndex.
static StringRef getLibcallImplName(RTLIB::LibcallImpl CallImpl)
Get the libcall routine name for the specified libcall implementation.
MakeLibCallOptions & setTypeListBeforeSoften(ArrayRef< EVT > OpsVT, EVT RetVT)
MakeLibCallOptions & setIsSigned(bool Value=true)