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::SHL: Res = PromoteIntRes_SHL(
N);
break;
105 Res = PromoteIntRes_SIGN_EXTEND_INREG(
N);
break;
106 case ISD::SRA: Res = PromoteIntRes_SRA(
N);
break;
107 case ISD::SRL: Res = PromoteIntRes_SRL(
N);
break;
110 case ISD::UNDEF: Res = PromoteIntRes_UNDEF(
N);
break;
111 case ISD::VAARG: Res = PromoteIntRes_VAARG(
N);
break;
115 Res = PromoteIntRes_EXTRACT_SUBVECTOR(
N);
break;
117 Res = PromoteIntRes_INSERT_SUBVECTOR(
N);
break;
119 Res = PromoteIntRes_VECTOR_REVERSE(
N);
break;
121 Res = PromoteIntRes_VECTOR_SHUFFLE(
N);
break;
124 Res = PromoteIntRes_VECTOR_SPLICE(
N);
127 Res = PromoteIntRes_VECTOR_REPEAT(
N);
131 Res = PromoteIntRes_VECTOR_INTERLEAVE_DEINTERLEAVE(
N);
134 Res = PromoteIntRes_INSERT_VECTOR_ELT(
N);
break;
136 Res = PromoteIntRes_BUILD_VECTOR(
N);
140 Res = PromoteIntRes_ScalarOp(
N);
144 Res = PromoteIntRes_CONCAT_VECTORS(
N);
break;
149 Res = PromoteIntRes_EXTEND_VECTOR_INREG(
N);
break;
152 Res = PromoteIntRes_VECTOR_FIND_LAST_ACTIVE(
N);
156 Res = PromoteIntRes_GET_ACTIVE_LANE_MASK(
N);
159 Res = PromoteIntRes_MASK_BEFOREFIRST(
N);
162 Res = PromoteIntRes_VECTOR_MATCH(
N);
168 Res = PromoteIntRes_PARTIAL_REDUCE_MLA(
N);
182 Res = PromoteIntRes_FP_TO_XINT_SAT(
N);
break;
186 Res = PromoteIntRes_FP_TO_FP16_BF16(
N);
189 Res = PromoteIntRes_CONVERT_TO_ARBITRARY_FP(
N);
193 Res = PromoteIntRes_STRICT_FP_TO_FP16_BF16(
N);
202 case ISD::MUL: Res = PromoteIntRes_SimpleIntBinOp(
N);
break;
212 case ISD::VP_SREM: Res = PromoteIntRes_SExtIntBinOp(
N);
break;
219 case ISD::VP_UREM: Res = PromoteIntRes_ZExtIntBinOp(
N);
break;
223 case ISD::ABDU: Res = PromoteIntRes_SExtOrZExtIntBinOp(
N);
break;
227 Res = PromoteIntRes_ZExtMaskedIntBinOp(
N);
231 Res = PromoteIntRes_SExtMaskedIntBinOp(
N);
235 case ISD::SSUBO: Res = PromoteIntRes_SADDSUBO(
N, ResNo);
break;
237 case ISD::USUBO: Res = PromoteIntRes_UADDSUBO(
N, ResNo);
break;
239 case ISD::UMULO: Res = PromoteIntRes_XMULO(
N, ResNo);
break;
255 Res = PromoteIntRes_ADDSUBSHLSAT(
N);
260 Res = PromoteIntRes_CMP(
N);
275 Res = PromoteIntRes_ABS(
N);
309 Res = PromoteIntRes_VECREDUCE(
N);
312 case ISD::VP_REDUCE_ADD:
313 case ISD::VP_REDUCE_MUL:
314 case ISD::VP_REDUCE_AND:
315 case ISD::VP_REDUCE_OR:
316 case ISD::VP_REDUCE_XOR:
317 case ISD::VP_REDUCE_SMAX:
318 case ISD::VP_REDUCE_SMIN:
319 case ISD::VP_REDUCE_UMAX:
320 case ISD::VP_REDUCE_UMIN:
321 Res = PromoteIntRes_VP_REDUCE(
N);
326 Res = PromoteIntRes_LOOP_DEPENDENCE_MASK(
N);
330 Res = PromoteIntRes_FREEZE(
N);
335 Res = PromoteIntRes_Rotate(
N);
340 Res = PromoteIntRes_FunnelShift(
N);
346 Res = PromoteIntRes_CLMUL(
N);
350 Res = PromoteIntRes_PEXT(
N);
354 Res = PromoteIntRes_PDEP(
N);
359 Res = PromoteIntRes_MULH(
N);
363 Res = PromoteIntRes_IS_FPCLASS(
N);
366 Res = PromoteIntRes_FFREXP(
N);
371 Res = PromoteIntRes_XRINT(
N);
375 Res = PromoteIntRes_PATCHPOINT(
N);
378 Res = PromoteIntRes_READ_REGISTER(
N);
384 SetPromotedInteger(
SDValue(
N, ResNo), Res);
389 SDValue
Op = DisintegrateMERGE_VALUES(
N, ResNo);
390 return GetPromotedInteger(
Op);
393SDValue DAGTypeLegalizer::PromoteIntRes_LOOP_DEPENDENCE_MASK(
SDNode *
N) {
395 EVT NewVT = TLI.getTypeToTransformTo(*DAG.getContext(), VT);
396 return DAG.getNode(
N->getOpcode(), SDLoc(
N), NewVT,
N->ops());
401 SDValue
Op = SExtPromotedInteger(
N->getOperand(0));
403 Op.getValueType(),
Op,
N->getOperand(1));
408 SDValue
Op = ZExtPromotedInteger(
N->getOperand(0));
410 Op.getValueType(),
Op,
N->getOperand(1));
414 EVT ResVT = TLI.getTypeToTransformTo(*DAG.getContext(),
N->getValueType(0));
417 switch (TLI.getExtendForAtomicOps()) {
433 DAG.getAtomicLoad(ExtType, SDLoc(
N),
N->getMemoryVT(), ResVT,
434 N->getChain(),
N->getBasePtr(),
N->getMemOperand());
438 ReplaceValueWith(SDValue(
N, 1), Res.
getValue(1));
444 switch (TLI.getExtendForAtomicRMWArg(
N->getOpcode())) {
446 Op2 = SExtPromotedInteger(Op2);
449 Op2 = ZExtPromotedInteger(Op2);
452 Op2 = GetPromotedInteger(Op2);
457 SDValue Res = DAG.getAtomic(
N->getOpcode(), SDLoc(
N),
459 N->getChain(),
N->getBasePtr(),
460 Op2,
N->getMemOperand());
463 ReplaceValueWith(SDValue(
N, 1), Res.
getValue(1));
471 EVT SVT = getSetCCResultType(
N->getOperand(2).getValueType());
472 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(),
N->getValueType(1));
476 if (!TLI.isTypeLegal(SVT))
479 SDVTList VTs = DAG.getVTList(
N->getValueType(0), SVT, MVT::Other);
480 SDValue Res = DAG.getAtomicCmpSwap(
482 N->getChain(),
N->getBasePtr(),
N->getOperand(2),
N->getOperand(3),
484 ReplaceValueWith(SDValue(
N, 0), Res.
getValue(0));
485 ReplaceValueWith(SDValue(
N, 2), Res.
getValue(2));
486 return DAG.getSExtOrTrunc(Res.
getValue(1), SDLoc(
N), NVT);
492 SDValue Op3 = GetPromotedInteger(
N->getOperand(3));
493 switch (TLI.getExtendForAtomicCmpSwapArg()) {
495 Op2 = SExtPromotedInteger(Op2);
498 Op2 = ZExtPromotedInteger(Op2);
501 Op2 = GetPromotedInteger(Op2);
508 DAG.getVTList(Op2.
getValueType(),
N->getValueType(1), MVT::Other);
509 SDValue Res = DAG.getAtomicCmpSwap(
510 N->getOpcode(), SDLoc(
N),
N->getMemoryVT(), VTs,
N->getChain(),
511 N->getBasePtr(), Op2, Op3,
N->getMemOperand());
513 for (
unsigned i = 1, NumResults =
N->getNumValues(); i < NumResults; ++i)
514 ReplaceValueWith(SDValue(
N, i), Res.
getValue(i));
521 EVT NInVT = TLI.getTypeToTransformTo(*DAG.getContext(), InVT);
522 EVT OutVT =
N->getValueType(0);
523 EVT NOutVT = TLI.getTypeToTransformTo(*DAG.getContext(), OutVT);
526 switch (getTypeAction(InVT)) {
532 return DAG.getNode(
ISD::BITCAST, dl, NOutVT, GetPromotedInteger(InOp));
536 return DAG.getNode(
ISD::ANY_EXTEND, dl, NOutVT, GetSoftenedFloat(InOp));
539 return DAG.getNode(
ISD::ANY_EXTEND, dl, NOutVT, GetSoftPromotedHalf(InOp));
547 BitConvertToInteger(GetScalarizedVector(InOp)));
556 GetSplitVector(
N->getOperand(0),
Lo,
Hi);
557 Lo = BitConvertToInteger(
Lo);
558 Hi = BitConvertToInteger(
Hi);
560 if (DAG.getDataLayout().isBigEndian())
566 JoinIntegers(
Lo,
Hi));
581 if (DAG.getDataLayout().isBigEndian()) {
585 DAG.getShiftAmountConstant(ShiftAmt, NOutVT, dl));
600 if (isTypeLegal(WideOutVT)) {
601 InOp = DAG.getBitcast(WideOutVT, GetWidenedVector(InOp));
603 DAG.getVectorIdxConstant(0, dl));
612 DAG.getDataLayout().isLittleEndian()) {
623 if (isTypeLegal(WideVecVT)) {
625 DAG.getUNDEF(WideVecVT), InOp,
626 DAG.getVectorIdxConstant(0, dl));
634 CreateStackStoreLoad(InOp, OutVT));
638 SDValue
V = GetPromotedInteger(
N->getOperand(0));
640 V.getValueType(), V);
644 SDValue
Op = GetPromotedInteger(
N->getOperand(0));
645 EVT OVT =
N->getValueType(0);
646 EVT NVT =
Op.getValueType();
654 !TLI.isOperationLegalOrCustomOrPromote(
ISD::BSWAP, NVT)) {
655 if (SDValue Res = TLI.expandBSWAP(
N, DAG))
660 SDValue ShAmt = DAG.getShiftAmountConstant(DiffBits, NVT, dl);
666 SDValue
Op = GetPromotedInteger(
N->getOperand(0));
667 EVT OVT =
N->getValueType(0);
668 EVT NVT =
Op.getValueType();
677 if (SDValue Res = TLI.expandBITREVERSE(
N, DAG))
682 SDValue ShAmt = DAG.getShiftAmountConstant(DiffBits, NVT, dl);
691 TLI.getTypeToTransformTo(*DAG.getContext(),
692 N->getValueType(0)), JoinIntegers(
N->getOperand(0),
697 EVT VT =
N->getValueType(0);
704 TLI.getTypeToTransformTo(*DAG.getContext(), VT),
711 EVT OVT =
N->getValueType(0);
712 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), OVT);
718 if (!OVT.
isVector() && TLI.isTypeLegal(NVT) &&
719 !TLI.isOperationLegalOrCustomOrPromote(
ISD::CTLZ, NVT) &&
721 if (SDValue Result = TLI.expandCTLZ(
N, DAG)) {
727 unsigned CtlzOpcode =
N->getOpcode();
730 SDValue ExtractLeadingBits = DAG.getConstant(
733 SDValue
Op = ZExtPromotedInteger(
N->getOperand(0));
737 return DAG.getNode(
ISD::SUB, dl, NVT,
738 DAG.getNode(
N->getOpcode(), dl, NVT,
Op),
743 SDValue
Op = GetPromotedInteger(
N->getOperand(0));
747 DAG.getShiftAmountConstant(SHLAmount,
Op.getValueType(), dl);
749 return DAG.getNode(CtlzOpcode, dl, NVT,
Op);
755 EVT OVT =
N->getValueType(0);
756 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), OVT);
759 SDValue ExtractLeadingBits = DAG.getConstant(
762 SDValue
Op = SExtPromotedInteger(
N->getOperand(0));
768 EVT OVT =
N->getValueType(0);
769 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), OVT);
777 !TLI.isOperationLegalOrCustomOrPromote(
ISD::CTPOP, NVT)) {
778 if (SDValue Result = TLI.expandCTPOP(
N, DAG)) {
785 SDValue
Op = ZExtPromotedInteger(
N->getOperand(0));
786 return DAG.getNode(
N->getOpcode(), SDLoc(
N),
Op.getValueType(),
Op);
790 SDValue
Op = GetPromotedInteger(
N->getOperand(0));
791 EVT OVT =
N->getValueType(0);
792 EVT NVT =
Op.getValueType();
799 if (!OVT.
isVector() && TLI.isTypeLegal(NVT) &&
800 !TLI.isOperationLegalOrCustomOrPromote(
ISD::CTTZ, NVT) &&
804 if (SDValue Result = TLI.expandCTTZ(
N, DAG)) {
810 unsigned NewOpc =
N->getOpcode();
817 Op = DAG.getNode(
ISD::OR, dl, NVT,
Op, DAG.getConstant(TopBit, dl, NVT));
820 return DAG.getNode(NewOpc, dl, NVT,
Op);
823SDValue DAGTypeLegalizer::PromoteIntRes_VP_CttzElements(
SDNode *
N) {
825 EVT NewVT = TLI.getTypeToTransformTo(*DAG.getContext(),
N->getValueType(0));
826 return DAG.getNode(
N->getOpcode(),
DL, NewVT,
N->ops());
829SDValue DAGTypeLegalizer::PromoteIntRes_EXTRACT_VECTOR_ELT(
SDNode *
N) {
831 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(),
N->getValueType(0));
833 SDValue Op0 =
N->getOperand(0);
834 SDValue Op1 =
N->getOperand(1);
838 if (TLI.getTypeAction(*DAG.getContext(), Op0.
getValueType())
840 SDValue
In = GetPromotedInteger(Op0);
844 EVT SVT =
In.getValueType().getScalarType();
847 return DAG.getAnyExtOrTrunc(Ext, dl, NVT);
855 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(),
N->getValueType(0));
857 TLI.getPreferredFPToIntOpcode(
N->getOpcode(),
N->getValueType(0), NVT);
861 if (
N->isStrictFPOpcode()) {
862 Res = DAG.
getNode(NewOpc, dl, {NVT, MVT::Other},
863 {
N->getOperand(0),
N->getOperand(1)});
866 ReplaceValueWith(SDValue(
N, 1), Res.
getValue(1));
868 Res = DAG.
getNode(NewOpc, dl, NVT,
N->getOperand(0));
883 DAG.getValueType(
N->getValueType(0).getScalarType()));
886SDValue DAGTypeLegalizer::PromoteIntRes_FP_TO_XINT_SAT(
SDNode *
N) {
888 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(),
N->getValueType(0));
890 return DAG.getNode(
N->getOpcode(), dl, NVT,
N->getOperand(0),
894SDValue DAGTypeLegalizer::PromoteIntRes_FP_TO_FP16_BF16(
SDNode *
N) {
895 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(),
N->getValueType(0));
898 return DAG.getNode(
N->getOpcode(), dl, NVT,
N->getOperand(0));
903SDValue DAGTypeLegalizer::PromoteIntRes_CONVERT_TO_ARBITRARY_FP(
SDNode *
N) {
904 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(),
N->getValueType(0));
908 N->getOperand(1),
N->getOperand(2),
N->getOperand(3));
911SDValue DAGTypeLegalizer::PromoteIntRes_STRICT_FP_TO_FP16_BF16(
SDNode *
N) {
912 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(),
N->getValueType(0));
915 SDValue Res = DAG.
getNode(
N->getOpcode(), dl, DAG.getVTList(NVT, MVT::Other),
916 N->getOperand(0),
N->getOperand(1));
917 ReplaceValueWith(SDValue(
N, 1), Res.
getValue(1));
922 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(),
N->getValueType(0));
924 return DAG.getNode(
N->getOpcode(), dl, NVT,
N->getOperand(0));
928 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(),
N->getValueType(0));
932 DAG.
getNode(
N->getOpcode(), dl, {NVT, MVT::Other},
N->getOperand(0));
936 ReplaceValueWith(SDValue(
N, 1), Res.
getValue(1));
941 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(),
N->getValueType(0));
944 if (getTypeAction(
N->getOperand(0).getValueType())
946 SDValue Res = GetPromotedInteger(
N->getOperand(0));
955 DAG.getValueType(
N->getOperand(0).getValueType()));
957 return DAG.getZeroExtendInReg(Res, dl,
N->getOperand(0).getValueType());
964 return DAG.getNode(
N->getOpcode(), dl, NVT,
N->getOperand(0));
969 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(),
N->getValueType(0));
973 SDValue Res = DAG.getExtLoad(ExtType, dl, NVT,
N->getChain(),
N->getBasePtr(),
974 N->getMemoryVT(),
N->getMemOperand());
978 ReplaceValueWith(SDValue(
N, 1), Res.
getValue(1));
983 assert(!
N->isIndexed() &&
"Indexed vp_load during type legalization!");
984 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(),
N->getValueType(0));
987 :
N->getExtensionType();
990 DAG.getExtLoadVP(ExtType, dl, NVT,
N->getChain(),
N->getBasePtr(),
991 N->getMask(),
N->getVectorLength(),
N->getMemoryVT(),
992 N->getMemOperand(),
N->isExpandingLoad());
995 ReplaceValueWith(SDValue(
N, 1), Res.
getValue(1));
1000 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(),
N->getValueType(0));
1001 SDValue ExtPassThru = GetPromotedInteger(
N->getPassThru());
1008 SDValue Res = DAG.getMaskedLoad(NVT, dl,
N->getChain(),
N->getBasePtr(),
1009 N->getOffset(),
N->getMask(), ExtPassThru,
1010 N->getMemoryVT(),
N->getMemOperand(),
1011 N->getAddressingMode(), ExtType,
1012 N->isExpandingLoad());
1015 ReplaceValueWith(SDValue(
N, 1), Res.
getValue(1));
1020 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(),
N->getValueType(0));
1021 SDValue ExtPassThru = GetPromotedInteger(
N->getPassThru());
1023 "Gather result type and the passThru argument type should be the same");
1030 SDValue
Ops[] = {
N->getChain(), ExtPassThru,
N->getMask(),
N->getBasePtr(),
1031 N->getIndex(),
N->getScale() };
1032 SDValue Res = DAG.getMaskedGather(DAG.getVTList(NVT, MVT::Other),
1033 N->getMemoryVT(), dl,
Ops,
1034 N->getMemOperand(),
N->getIndexType(),
1038 ReplaceValueWith(SDValue(
N, 1), Res.
getValue(1));
1042SDValue DAGTypeLegalizer::PromoteIntRes_VECTOR_COMPRESS(
SDNode *
N) {
1043 SDValue Vec = GetPromotedInteger(
N->getOperand(0));
1044 SDValue Passthru = GetPromotedInteger(
N->getOperand(2));
1046 N->getOperand(1), Passthru);
1053 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(),
N->getValueType(1));
1054 EVT VT =
N->getValueType(0);
1055 EVT SVT = getSetCCResultType(VT);
1056 SDValue
Ops[3] = {
N->getOperand(0),
N->getOperand(1) };
1057 unsigned NumOps =
N->getNumOperands();
1060 Ops[2] = PromoteTargetBoolean(
N->getOperand(2), VT);
1063 SDValue Res = DAG.
getNode(
N->getOpcode(), dl, DAG.getVTList(VT, SVT),
1068 ReplaceValueWith(SDValue(
N, 0), Res);
1071 return DAG.getBoolExtOrTrunc(Res.
getValue(1), dl, NVT, VT);
1086 unsigned Opcode =
N->getOpcode();
1092 SExtOrZExtPromotedOperands(Op1, Op2);
1098 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), OVT);
1100 if (TLI.isSExtCheaperThanZExt(OVT, NVT)) {
1101 Op1 = SExtPromotedInteger(Op1);
1102 Op2 = SExtPromotedInteger(Op2);
1106 Op1 = ZExtPromotedInteger(Op1);
1107 Op2 = ZExtPromotedInteger(Op2);
1110 SDValue SatMax = DAG.getConstant(MaxVal, dl, NVT);
1111 SDValue
Add = DAG.getNode(
ISD::ADD, dl, NVT, Op1, Op2);
1119 Op1 = GetPromotedInteger(Op1);
1121 Op2 = ZExtPromotedInteger(Op2);
1123 Op1 = SExtPromotedInteger(Op1);
1124 Op2 = SExtPromotedInteger(Op2);
1131 if (IsShift || TLI.isOperationLegal(Opcode, PromotedType)) {
1144 "addition, subtraction or left shift");
1147 unsigned SHLAmount = NewBits - OldBits;
1148 SDValue ShiftAmount =
1149 DAG.getShiftAmountConstant(SHLAmount, PromotedType, dl);
1154 SDValue
Result = DAG.getNode(Opcode, dl, PromotedType, Op1, Op2);
1155 return DAG.getNode(ShiftOp, dl, PromotedType, Result, ShiftAmount);
1161 SDValue SatMin = DAG.getConstant(MinVal, dl, PromotedType);
1162 SDValue SatMax = DAG.getConstant(MaxVal, dl, PromotedType);
1163 SDValue
Result = DAG.getNode(AddOp, dl, PromotedType, Op1, Op2);
1172 SDValue Op1Promoted, Op2Promoted;
1178 Op1Promoted = SExtPromotedInteger(
N->getOperand(0));
1179 Op2Promoted = SExtPromotedInteger(
N->getOperand(1));
1181 Op1Promoted = ZExtPromotedInteger(
N->getOperand(0));
1182 Op2Promoted = ZExtPromotedInteger(
N->getOperand(1));
1184 EVT OldType =
N->getOperand(0).getValueType();
1196 DAG.getShiftAmountConstant(DiffSize, PromotedType, dl));
1197 SDValue
Result = DAG.getNode(
N->getOpcode(), dl, PromotedType, Op1Promoted,
1198 Op2Promoted,
N->getOperand(2));
1200 return DAG.getNode(ShiftOp, dl, PromotedType, Result,
1201 DAG.getShiftAmountConstant(DiffSize, PromotedType, dl));
1203 return DAG.getNode(
N->getOpcode(), dl, PromotedType, Op1Promoted, Op2Promoted,
1208 unsigned SatW,
bool Signed,
1211 EVT VT = V.getValueType();
1238 EVT VT =
LHS.getValueType();
1254 assert(Res &&
"Expanding DIVFIX with wide type failed?");
1260 "Tried to saturate to more than the original type?");
1269 SDValue Op1Promoted, Op2Promoted;
1275 Op1Promoted = SExtPromotedInteger(
N->getOperand(0));
1276 Op2Promoted = SExtPromotedInteger(
N->getOperand(1));
1278 Op1Promoted = ZExtPromotedInteger(
N->getOperand(0));
1279 Op2Promoted = ZExtPromotedInteger(
N->getOperand(1));
1282 unsigned Scale =
N->getConstantOperandVal(2);
1286 if (TLI.isTypeLegal(PromotedType)) {
1288 TLI.getFixedPointOperationAction(
N->getOpcode(), PromotedType, Scale);
1291 N->getValueType(0).getScalarSizeInBits();
1295 DAG.getShiftAmountConstant(Diff, PromotedType, dl));
1296 SDValue Res = DAG.
getNode(
N->getOpcode(), dl, PromotedType, Op1Promoted,
1297 Op2Promoted,
N->getOperand(2));
1300 DAG.getShiftAmountConstant(Diff, PromotedType, dl));
1306 if (SDValue Res = TLI.expandFixedPointDiv(
N->getOpcode(), dl, Op1Promoted,
1307 Op2Promoted, Scale, DAG)) {
1310 N->getValueType(0).getScalarSizeInBits(),
1318 N->getValueType(0).getScalarSizeInBits());
1321SDValue DAGTypeLegalizer::PromoteIntRes_SADDSUBO(
SDNode *
N,
unsigned ResNo) {
1323 return PromoteIntRes_Overflow(
N);
1327 SDValue
LHS = SExtPromotedInteger(
N->getOperand(0));
1328 SDValue
RHS = SExtPromotedInteger(
N->getOperand(1));
1329 EVT OVT =
N->getOperand(0).getValueType();
1330 EVT NVT =
LHS.getValueType();
1340 DAG.getValueType(OVT));
1342 Ofl = DAG.getSetCC(dl,
N->getValueType(1), Ofl, Res,
ISD::SETNE);
1345 ReplaceValueWith(SDValue(
N, 1), Ofl);
1351 EVT PromotedResultTy =
1352 TLI.getTypeToTransformTo(*DAG.getContext(),
N->getValueType(0));
1353 return DAG.
getNode(
N->getOpcode(), SDLoc(
N), PromotedResultTy,
1354 N->getOperand(0),
N->getOperand(1));
1358 SDValue
Mask =
N->getOperand(0);
1360 SDValue
LHS = GetPromotedInteger(
N->getOperand(1));
1361 SDValue
RHS = GetPromotedInteger(
N->getOperand(2));
1363 unsigned Opcode =
N->getOpcode();
1364 if (Opcode == ISD::VP_MERGE)
1365 return DAG.getNode(Opcode, SDLoc(
N),
LHS.getValueType(), Mask,
LHS,
RHS,
1367 return DAG.getNode(Opcode, SDLoc(
N),
LHS.getValueType(), Mask,
LHS,
RHS);
1371 SDValue
LHS = GetPromotedInteger(
N->getOperand(2));
1372 SDValue
RHS = GetPromotedInteger(
N->getOperand(3));
1374 LHS.getValueType(),
N->getOperand(0),
1375 N->getOperand(1),
LHS,
RHS,
N->getOperand(4));
1380 EVT InVT =
N->getOperand(OpNo).getValueType();
1381 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(),
N->getValueType(0));
1383 EVT SVT = getSetCCResultType(InVT);
1390 InVT = TLI.getTypeToTransformTo(*DAG.getContext(), InVT);
1391 SVT = getSetCCResultType(InVT);
1399 assert(SVT.
isVector() ==
N->getOperand(OpNo).getValueType().isVector() &&
1400 "Vector compare must return a vector result!");
1404 if (
N->isStrictFPOpcode()) {
1405 SDVTList VTs = DAG.getVTList({SVT, MVT::Other});
1406 SDValue Opers[] = {
N->getOperand(0),
N->getOperand(1),
1407 N->getOperand(2),
N->getOperand(3)};
1408 SetCC = DAG.
getNode(
N->getOpcode(), dl, VTs, Opers,
N->getFlags());
1411 ReplaceValueWith(SDValue(
N, 1), SetCC.
getValue(1));
1413 SetCC = DAG.
getNode(
N->getOpcode(), dl, SVT,
N->getOperand(0),
1414 N->getOperand(1),
N->getOperand(2),
N->getFlags());
1417 return DAG.getSExtOrTrunc(SetCC, dl, NVT);
1422 SDValue Arg =
N->getOperand(0);
1423 SDValue
Test =
N->getOperand(1);
1424 EVT NResVT = TLI.getTypeToTransformTo(*DAG.getContext(),
N->getValueType(0));
1429 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(),
N->getValueType(1));
1430 EVT VT =
N->getValueType(0);
1434 DAG.
getNode(
N->getOpcode(), dl, DAG.getVTList(VT, NVT),
N->getOperand(0));
1436 ReplaceValueWith(SDValue(
N, 0), Res);
1441 SDValue
LHS = GetPromotedInteger(
N->getOperand(0));
1442 SDValue
RHS =
N->getOperand(1);
1444 RHS = ZExtPromotedInteger(
RHS);
1445 return DAG.getNode(
N->getOpcode(), SDLoc(
N),
LHS.getValueType(),
LHS,
RHS);
1448SDValue DAGTypeLegalizer::PromoteIntRes_SIGN_EXTEND_INREG(
SDNode *
N) {
1449 SDValue
Op = GetPromotedInteger(
N->getOperand(0));
1451 Op.getValueType(),
Op,
N->getOperand(1));
1454SDValue DAGTypeLegalizer::PromoteIntRes_SimpleIntBinOp(
SDNode *
N) {
1458 SDValue
LHS = GetPromotedInteger(
N->getOperand(0));
1459 SDValue
RHS = GetPromotedInteger(
N->getOperand(1));
1460 return DAG.getNode(
N->getOpcode(), SDLoc(
N),
LHS.getValueType(),
LHS,
RHS);
1465 SDValue
LHS = SExtPromotedInteger(
N->getOperand(0));
1466 SDValue
RHS = SExtPromotedInteger(
N->getOperand(1));
1467 if (
N->getNumOperands() == 2)
1468 return DAG.getNode(
N->getOpcode(), SDLoc(
N),
LHS.getValueType(),
LHS,
RHS);
1469 assert(
N->getNumOperands() == 4 &&
"Unexpected number of operands!");
1470 assert((
N->getOpcode() == ISD::VP_SDIV ||
N->getOpcode() == ISD::VP_SREM) &&
1471 "Expected VP opcode");
1472 SDValue
Mask =
N->getOperand(2);
1473 SDValue EVL =
N->getOperand(3);
1474 return DAG.getNode(
N->getOpcode(), SDLoc(
N),
LHS.getValueType(),
LHS,
RHS,
1480 SDValue
LHS = ZExtPromotedInteger(
N->getOperand(0));
1481 SDValue
RHS = ZExtPromotedInteger(
N->getOperand(1));
1482 if (
N->getNumOperands() == 2)
1483 return DAG.getNode(
N->getOpcode(), SDLoc(
N),
LHS.getValueType(),
LHS,
RHS);
1484 assert(
N->getNumOperands() == 4 &&
"Unexpected number of operands!");
1485 assert((
N->getOpcode() == ISD::VP_UDIV ||
N->getOpcode() == ISD::VP_UREM) &&
1486 "Expected VP opcode");
1488 SDValue
Mask =
N->getOperand(2);
1494SDValue DAGTypeLegalizer::PromoteIntRes_ZExtMaskedIntBinOp(
SDNode *
N) {
1495 SDValue
LHS = ZExtPromotedInteger(
N->getOperand(0));
1496 SDValue
RHS = ZExtPromotedInteger(
N->getOperand(1));
1497 SDValue
Mask =
N->getOperand(2);
1498 return DAG.getNode(
N->getOpcode(), SDLoc(
N),
LHS.getValueType(),
LHS,
RHS,
1502SDValue DAGTypeLegalizer::PromoteIntRes_SExtMaskedIntBinOp(
SDNode *
N) {
1503 SDValue
LHS = SExtPromotedInteger(
N->getOperand(0));
1504 SDValue
RHS = SExtPromotedInteger(
N->getOperand(1));
1505 SDValue
Mask =
N->getOperand(2);
1506 return DAG.getNode(
N->getOpcode(), SDLoc(
N),
LHS.getValueType(),
LHS,
RHS,
1510SDValue DAGTypeLegalizer::PromoteIntRes_SExtOrZExtIntBinOp(
SDNode *
N) {
1511 SDValue
LHS =
N->getOperand(0);
1512 SDValue
RHS =
N->getOperand(1);
1516 SExtOrZExtPromotedOperands(
LHS,
RHS);
1518 return DAG.getNode(
N->getOpcode(), SDLoc(
N),
1524 SDValue
LHS = SExtPromotedInteger(
N->getOperand(0));
1525 SDValue
RHS =
N->getOperand(1);
1527 RHS = ZExtPromotedInteger(
RHS);
1528 return DAG.getNode(
N->getOpcode(), SDLoc(
N),
LHS.getValueType(),
LHS,
RHS);
1532 SDValue
RHS =
N->getOperand(1);
1534 SDValue
LHS = ZExtPromotedInteger(
N->getOperand(0));
1536 RHS = ZExtPromotedInteger(
RHS);
1537 return DAG.getNode(
N->getOpcode(), SDLoc(
N),
LHS.getValueType(),
LHS,
RHS);
1542 EVT VT = TLI.getTypeToTransformTo(*DAG.getContext(), OldVT);
1543 SDValue Amt =
N->getOperand(1);
1544 unsigned Opcode =
N->getOpcode();
1555 !TLI.isOperationLegalOrCustom(Opcode, VT) &&
1558 SDValue Op0 = GetPromotedInteger(
N->getOperand(0));
1560 Amt = ZExtPromotedInteger(Amt);
1566 DAG.getConstant(OldBits,
DL, AmtVT));
1567 SDValue HiShift = DAG.getShiftAmountConstant(OldBits, VT,
DL);
1568 SDValue
Hi = DAG.getNode(
ISD::SHL,
DL, VT, Op0, HiShift);
1569 SDValue
Lo = DAG.getZeroExtendInReg(Op0,
DL, OldVT);
1581 SDValue Res = TLI.expandROT(
N,
true , DAG);
1582 ReplaceValueWith(SDValue(
N, 0), Res);
1587 SDValue
Hi = GetPromotedInteger(
N->getOperand(0));
1588 SDValue
Lo = GetPromotedInteger(
N->getOperand(1));
1591 Amt = ZExtPromotedInteger(Amt);
1595 EVT OldVT =
N->getOperand(0).getValueType();
1596 EVT VT =
Lo.getValueType();
1597 unsigned Opcode =
N->getOpcode();
1604 DAG.getConstant(OldBits,
DL, AmtVT));
1612 !TLI.isOperationLegalOrCustom(Opcode, VT)) {
1613 SDValue HiShift = DAG.getShiftAmountConstant(OldBits, VT,
DL);
1615 Lo = DAG.getZeroExtendInReg(
Lo,
DL, OldVT);
1625 DAG.getShiftAmountConstant(NewBits - OldBits, VT,
DL));
1631 DAG.getConstant(NewBits - OldBits,
DL, AmtVT));
1633 return DAG.getNode(Opcode,
DL, VT,
Hi,
Lo, Amt);
1637 unsigned Opcode =
N->getOpcode();
1640 EVT OldVT =
N->getOperand(0).getValueType();
1641 EVT VT = TLI.getTypeToTransformTo(*DAG.getContext(), OldVT);
1646 if (!TLI.isOperationLegalOrCustomOrPromote(
ISD::CLMUL, VT) &&
1648 TLI.isOperationLegalOrCustom(
1649 ISD::CLMUL, TLI.getRegisterType(*DAG.getContext(), VT)))) {
1650 if (SDValue Res = TLI.expandCLMUL(
N, DAG))
1653 SDValue
X = GetPromotedInteger(
N->getOperand(0));
1654 SDValue
Y = GetPromotedInteger(
N->getOperand(1));
1658 SDValue
X = ZExtPromotedInteger(
N->getOperand(0));
1659 SDValue
Y = ZExtPromotedInteger(
N->getOperand(1));
1663 if (NewBits < 2 * OldBits) {
1665 unsigned ShAmt = Opcode ==
ISD::CLMULH ? OldBits : OldBits - 1;
1667 DAG.getShiftAmountConstant(ShAmt, VT,
DL));
1669 ShAmt = Opcode ==
ISD::CLMULH ? NewBits - OldBits : NewBits - OldBits + 1;
1671 DAG.getShiftAmountConstant(ShAmt, VT,
DL));
1676 unsigned ShAmt = Opcode ==
ISD::CLMULH ? OldBits : OldBits - 1;
1678 DAG.getShiftAmountConstant(ShAmt, VT,
DL));
1683 EVT VT = TLI.getTypeToTransformTo(*DAG.getContext(),
N->getValueType(0));
1684 if (!TLI.isOperationLegalOrCustomOrPromote(
ISD::PEXT, VT)) {
1685 if (SDValue Res = TLI.expandPEXT(
N, DAG))
1690 SDValue
X = GetPromotedInteger(
N->getOperand(0));
1691 SDValue
Y = ZExtPromotedInteger(
N->getOperand(1));
1697 EVT VT = TLI.getTypeToTransformTo(*DAG.getContext(),
N->getValueType(0));
1698 if (!TLI.isOperationLegalOrCustomOrPromote(
ISD::PDEP, VT)) {
1699 if (SDValue Res = TLI.expandPDEP(
N, DAG))
1704 SDValue
X = GetPromotedInteger(
N->getOperand(0));
1705 SDValue
Y = GetPromotedInteger(
N->getOperand(1));
1711 EVT VT =
N->getValueType(0);
1712 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), VT);
1719 LHS = SExtPromotedInteger(
N->getOperand(0));
1720 RHS = SExtPromotedInteger(
N->getOperand(1));
1722 LHS = ZExtPromotedInteger(
N->getOperand(0));
1723 RHS = ZExtPromotedInteger(
N->getOperand(1));
1730 DAG.getShiftAmountConstant(BW, NVT, dl));
1734 DAG.getShiftAmountConstant(NBW - BW, NVT, dl));
1735 return DAG.getNode(
N->getOpcode(), dl, NVT,
LHS,
RHS);
1739 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(),
N->getValueType(0));
1751 Res = GetPromotedInteger(InOp);
1758 "Dst and Src must have the same number of elements");
1760 "Promoted vector type must be a power of two");
1763 GetSplitVector(InOp, EOp1, EOp2);
1772 SDValue WideInOp = GetWidenedVector(InOp);
1777 N->getValueType(0).getScalarType(), NumElem);
1778 SDValue WideTrunc = DAG.getNode(
ISD::TRUNCATE, dl, TruncVT, WideInOp);
1786 SDValue ZeroIdx = DAG.getVectorIdxConstant(0, dl);
1795SDValue DAGTypeLegalizer::PromoteIntRes_UADDSUBO(
SDNode *
N,
unsigned ResNo) {
1797 return PromoteIntRes_Overflow(
N);
1801 SDValue
LHS = ZExtPromotedInteger(
N->getOperand(0));
1802 SDValue
RHS = ZExtPromotedInteger(
N->getOperand(1));
1803 EVT OVT =
N->getOperand(0).getValueType();
1804 EVT NVT =
LHS.getValueType();
1813 SDValue Ofl = DAG.getZeroExtendInReg(Res, dl, OVT);
1815 Ofl = DAG.getSetCC(dl,
N->getValueType(1), Ofl, Res,
ISD::SETNE);
1818 ReplaceValueWith(SDValue(
N, 1), Ofl);
1829 return PromoteIntRes_Overflow(
N);
1841 SDValue
LHS = SExtPromotedInteger(
N->getOperand(0));
1842 SDValue
RHS = SExtPromotedInteger(
N->getOperand(1));
1844 EVT ValueVTs[] = {
LHS.getValueType(),
N->getValueType(1)};
1847 SDValue Res = DAG.
getNode(
N->getOpcode(), SDLoc(
N), DAG.getVTList(ValueVTs),
1851 ReplaceValueWith(SDValue(
N, 1), Res.
getValue(1));
1853 return SDValue(Res.
getNode(), 0);
1858 assert(ResNo == 1 &&
"Don't know how to promote other results yet.");
1859 return PromoteIntRes_Overflow(
N);
1863 EVT OVT =
N->getValueType(0);
1864 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), OVT);
1870 !TLI.isOperationLegalOrCustomOrPromote(
ISD::ABS, NVT) &&
1872 !TLI.isOperationLegal(
ISD::SMAX, NVT)) {
1873 if (SDValue Res = TLI.expandABS(
N, DAG))
1877 SDValue Op0 = SExtPromotedInteger(
N->getOperand(0));
1881SDValue DAGTypeLegalizer::PromoteIntRes_XMULO(
SDNode *
N,
unsigned ResNo) {
1884 return PromoteIntRes_Overflow(
N);
1886 SDValue
LHS =
N->getOperand(0),
RHS =
N->getOperand(1);
1888 EVT SmallVT =
LHS.getValueType();
1895 LHS = SExtPromotedInteger(
LHS);
1896 RHS = SExtPromotedInteger(
RHS);
1898 LHS = ZExtPromotedInteger(
LHS);
1899 RHS = ZExtPromotedInteger(
RHS);
1901 SDVTList VTs = DAG.getVTList(
LHS.getValueType(),
N->getValueType(1));
1902 SDValue
Mul = DAG.getNode(
N->getOpcode(),
DL, VTs,
LHS,
RHS);
1913 DAG.getShiftAmountConstant(Shift,
Mul.getValueType(),
DL));
1914 Overflow = DAG.getSetCC(
DL,
N->getValueType(1),
Hi,
1915 DAG.getConstant(0,
DL,
Hi.getValueType()),
1920 Mul, DAG.getValueType(SmallVT));
1927 SDValue(
Mul.getNode(), 1));
1930 ReplaceValueWith(SDValue(
N, 1), Overflow);
1935 return DAG.getUNDEF(TLI.getTypeToTransformTo(*DAG.getContext(),
1936 N->getValueType(0)));
1940 EVT VT = TLI.getTypeToTransformTo(*DAG.getContext(),
N->getValueType(0));
1942 const APInt &MulImm =
N->getConstantOperandAPInt(0);
1949 EVT VT =
N->getValueType(0);
1952 MVT RegVT = TLI.getRegisterType(*DAG.getContext(), VT);
1953 unsigned NumRegs = TLI.getNumRegisters(*DAG.getContext(), VT);
1957 for (
unsigned i = 0; i < NumRegs; ++i) {
1958 Parts[i] = DAG.getVAArg(RegVT, dl, Chain, Ptr,
N->getOperand(2),
1959 N->getConstantOperandVal(3));
1964 if (DAG.getDataLayout().isBigEndian())
1965 std::reverse(Parts.begin(), Parts.end());
1968 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(),
N->getValueType(0));
1970 for (
unsigned i = 1; i < NumRegs; ++i) {
1975 DAG.getShiftAmountConstant(i * RegVT.
getSizeInBits(), NVT, dl));
1981 ReplaceValueWith(SDValue(
N, 1), Chain);
1994bool DAGTypeLegalizer::PromoteIntegerOperand(
SDNode *
N,
unsigned OpNo) {
1996 SDValue Res = SDValue();
1997 if (CustomLowerNode(
N,
N->getOperand(OpNo).getValueType(),
false)) {
2002 switch (
N->getOpcode()) {
2005 dbgs() <<
"PromoteIntegerOperand Op #" << OpNo <<
": ";
2006 N->dump(&DAG);
dbgs() <<
"\n";
2012 Res = PromoteIntOp_ANY_EXTEND_VECTOR_INREG(
N);
2018 case ISD::BR_CC: Res = PromoteIntOp_BR_CC(
N, OpNo);
break;
2019 case ISD::BRCOND: Res = PromoteIntOp_BRCOND(
N, OpNo);
break;
2024 Res = PromoteIntOp_COND_LOOP(
N, OpNo);
2028 Res = PromoteIntOp_FAKE_USE(
N);
2031 Res = PromoteIntOp_INSERT_VECTOR_ELT(
N, OpNo);
2035 Res = PromoteIntOp_ScalarOp(
N);
2038 case ISD::SELECT: Res = PromoteIntOp_SELECT(
N, OpNo);
break;
2040 case ISD::SETCC: Res = PromoteIntOp_SETCC(
N, OpNo);
break;
2058 Res = PromoteIntOp_VECTOR_COMPRESS(
N, OpNo);
2065 Res = PromoteIntOp_CONVERT_FROM_ARBITRARY_FP(
N);
2080 Res = PromoteIntOp_Shift(
N);
2084 case ISD::UCMP: Res = PromoteIntOp_CMP(
N);
break;
2087 case ISD::FSHR: Res = PromoteIntOp_FunnelShift(
N);
break;
2113 case ISD::VP_REDUCE_ADD:
2114 case ISD::VP_REDUCE_MUL:
2115 case ISD::VP_REDUCE_AND:
2116 case ISD::VP_REDUCE_OR:
2117 case ISD::VP_REDUCE_XOR:
2118 case ISD::VP_REDUCE_SMAX:
2119 case ISD::VP_REDUCE_SMIN:
2120 case ISD::VP_REDUCE_UMAX:
2121 case ISD::VP_REDUCE_UMIN:
2122 Res = PromoteIntOp_VP_REDUCE(
N, OpNo);
2127 Res = PromoteIntOp_STACKMAP(
N, OpNo);
2130 Res = PromoteIntOp_PATCHPOINT(
N, OpNo);
2133 Res = PromoteIntOp_WRITE_REGISTER(
N, OpNo);
2135 case ISD::EXPERIMENTAL_VP_STRIDED_LOAD:
2136 case ISD::EXPERIMENTAL_VP_STRIDED_STORE:
2137 Res = PromoteIntOp_VP_STRIDED(
N, OpNo);
2139 case ISD::EXPERIMENTAL_VP_SPLICE:
2140 Res = PromoteIntOp_VP_SPLICE(
N, OpNo);
2143 Res = PromoteIntOp_VECTOR_HISTOGRAM(
N, OpNo);
2148 Res = PromoteIntOp_UnaryBooleanVectorOp(
N, OpNo);
2151 Res = PromoteIntOp_GET_ACTIVE_LANE_MASK(
N);
2154 Res = PromoteIntOp_VECTOR_MATCH(
N, OpNo);
2160 Res = PromoteIntOp_MaskedBinOp(
N, OpNo);
2165 Res = PromoteIntOp_PARTIAL_REDUCE_MLA(
N);
2168 Res = PromoteIntOp_VECTOR_REPEAT(
N);
2172 Res = PromoteIntOp_LOOP_DEPENDENCE_MASK(
N);
2177 if (!Res.
getNode())
return false;
2184 const bool IsStrictFp =
N->isStrictFPOpcode();
2186 N->getNumValues() == (IsStrictFp ? 2 : 1) &&
2187 "Invalid operand expansion");
2191 ReplaceValueWith(SDValue(
N, 0), Res);
2193 ReplaceValueWith(SDValue(
N, 1), SDValue(Res.
getNode(), 1));
2202 SDValue OpL = GetPromotedInteger(
LHS);
2203 SDValue OpR = GetPromotedInteger(
RHS);
2205 if (TLI.isSExtCheaperThanZExt(
LHS.getValueType(), OpL.
getValueType())) {
2209 unsigned OpLEffectiveBits =
2210 DAG.computeKnownBits(OpL).countMaxActiveBits();
2211 unsigned OpREffectiveBits =
2212 DAG.computeKnownBits(OpR).countMaxActiveBits();
2213 if (OpLEffectiveBits <=
LHS.getScalarValueSizeInBits() &&
2214 OpREffectiveBits <=
RHS.getScalarValueSizeInBits()) {
2221 LHS = SExtPromotedInteger(
LHS);
2222 RHS = SExtPromotedInteger(
RHS);
2231 unsigned OpLEffectiveBits = DAG.ComputeMaxSignificantBits(OpL);
2232 unsigned OpREffectiveBits = DAG.ComputeMaxSignificantBits(OpR);
2233 if (OpLEffectiveBits <=
LHS.getScalarValueSizeInBits() &&
2234 OpREffectiveBits <=
RHS.getScalarValueSizeInBits()) {
2241 LHS = ZExtPromotedInteger(
LHS);
2242 RHS = ZExtPromotedInteger(
RHS);
2256 LHS = SExtPromotedInteger(
LHS);
2257 RHS = SExtPromotedInteger(
RHS);
2262 "Unknown integer comparison!");
2264 SExtOrZExtPromotedOperands(
LHS,
RHS);
2268 SDValue
Op = GetPromotedInteger(
N->getOperand(0));
2272SDValue DAGTypeLegalizer::PromoteIntOp_ANY_EXTEND_VECTOR_INREG(
SDNode *
N) {
2273 SDValue
Op = GetPromotedInteger(
N->getOperand(0));
2274 EVT ResVT =
N->getValueType(0);
2275 EVT OpVT =
Op.getValueType();
2278 Op = DAG.getExtractSubvector(SDLoc(
Op), NewVT,
Op, 0);
2283 SDValue Op1 = GetPromotedInteger(
N->getOperand(1));
2284 return DAG.getAtomic(
N->getOpcode(), SDLoc(
N),
N->getMemoryVT(),
2285 N->getChain(), Op1,
N->getBasePtr(),
N->getMemOperand());
2289 EVT OutVT =
N->getValueType(0);
2292 EVT NInVT = TLI.getTypeToTransformTo(*DAG.getContext(), InVT);
2295 switch (getTypeAction(InVT)) {
2299 DAG.getDataLayout().isLittleEndian()) {
2309 if (isTypeLegal(WideVecVT)) {
2310 SDValue Promoted = GetPromotedInteger(InOp);
2311 SDValue Cast = DAG.getNode(
ISD::BITCAST, dl, WideVecVT, Promoted);
2313 DAG.getVectorIdxConstant(0, dl));
2326 return CreateStackStoreLoad(InOp, OutVT);
2329SDValue DAGTypeLegalizer::PromoteIntOp_BR_CC(
SDNode *
N,
unsigned OpNo) {
2330 assert(OpNo == 2 &&
"Don't know how to promote this operand!");
2332 SDValue
LHS =
N->getOperand(2);
2333 SDValue
RHS =
N->getOperand(3);
2338 return SDValue(DAG.UpdateNodeOperands(
N,
N->getOperand(0),
2339 N->getOperand(1),
LHS,
RHS,
N->getOperand(4)),
2343SDValue DAGTypeLegalizer::PromoteIntOp_BRCOND(
SDNode *
N,
unsigned OpNo) {
2344 assert(OpNo == 1 &&
"only know how to promote condition");
2347 SDValue
Cond = PromoteTargetBoolean(
N->getOperand(1), MVT::Other);
2350 return SDValue(DAG.UpdateNodeOperands(
N,
N->getOperand(0),
Cond,
2351 N->getOperand(2)), 0);
2354SDValue DAGTypeLegalizer::PromoteIntOp_COND_LOOP(
SDNode *
N,
unsigned OpNo) {
2355 assert(OpNo == 1 &&
"only know how to promote condition");
2358 SDValue
Cond = PromoteTargetBoolean(
N->getOperand(1), MVT::Other);
2361 return SDValue(DAG.UpdateNodeOperands(
N,
N->getOperand(0),
Cond), 0);
2366 EVT OVT =
N->getOperand(0).getValueType();
2367 SDValue
Lo = ZExtPromotedInteger(
N->getOperand(0));
2368 SDValue
Hi = GetPromotedInteger(
N->getOperand(1));
2369 assert(
Lo.getValueType() ==
N->getValueType(0) &&
"Operand over promoted?");
2374 DAG.getShiftAmountConstant(OVT.
getSizeInBits(),
N->getValueType(0), dl));
2375 return DAG.getNode(
ISD::OR, dl,
N->getValueType(0),
Lo,
Hi);
2384 assert(!((NumElts & 1) && (!TLI.isTypeLegal(VecVT))) &&
2385 "Legal vector of one illegal element?");
2390 assert(
N->getOperand(0).getValueSizeInBits() >=
2391 N->getValueType(0).getScalarSizeInBits() &&
2392 "Type of inserted value narrower than vector element type!");
2395 for (
unsigned i = 0; i < NumElts; ++i)
2396 NewOps.
push_back(GetPromotedInteger(
N->getOperand(i)));
2398 return SDValue(DAG.UpdateNodeOperands(
N, NewOps), 0);
2401SDValue DAGTypeLegalizer::PromoteIntOp_INSERT_VECTOR_ELT(
SDNode *
N,
2408 assert(
N->getOperand(1).getValueSizeInBits() >=
2409 N->getValueType(0).getScalarSizeInBits() &&
2410 "Type of inserted value narrower than vector element type!");
2411 return SDValue(DAG.UpdateNodeOperands(
N,
N->getOperand(0),
2412 GetPromotedInteger(
N->getOperand(1)),
2417 assert(OpNo == 2 &&
"Different operand and result vector types?");
2420 SDValue
Idx = DAG.getZExtOrTrunc(
N->getOperand(2), SDLoc(
N),
2421 TLI.getVectorIdxTy(DAG.getDataLayout()));
2422 return SDValue(DAG.UpdateNodeOperands(
N,
N->getOperand(0),
2423 N->getOperand(1), Idx), 0);
2427 SDValue
Op = GetPromotedInteger(
N->getOperand(0));
2431 return SDValue(DAG.UpdateNodeOperands(
N,
Op), 0);
2434SDValue DAGTypeLegalizer::PromoteIntOp_SELECT(
SDNode *
N,
unsigned OpNo) {
2435 assert(OpNo == 0 &&
"Only know how to promote the condition!");
2436 SDValue
Cond =
N->getOperand(0);
2437 EVT OpTy =
N->getOperand(1).getValueType();
2440 if (SDValue Res = WidenVSELECTMask(
N))
2441 return DAG.getNode(
N->getOpcode(), SDLoc(
N),
N->getValueType(0),
2442 Res,
N->getOperand(1),
N->getOperand(2));
2446 Cond = PromoteTargetBoolean(
Cond, OpVT);
2448 return SDValue(DAG.UpdateNodeOperands(
N,
Cond,
N->getOperand(1),
2449 N->getOperand(2)), 0);
2452SDValue DAGTypeLegalizer::PromoteIntOp_SELECT_CC(
SDNode *
N,
unsigned OpNo) {
2453 assert(OpNo == 0 &&
"Don't know how to promote this operand!");
2455 SDValue
LHS =
N->getOperand(0);
2456 SDValue
RHS =
N->getOperand(1);
2460 return SDValue(DAG.UpdateNodeOperands(
N,
LHS,
RHS,
N->getOperand(2),
2461 N->getOperand(3),
N->getOperand(4)), 0);
2464SDValue DAGTypeLegalizer::PromoteIntOp_SETCC(
SDNode *
N,
unsigned OpNo) {
2465 assert(OpNo == 0 &&
"Don't know how to promote this operand!");
2467 SDValue
LHS =
N->getOperand(0);
2468 SDValue
RHS =
N->getOperand(1);
2472 return SDValue(DAG.UpdateNodeOperands(
N,
LHS,
RHS,
N->getOperand(2)), 0);
2476 return SDValue(DAG.UpdateNodeOperands(
N,
N->getOperand(0),
2477 ZExtPromotedInteger(
N->getOperand(1))), 0);
2481 SDValue
LHS =
N->getOperand(0);
2482 SDValue
RHS =
N->getOperand(1);
2485 LHS = SExtPromotedInteger(
LHS);
2486 RHS = SExtPromotedInteger(
RHS);
2488 SExtOrZExtPromotedOperands(
LHS,
RHS);
2491 return SDValue(DAG.UpdateNodeOperands(
N,
LHS,
RHS), 0);
2495 return SDValue(DAG.UpdateNodeOperands(
N,
N->getOperand(0),
N->getOperand(1),
2496 ZExtPromotedInteger(
N->getOperand(2))), 0);
2500 SDValue
Op = GetPromotedInteger(
N->getOperand(0));
2504 Op, DAG.getValueType(
N->getOperand(0).getValueType()));
2508 return SDValue(DAG.UpdateNodeOperands(
N,
2509 SExtPromotedInteger(
N->getOperand(0))), 0);
2512SDValue DAGTypeLegalizer::PromoteIntOp_STRICT_SINT_TO_FP(
SDNode *
N) {
2513 return SDValue(DAG.UpdateNodeOperands(
N,
N->getOperand(0),
2514 SExtPromotedInteger(
N->getOperand(1))), 0);
2519 SDValue Ch =
N->getChain(), Ptr =
N->getBasePtr();
2522 SDValue Val = GetPromotedInteger(
N->getValue());
2525 return DAG.getTruncStore(Ch, dl, Val, Ptr,
2526 N->getMemoryVT(),
N->getMemOperand());
2532 assert(OpNo == 1 &&
"Unexpected operand for promotion");
2533 assert(!
N->isIndexed() &&
"expecting unindexed vp_store!");
2535 SDValue DataOp = GetPromotedInteger(
N->getValue());
2536 return DAG.getTruncStoreVP(
N->getChain(), SDLoc(
N), DataOp,
N->getBasePtr(),
2537 N->getMask(),
N->getVectorLength(),
2538 N->getMemoryVT(),
N->getMemOperand(),
2539 N->isCompressingStore());
2544 SDValue DataOp =
N->getValue();
2545 SDValue
Mask =
N->getMask();
2550 Mask = PromoteTargetBoolean(Mask, DataVT);
2553 return SDValue(DAG.UpdateNodeOperands(
N, NewOps), 0);
2556 assert(OpNo == 1 &&
"Unexpected operand for promotion");
2557 DataOp = GetPromotedInteger(DataOp);
2559 return DAG.getMaskedStore(
N->getChain(), SDLoc(
N), DataOp,
N->getBasePtr(),
2560 N->getOffset(), Mask,
N->getMemoryVT(),
2561 N->getMemOperand(),
N->getAddressingMode(),
2562 true,
N->isCompressingStore());
2567 assert(OpNo == 3 &&
"Only know how to promote the mask!");
2568 EVT DataVT =
N->getValueType(0);
2569 SDValue
Mask = PromoteTargetBoolean(
N->getOperand(OpNo), DataVT);
2571 NewOps[OpNo] =
Mask;
2572 SDNode *Res = DAG.UpdateNodeOperands(
N, NewOps);
2574 return SDValue(Res, 0);
2577 ReplaceValueWith(SDValue(
N, 0), SDValue(Res, 0));
2578 ReplaceValueWith(SDValue(
N, 1), SDValue(Res, 1));
2588 EVT DataVT =
N->getValueType(0);
2589 NewOps[OpNo] = PromoteTargetBoolean(
N->getOperand(OpNo), DataVT);
2590 }
else if (OpNo == 4) {
2592 if (
N->isIndexSigned())
2594 NewOps[OpNo] = SExtPromotedInteger(
N->getOperand(OpNo));
2596 NewOps[OpNo] = ZExtPromotedInteger(
N->getOperand(OpNo));
2598 NewOps[OpNo] = GetPromotedInteger(
N->getOperand(OpNo));
2600 SDNode *Res = DAG.UpdateNodeOperands(
N, NewOps);
2602 return SDValue(Res, 0);
2605 ReplaceValueWith(SDValue(
N, 0), SDValue(Res, 0));
2606 ReplaceValueWith(SDValue(
N, 1), SDValue(Res, 1));
2612 bool TruncateStore =
N->isTruncatingStore();
2617 EVT DataVT =
N->getValue().getValueType();
2618 NewOps[OpNo] = PromoteTargetBoolean(
N->getOperand(OpNo), DataVT);
2619 }
else if (OpNo == 4) {
2621 if (
N->isIndexSigned())
2623 NewOps[OpNo] = SExtPromotedInteger(
N->getOperand(OpNo));
2625 NewOps[OpNo] = ZExtPromotedInteger(
N->getOperand(OpNo));
2627 NewOps[OpNo] = GetPromotedInteger(
N->getOperand(OpNo));
2628 TruncateStore =
true;
2631 return DAG.getMaskedScatter(DAG.getVTList(MVT::Other),
N->getMemoryVT(),
2632 SDLoc(
N), NewOps,
N->getMemOperand(),
2633 N->getIndexType(), TruncateStore);
2638 assert(OpNo == 1 &&
"Can only promote VECTOR_COMPRESS mask.");
2642 SDValue
Mask = PromoteTargetBoolean(
N->getOperand(1), VT);
2647 SDValue
Op = GetPromotedInteger(
N->getOperand(0));
2652 return SDValue(DAG.UpdateNodeOperands(
N,
2653 ZExtPromotedInteger(
N->getOperand(0))), 0);
2656SDValue DAGTypeLegalizer::PromoteIntOp_CONVERT_FROM_ARBITRARY_FP(
SDNode *
N) {
2657 return SDValue(DAG.UpdateNodeOperands(
N, GetPromotedInteger(
N->getOperand(0)),
2662SDValue DAGTypeLegalizer::PromoteIntOp_STRICT_UINT_TO_FP(
SDNode *
N) {
2663 return SDValue(DAG.UpdateNodeOperands(
N,
N->getOperand(0),
2664 ZExtPromotedInteger(
N->getOperand(1))), 0);
2669 SDValue Src =
N->getOperand(0);
2670 SDValue
Op = GetPromotedInteger(Src);
2671 EVT VT =
N->getValueType(0);
2676 if (
N->getFlags().hasNonNeg() &&
Op.getValueType() == VT &&
2677 TLI.isSExtCheaperThanZExt(Src.getValueType(), VT)) {
2678 unsigned OpEffectiveBits = DAG.ComputeMaxSignificantBits(
Op);
2679 if (OpEffectiveBits <= Src.getScalarValueSizeInBits())
2684 return DAG.getZeroExtendInReg(
Op, dl, Src.getValueType());
2688 SDValue Op2 = ZExtPromotedInteger(
N->getOperand(2));
2690 DAG.UpdateNodeOperands(
N,
N->getOperand(0),
N->getOperand(1), Op2), 0);
2693SDValue DAGTypeLegalizer::PromoteIntOp_FRAMERETURNADDR(
SDNode *
N) {
2695 SDValue
Op = ZExtPromotedInteger(
N->getOperand(0));
2696 return SDValue(DAG.UpdateNodeOperands(
N,
Op), 0);
2701 SDValue Chain = IsStrict ?
N->getOperand(0) : SDValue();
2705 unsigned OpOffset = IsStrict ? 1 : 0;
2709 RTLIB::Libcall LC = IsPowI ? RTLIB::getPOWI(
N->getValueType(0))
2712 RTLIB::LibcallImpl LCImpl = DAG.getLibcalls().getLibcallImpl(LC);
2713 if (LCImpl == RTLIB::Unsupported) {
2719 if (IsPowI &&
N->getValueType(0).isVector())
2720 return DAG.UnrollVectorOp(
N);
2722 NewOps[1 + OpOffset] = SExtPromotedInteger(
N->getOperand(1 + OpOffset));
2723 return SDValue(DAG.UpdateNodeOperands(
N, NewOps), 0);
2735 if (
N->getOperand(1 + OpOffset).getScalarValueSizeInBits() >
2736 DAG.getLibInfo().getIntSize()) {
2737 const Function &Fn = DAG.getMachineFunction().getFunction();
2738 Fn.getContext().diagnose(DiagnosticInfoLegalizationFailure(
2739 Twine(IsPowI ?
"powi" :
"ldexp") +
2740 " exponent does not match sizeof(int)",
2741 Fn, N->getDebugLoc()));
2743 ReplaceValueWith(SDValue(N, 1), Chain);
2744 ReplaceValueWith(SDValue(N, 0), DAG.getPOISON(N->getValueType(0)));
2748 TargetLowering::MakeLibCallOptions CallOptions;
2749 CallOptions.setIsSigned(
true);
2750 SDValue
Ops[2] = {N->getOperand(0 + OpOffset), N->getOperand(1 + OpOffset)};
2751 std::pair<SDValue, SDValue> Tmp = TLI.makeLibCall(
2752 DAG, LCImpl,
N->getValueType(0),
Ops, CallOptions, SDLoc(
N), Chain);
2753 ReplaceValueWith(SDValue(
N, 0), Tmp.first);
2755 ReplaceValueWith(SDValue(
N, 1), Tmp.second);
2760 switch (
N->getOpcode()) {
2768 case ISD::VP_REDUCE_ADD:
2769 case ISD::VP_REDUCE_MUL:
2770 case ISD::VP_REDUCE_AND:
2771 case ISD::VP_REDUCE_OR:
2772 case ISD::VP_REDUCE_XOR:
2776 case ISD::VP_REDUCE_SMAX:
2777 case ISD::VP_REDUCE_SMIN:
2781 case ISD::VP_REDUCE_UMAX:
2782 case ISD::VP_REDUCE_UMIN:
2792 return GetPromotedInteger(V);
2794 return SExtPromotedInteger(V);
2796 return ZExtPromotedInteger(V);
2802 SDValue
Op = PromoteIntOpVectorReduction(
N,
N->getOperand(0));
2804 EVT OrigEltVT =
N->getOperand(0).getValueType().getVectorElementType();
2805 EVT InVT =
Op.getValueType();
2807 EVT ResVT =
N->getValueType(0);
2808 unsigned Opcode =
N->getOpcode();
2825 switch (TLI.getBooleanContents(InVT)) {
2828 Op = ZExtPromotedInteger(
N->getOperand(0));
2831 Op = SExtPromotedInteger(
N->getOperand(0));
2844 switch (TLI.getBooleanContents(InVT)) {
2847 Op = ZExtPromotedInteger(
N->getOperand(0));
2850 Op = SExtPromotedInteger(
N->getOperand(0));
2856 return DAG.getNode(Opcode, SDLoc(
N), ResVT,
Op);
2860 SDValue Reduce = DAG.getNode(Opcode, dl, EltVT,
Op);
2864SDValue DAGTypeLegalizer::PromoteIntOp_VP_REDUCE(
SDNode *
N,
unsigned OpNo) {
2866 SDValue
Op =
N->getOperand(OpNo);
2871 NewOps[2] = PromoteTargetBoolean(
Op,
N->getOperand(1).getValueType());
2872 return SDValue(DAG.UpdateNodeOperands(
N, NewOps), 0);
2875 assert(OpNo == 1 &&
"Unexpected operand for promotion");
2877 Op = PromoteIntOpVectorReduction(
N,
Op);
2881 EVT VT =
N->getValueType(0);
2882 EVT EltVT =
Op.getValueType().getScalarType();
2885 return DAG.getNode(
N->getOpcode(), SDLoc(
N), VT, NewOps);
2892 SDValue Reduce = DAG.
getNode(
N->getOpcode(),
DL, EltVT, NewOps);
2897 SDValue
Op = ZExtPromotedInteger(
N->getOperand(1));
2898 return SDValue(DAG.UpdateNodeOperands(
N,
N->getOperand(0),
Op), 0);
2901SDValue DAGTypeLegalizer::PromoteIntOp_STACKMAP(
SDNode *
N,
unsigned OpNo) {
2904 NewOps[OpNo] = GetPromotedInteger(NewOps[OpNo]);
2905 return SDValue(DAG.UpdateNodeOperands(
N, NewOps), 0);
2908SDValue DAGTypeLegalizer::PromoteIntOp_PATCHPOINT(
SDNode *
N,
unsigned OpNo) {
2911 NewOps[OpNo] = GetPromotedInteger(NewOps[OpNo]);
2912 return SDValue(DAG.UpdateNodeOperands(
N, NewOps), 0);
2917 const Function &Fn = DAG.getMachineFunction().getFunction();
2919 "cannot use llvm.write_register with illegal type", Fn,
2921 return N->getOperand(0);
2924SDValue DAGTypeLegalizer::PromoteIntOp_VP_STRIDED(
SDNode *
N,
unsigned OpNo) {
2925 assert((
N->getOpcode() == ISD::EXPERIMENTAL_VP_STRIDED_LOAD && OpNo == 3) ||
2926 (
N->getOpcode() == ISD::EXPERIMENTAL_VP_STRIDED_STORE && OpNo == 4));
2929 NewOps[OpNo] = SExtPromotedInteger(
N->getOperand(OpNo));
2930 SDNode *Res = DAG.UpdateNodeOperands(
N, NewOps);
2932 return SDValue(Res, 0);
2935 ReplaceValueWith(SDValue(
N, 0), SDValue(Res, 0));
2936 ReplaceValueWith(SDValue(
N, 1), SDValue(Res, 1));
2940SDValue DAGTypeLegalizer::PromoteIntOp_VP_SPLICE(
SDNode *
N,
unsigned OpNo) {
2944 NewOps[OpNo] = SExtPromotedInteger(
N->getOperand(OpNo));
2945 return SDValue(DAG.UpdateNodeOperands(
N, NewOps), 0);
2948 assert((OpNo == 4 || OpNo == 5) &&
"Unexpected operand for promotion");
2950 NewOps[OpNo] = ZExtPromotedInteger(
N->getOperand(OpNo));
2951 return SDValue(DAG.UpdateNodeOperands(
N, NewOps), 0);
2954SDValue DAGTypeLegalizer::PromoteIntOp_VECTOR_HISTOGRAM(
SDNode *
N,
2956 assert(OpNo == 1 &&
"Unexpected operand for promotion");
2958 NewOps[1] = GetPromotedInteger(
N->getOperand(1));
2959 return SDValue(DAG.UpdateNodeOperands(
N, NewOps), 0);
2962SDValue DAGTypeLegalizer::PromoteIntOp_UnaryBooleanVectorOp(
SDNode *
N,
2964 assert(OpNo == 0 &&
"Unexpected operand for promotion");
2965 SDValue
Op =
N->getOperand(0);
2968 if (TLI.getBooleanContents(
Op.getValueType()) ==
2970 NewOp = SExtPromotedInteger(
Op);
2972 NewOp = ZExtPromotedInteger(
Op);
2974 return SDValue(DAG.UpdateNodeOperands(
N, NewOp), 0);
2977SDValue DAGTypeLegalizer::PromoteIntOp_GET_ACTIVE_LANE_MASK(
SDNode *
N) {
2979 NewOps[0] = ZExtPromotedInteger(
N->getOperand(0));
2980 NewOps[1] = ZExtPromotedInteger(
N->getOperand(1));
2981 return SDValue(DAG.UpdateNodeOperands(
N, NewOps), 0);
2984SDValue DAGTypeLegalizer::PromoteIntOp_VECTOR_MATCH(
SDNode *
N,
unsigned OpNo) {
2985 assert(OpNo < 3 &&
"Unexpected operand for promotion");
2987 return TLI.expandVectorMatch(
N, DAG);
2990 NewOps[2] = PromoteTargetBoolean(
N->getOperand(2),
N->getValueType(0));
2991 return SDValue(DAG.UpdateNodeOperands(
N, NewOps), 0);
2994SDValue DAGTypeLegalizer::PromoteIntOp_MaskedBinOp(
SDNode *
N,
unsigned OpNo) {
2997 NewOps[2] = PromoteTargetBoolean(NewOps[2],
N->getValueType(0));
2998 return SDValue(DAG.UpdateNodeOperands(
N, NewOps), 0);
3001SDValue DAGTypeLegalizer::PromoteIntOp_PARTIAL_REDUCE_MLA(
SDNode *
N) {
3003 switch (
N->getOpcode()) {
3005 NewOps[1] = SExtPromotedInteger(
N->getOperand(1));
3006 NewOps[2] = SExtPromotedInteger(
N->getOperand(2));
3009 NewOps[1] = ZExtPromotedInteger(
N->getOperand(1));
3010 NewOps[2] = ZExtPromotedInteger(
N->getOperand(2));
3013 NewOps[1] = SExtPromotedInteger(
N->getOperand(1));
3014 NewOps[2] = ZExtPromotedInteger(
N->getOperand(2));
3019 return SDValue(DAG.UpdateNodeOperands(
N, NewOps), 0);
3022SDValue DAGTypeLegalizer::PromoteIntOp_LOOP_DEPENDENCE_MASK(
SDNode *
N) {
3024 NewOps[0] = ZExtPromotedInteger(
N->getOperand(0));
3025 NewOps[1] = ZExtPromotedInteger(
N->getOperand(1));
3026 NewOps[2] = ZExtPromotedInteger(
N->getOperand(2));
3028 return SDValue(DAG.UpdateNodeOperands(
N, NewOps), 0);
3033 SDValue Src = GetPromotedInteger(
N->getOperand(0));
3034 EVT SrcVT = Src.getValueType();
3035 EVT OrigVT =
N->getValueType(0);
3050void DAGTypeLegalizer::ExpandIntegerResult(
SDNode *
N,
unsigned ResNo) {
3053 Lo =
Hi = SDValue();
3056 if (CustomLowerNode(
N,
N->getValueType(ResNo),
true))
3059 switch (
N->getOpcode()) {
3062 dbgs() <<
"ExpandIntegerResult #" << ResNo <<
": ";
3063 N->dump(&DAG);
dbgs() <<
"\n";
3092 ExpandIntRes_ABS(
N,
Lo,
Hi);
3144 std::pair<SDValue, SDValue> Tmp = ExpandAtomic(
N);
3145 SplitInteger(Tmp.first,
Lo,
Hi);
3146 ReplaceValueWith(SDValue(
N, 1), Tmp.second);
3151 SDVTList VTs = DAG.getVTList(
N->getValueType(0), MVT::Other);
3152 SDValue Tmp = DAG.getAtomicCmpSwap(
3154 N->getOperand(0),
N->getOperand(1),
N->getOperand(2),
N->getOperand(3),
3160 SDValue
Success = DAG.getSetCC(SDLoc(
N),
N->getValueType(1), Tmp,
3163 SplitInteger(Tmp,
Lo,
Hi);
3164 ReplaceValueWith(SDValue(
N, 1),
Success);
3165 ReplaceValueWith(SDValue(
N, 2), Tmp.
getValue(1));
3242 ExpandIntRes_Rotate(
N,
Lo,
Hi);
3247 ExpandIntRes_FunnelShift(
N,
Lo,
Hi);
3253 ExpandIntRes_CLMUL(
N,
Lo,
Hi);
3257 ExpandIntRes_PEXT(
N,
Lo,
Hi);
3261 ExpandIntRes_PDEP(
N,
Lo,
Hi);
3266 ExpandIntRes_MULH(
N,
Lo,
Hi);
3270 ExpandIntRes_VSCALE(
N,
Lo,
Hi);
3274 ExpandIntRes_READ_REGISTER(
N,
Lo,
Hi);
3279 ExpandIntRes_CTTZ_ELTS(
N,
Lo,
Hi);
3285 SetExpandedInteger(SDValue(
N, ResNo),
Lo,
Hi);
3289std::pair <SDValue, SDValue> DAGTypeLegalizer::ExpandAtomic(
SDNode *Node) {
3290 unsigned Opc =
Node->getOpcode();
3296 EVT RetVT =
Node->getValueType(0);
3297 TargetLowering::MakeLibCallOptions CallOptions;
3300 RTLIB::LibcallImpl LCImpl = DAG.getLibcalls().getLibcallImpl(LC);
3301 if (LCImpl != RTLIB::Unsupported) {
3303 Ops.push_back(
Node->getOperand(1));
3306 assert(LC != RTLIB::UNKNOWN_LIBCALL &&
3307 "Unexpected atomic op or value type!");
3309 LCImpl = DAG.getLibcalls().getLibcallImpl(LC);
3311 return TLI.makeLibCall(DAG, LCImpl, RetVT,
Ops, CallOptions, SDLoc(Node),
3312 Node->getOperand(0));
3317void DAGTypeLegalizer::ExpandShiftByConstant(
SDNode *
N,
const APInt &Amt,
3322 GetExpandedInteger(
N->getOperand(0), InL, InH);
3337 if (Amt.
uge(VTBits)) {
3338 Lo =
Hi = DAG.getConstant(0,
DL, NVT);
3339 }
else if (Amt.
ugt(NVTBits)) {
3340 Lo = DAG.getConstant(0,
DL, NVT);
3342 DAG.getShiftAmountConstant(Amt - NVTBits, NVT,
DL));
3343 }
else if (Amt == NVTBits) {
3344 Lo = DAG.getConstant(0,
DL, NVT);
3348 DAG.getShiftAmountConstant(Amt, NVT,
DL));
3350 if (TLI.isOperationLegal(
ISD::FSHL, NVT)) {
3352 DAG.getShiftAmountConstant(Amt, NVT,
DL));
3357 DAG.getShiftAmountConstant(Amt, NVT,
DL)),
3359 DAG.getShiftAmountConstant(-Amt + NVTBits, NVT,
DL)));
3366 if (Amt.
uge(VTBits)) {
3367 Lo =
Hi = DAG.getConstant(0,
DL, NVT);
3368 }
else if (Amt.
ugt(NVTBits)) {
3370 DAG.getShiftAmountConstant(Amt - NVTBits, NVT,
DL));
3371 Hi = DAG.getConstant(0,
DL, NVT);
3372 }
else if (Amt == NVTBits) {
3374 Hi = DAG.getConstant(0,
DL, NVT);
3377 if (TLI.isOperationLegal(
ISD::FSHR, NVT)) {
3379 DAG.getShiftAmountConstant(Amt, NVT,
DL));
3384 DAG.getShiftAmountConstant(Amt, NVT,
DL)),
3386 DAG.getShiftAmountConstant(-Amt + NVTBits, NVT,
DL)));
3389 DAG.getShiftAmountConstant(Amt, NVT,
DL));
3395 if (Amt.
uge(VTBits)) {
3397 DAG.getShiftAmountConstant(NVTBits - 1, NVT,
DL));
3398 }
else if (Amt.
ugt(NVTBits)) {
3400 DAG.getShiftAmountConstant(Amt - NVTBits, NVT,
DL));
3402 DAG.getShiftAmountConstant(NVTBits - 1, NVT,
DL));
3403 }
else if (Amt == NVTBits) {
3406 DAG.getShiftAmountConstant(NVTBits - 1, NVT,
DL));
3409 if (TLI.isOperationLegal(
ISD::FSHR, NVT)) {
3411 DAG.getShiftAmountConstant(Amt, NVT,
DL));
3416 DAG.getShiftAmountConstant(Amt, NVT,
DL)),
3418 DAG.getShiftAmountConstant(-Amt + NVTBits, NVT,
DL)));
3421 DAG.getShiftAmountConstant(Amt, NVT,
DL));
3429bool DAGTypeLegalizer::
3431 unsigned Opc =
N->getOpcode();
3432 SDValue
In =
N->getOperand(0);
3433 SDValue Amt =
N->getOperand(1);
3434 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(),
N->getValueType(0));
3439 "Expanded integer type size not a power of two!");
3443 KnownBits
Known = DAG.computeKnownBits(Amt);
3446 if (((
Known.Zero |
Known.One) & HighBitMask) == 0)
3451 GetExpandedInteger(In, InL, InH);
3455 if (
Known.One.intersects(HighBitMask)) {
3458 DAG.getConstant(~HighBitMask, dl, ShTy));
3463 Lo = DAG.getConstant(0, dl, NVT);
3464 Hi = DAG.getNode(
ISD::SHL, dl, NVT, InL, Amt);
3467 Hi = DAG.getConstant(0, dl, NVT);
3468 Lo = DAG.getNode(
ISD::SRL, dl, NVT, InH, Amt);
3472 DAG.getConstant(NVTBits - 1, dl, ShTy));
3473 Lo = DAG.getNode(
ISD::SRA, dl, NVT, InH, Amt);
3484 SDValue Amt2 = DAG.getNode(
ISD::XOR, dl, ShTy, Amt,
3485 DAG.getConstant(NVTBits - 1, dl, ShTy));
3501 SDValue Sh1 = DAG.getNode(Op2, dl, NVT, InL, DAG.getConstant(1, dl, ShTy));
3503 SDValue Sh2 = DAG.getNode(Op2, dl, NVT, Sh1, Amt2);
3505 Lo = DAG.getNode(
Opc, dl, NVT, InL, Amt);
3506 Hi = DAG.getNode(
ISD::OR, dl, NVT, DAG.getNode(Op1, dl, NVT, InH, Amt),Sh2);
3518bool DAGTypeLegalizer::
3521 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(),
N->getValueType(0));
3525 "Expanded integer type size not a power of two!");
3530 GetExpandedInteger(
N->getOperand(0), InL, InH);
3532 SDValue NVBitsNode = DAG.getConstant(NVTBits, dl, ShTy);
3533 SDValue AmtExcess = DAG.getNode(
ISD::SUB, dl, ShTy, Amt, NVBitsNode);
3534 SDValue AmtLack = DAG.getNode(
ISD::SUB, dl, ShTy, NVBitsNode, Amt);
3535 SDValue isShort = DAG.getSetCC(dl, getSetCCResultType(ShTy),
3537 SDValue
isZero = DAG.getSetCC(dl, getSetCCResultType(ShTy),
3538 Amt, DAG.getConstant(0, dl, ShTy),
3541 SDValue LoS, HiS, LoL, HiL;
3542 switch (
N->getOpcode()) {
3548 DAG.getNode(
ISD::SHL, dl, NVT, InH, Amt),
3549 DAG.getNode(
ISD::SRL, dl, NVT, InL, AmtLack));
3552 LoL = DAG.getConstant(0, dl, NVT);
3555 Lo = DAG.getSelect(dl, NVT, isShort, LoS, LoL);
3556 Hi = DAG.getSelect(dl, NVT,
isZero, InH,
3557 DAG.getSelect(dl, NVT, isShort, HiS, HiL));
3563 DAG.getNode(
ISD::SRL, dl, NVT, InL, Amt),
3566 DAG.getNode(
ISD::SHL, dl, NVT, InH, AmtLack));
3569 HiL = DAG.getConstant(0, dl, NVT);
3572 Lo = DAG.getSelect(dl, NVT,
isZero, InL,
3573 DAG.getSelect(dl, NVT, isShort, LoS, LoL));
3574 Hi = DAG.getSelect(dl, NVT, isShort, HiS, HiL);
3580 DAG.getNode(
ISD::SRL, dl, NVT, InL, Amt),
3581 DAG.getNode(
ISD::SHL, dl, NVT, InH, AmtLack));
3585 DAG.getConstant(NVTBits - 1, dl, ShTy));
3588 Lo = DAG.getSelect(dl, NVT,
isZero, InL,
3589 DAG.getSelect(dl, NVT, isShort, LoS, LoL));
3590 Hi = DAG.getSelect(dl, NVT, isShort, HiS, HiL);
3613 SDValue
LHS =
N->getOperand(0);
3614 SDValue
RHS =
N->getOperand(1);
3615 EVT NewVT = getSetCCResultType(
LHS.getValueType());
3620 Res = DAG.getBoolExtOrTrunc(Res,
DL,
N->getValueType(0), NewVT);
3621 SplitInteger(Res,
Lo,
Hi);
3624void DAGTypeLegalizer::ExpandIntRes_MINMAX(
SDNode *
N,
3628 SDValue
LHS =
N->getOperand(0);
3629 SDValue
RHS =
N->getOperand(1);
3633 unsigned NumBits =
N->getValueType(0).getScalarSizeInBits();
3634 unsigned NumHalfBits = NumBits / 2;
3635 if (DAG.ComputeNumSignBits(
LHS) > NumHalfBits &&
3636 DAG.ComputeNumSignBits(
RHS) > NumHalfBits) {
3637 SDValue LHSL, LHSH, RHSL, RHSH;
3638 GetExpandedInteger(
LHS, LHSL, LHSH);
3639 GetExpandedInteger(
RHS, RHSL, RHSH);
3642 Lo = DAG.getNode(
N->getOpcode(),
DL, NVT, LHSL, RHSL);
3644 DAG.getShiftAmountConstant(NumHalfBits - 1, NVT,
DL));
3652 SDValue LHSL, LHSH, RHSL, RHSH;
3653 GetExpandedInteger(
LHS, LHSL, LHSH);
3654 GetExpandedInteger(
RHS, RHSL, RHSH);
3656 EVT CCT = getSetCCResultType(NVT);
3659 DAG.getSetCC(
DL, CCT, LHSH, DAG.getConstant(0,
DL, NVT),
ISD::SETLT);
3661 Lo = DAG.getSelect(
DL, NVT, HiNeg, LHSL, DAG.getAllOnesConstant(
DL, NVT));
3663 Lo = DAG.getSelect(
DL, NVT, HiNeg, DAG.getConstant(0,
DL, NVT), LHSL);
3665 Hi = DAG.getNode(
N->getOpcode(),
DL, NVT, {LHSH, RHSH});
3669 const APInt *RHSVal =
nullptr;
3671 RHSVal = &RHSConst->getAPIntValue();
3678 SDValue LHSL, LHSH, RHSL, RHSH;
3679 GetExpandedInteger(
LHS, LHSL, LHSH);
3680 GetExpandedInteger(
RHS, RHSL, RHSH);
3682 EVT CCT = getSetCCResultType(NVT);
3688 Hi = DAG.getNode(
N->getOpcode(),
DL, NVT, {LHSH, RHSH});
3691 SDValue IsHiLeft = DAG.getSetCC(
DL, CCT, LHSH, RHSH, CondC);
3692 SDValue IsHiEq = DAG.getSetCC(
DL, CCT, LHSH, RHSH,
ISD::SETEQ);
3695 SDValue LoCmp = DAG.getSelect(
DL, NVT, IsHiLeft, LHSL, RHSL);
3698 SDValue LoMinMax = DAG.getNode(LoOpc,
DL, NVT, {LHSL, RHSL});
3700 Lo = DAG.getSelect(
DL, NVT, IsHiEq, LoMinMax, LoCmp);
3707 switch (
N->getOpcode()) {
3734 EVT VT =
N->getValueType(0);
3735 EVT CCT = getSetCCResultType(VT);
3738 SplitInteger(Result,
Lo,
Hi);
3742 SDValue ExpandedCMP = TLI.expandCMP(
N, DAG);
3743 SplitInteger(ExpandedCMP,
Lo,
Hi);
3746void DAGTypeLegalizer::ExpandIntRes_ADDSUB(
SDNode *
N,
3750 SDValue LHSL, LHSH, RHSL, RHSH;
3751 GetExpandedInteger(
N->getOperand(0), LHSL, LHSH);
3752 GetExpandedInteger(
N->getOperand(1), RHSL, RHSH);
3755 SDValue LoOps[2] = { LHSL, RHSL };
3756 SDValue HiOps[3] = { LHSH, RHSH };
3758 bool HasOpCarry = TLI.isOperationLegalOrCustom(
3760 TLI.getTypeToExpandTo(*DAG.getContext(), NVT));
3762 SDVTList VTList = DAG.getVTList(NVT, getSetCCResultType(NVT));
3766 Hi = DAG.computeKnownBits(HiOps[2]).isZero()
3772 Hi = DAG.computeKnownBits(HiOps[2]).isZero()
3785 TLI.isOperationLegalOrCustom(
N->getOpcode() ==
ISD::ADD ?
3787 TLI.getTypeToExpandTo(*DAG.getContext(), NVT));
3790 SDVTList VTList = DAG.getVTList(NVT, MVT::Glue);
3804 TLI.isOperationLegalOrCustom(
N->getOpcode() ==
ISD::ADD ?
3806 TLI.getTypeToExpandTo(*DAG.getContext(), NVT));
3810 EVT OvfVT = getSetCCResultType(NVT);
3811 SDVTList VTList = DAG.getVTList(NVT, OvfVT);
3822 SDValue OVF =
Lo.getValue(1);
3826 OVF = DAG.
getNode(
ISD::AND, dl, OvfVT, DAG.getConstant(1, dl, OvfVT), OVF);
3829 OVF = DAG.getZExtOrTrunc(OVF, dl, NVT);
3833 OVF = DAG.getSExtOrTrunc(OVF, dl, NVT);
3845 Cmp = DAG.getSetCC(dl, getSetCCResultType(NVT),
Lo,
3849 Cmp = DAG.getSetCC(dl, getSetCCResultType(NVT), LoOps[0],
3852 Cmp = DAG.getSetCC(dl, getSetCCResultType(NVT), LoOps[0],
3855 Cmp = DAG.getSetCC(dl, getSetCCResultType(NVT),
Lo, LoOps[0],
3860 Carry = DAG.getZExtOrTrunc(Cmp, dl, NVT);
3862 Carry = DAG.getSelect(dl, NVT, Cmp, DAG.getConstant(1, dl, NVT),
3863 DAG.getConstant(0, dl, NVT));
3866 Hi = DAG.getNode(
ISD::SUB, dl, NVT, HiOps[0], Carry);
3875 DAG.getSetCC(dl, getSetCCResultType(LoOps[0].
getValueType()),
3880 Borrow = DAG.getZExtOrTrunc(Cmp, dl, NVT);
3882 Borrow = DAG.getSelect(dl, NVT, Cmp, DAG.getConstant(1, dl, NVT),
3883 DAG.getConstant(0, dl, NVT));
3889void DAGTypeLegalizer::ExpandIntRes_ADDSUBC(
SDNode *
N,
3892 SDValue LHSL, LHSH, RHSL, RHSH;
3894 GetExpandedInteger(
N->getOperand(0), LHSL, LHSH);
3895 GetExpandedInteger(
N->getOperand(1), RHSL, RHSH);
3896 SDVTList VTList = DAG.getVTList(LHSL.
getValueType(), MVT::Glue);
3897 SDValue LoOps[2] = { LHSL, RHSL };
3898 SDValue HiOps[3] = { LHSH, RHSH };
3912 ReplaceValueWith(SDValue(
N, 1),
Hi.getValue(1));
3915void DAGTypeLegalizer::ExpandIntRes_ADDSUBE(
SDNode *
N,
3918 SDValue LHSL, LHSH, RHSL, RHSH;
3920 GetExpandedInteger(
N->getOperand(0), LHSL, LHSH);
3921 GetExpandedInteger(
N->getOperand(1), RHSL, RHSH);
3922 SDVTList VTList = DAG.getVTList(LHSL.
getValueType(), MVT::Glue);
3923 SDValue LoOps[3] = { LHSL, RHSL,
N->
getOperand(2) };
3924 SDValue HiOps[3] = { LHSH, RHSH };
3926 Lo = DAG.
getNode(
N->getOpcode(), dl, VTList, LoOps);
3928 Hi = DAG.
getNode(
N->getOpcode(), dl, VTList, HiOps);
3932 ReplaceValueWith(SDValue(
N, 1),
Hi.getValue(1));
3935void DAGTypeLegalizer::ExpandIntRes_UADDSUBO(
SDNode *
N,
3937 SDValue
LHS =
N->getOperand(0);
3938 SDValue
RHS =
N->getOperand(1);
3943 unsigned CarryOp, NoCarryOp;
3945 switch(
N->getOpcode()) {
3960 bool HasCarryOp = TLI.isOperationLegalOrCustom(
3961 CarryOp, TLI.getTypeToExpandTo(*DAG.getContext(),
LHS.getValueType()));
3965 SDValue LHSL, LHSH, RHSL, RHSH;
3966 GetExpandedInteger(
LHS, LHSL, LHSH);
3967 GetExpandedInteger(
RHS, RHSL, RHSH);
3968 SDVTList VTList = DAG.getVTList(LHSL.
getValueType(),
N->getValueType(1));
3969 SDValue LoOps[2] = { LHSL, RHSL };
3970 SDValue HiOps[3] = { LHSH, RHSH };
3972 Lo = DAG.
getNode(
N->getOpcode(), dl, VTList, LoOps);
3974 Hi = DAG.
getNode(CarryOp, dl, VTList, HiOps);
3980 SDValue Sum = DAG.getNode(NoCarryOp, dl,
LHS.getValueType(),
LHS,
RHS);
3981 SplitInteger(Sum,
Lo,
Hi);
3987 Ovf = DAG.getSetCC(dl,
N->getValueType(1),
Or,
3988 DAG.getConstant(0, dl,
Lo.getValueType()),
ISD::SETEQ);
3992 DAG.getSetCC(dl,
N->getValueType(1),
LHS,
3997 Ovf = DAG.getSetCC(dl,
N->getValueType(1), Sum,
LHS,
Cond);
4003 ReplaceValueWith(SDValue(
N, 1), Ovf);
4009 SDValue LHSL, LHSH, RHSL, RHSH;
4011 GetExpandedInteger(
N->getOperand(0), LHSL, LHSH);
4012 GetExpandedInteger(
N->getOperand(1), RHSL, RHSH);
4013 SDVTList VTList = DAG.getVTList(LHSL.
getValueType(),
N->getValueType(1));
4014 SDValue LoOps[3] = { LHSL, RHSL,
N->
getOperand(2) };
4015 SDValue HiOps[3] = { LHSH, RHSH, SDValue() };
4017 Lo = DAG.
getNode(
N->getOpcode(), dl, VTList, LoOps);
4019 Hi = DAG.
getNode(
N->getOpcode(), dl, VTList, HiOps);
4023 ReplaceValueWith(SDValue(
N, 1),
Hi.getValue(1));
4026void DAGTypeLegalizer::ExpandIntRes_SADDSUBO_CARRY(
SDNode *
N,
4029 SDValue LHSL, LHSH, RHSL, RHSH;
4031 GetExpandedInteger(
N->getOperand(0), LHSL, LHSH);
4032 GetExpandedInteger(
N->getOperand(1), RHSL, RHSH);
4033 SDVTList VTList = DAG.getVTList(LHSL.
getValueType(),
N->getValueType(1));
4038 Lo = DAG.getNode(CarryOp, dl, VTList, { LHSL, RHSL,
N->
getOperand(2) });
4039 Hi = DAG.getNode(
N->getOpcode(), dl, VTList, { LHSH, RHSH, Lo.getValue(1) });
4043 ReplaceValueWith(SDValue(
N, 1),
Hi.getValue(1));
4046void DAGTypeLegalizer::ExpandIntRes_ANY_EXTEND(
SDNode *
N,
4048 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(),
N->getValueType(0));
4050 SDValue
Op =
N->getOperand(0);
4051 if (
Op.getValueType().bitsLE(NVT)) {
4054 Hi = DAG.getUNDEF(NVT);
4058 assert(getTypeAction(
Op.getValueType()) ==
4060 "Only know how to promote this result!");
4061 SDValue Res = GetPromotedInteger(
Op);
4063 "Operand over promoted?");
4065 SplitInteger(Res,
Lo,
Hi);
4069void DAGTypeLegalizer::ExpandIntRes_AssertSext(
SDNode *
N,
4072 GetExpandedInteger(
N->getOperand(0),
Lo,
Hi);
4073 EVT NVT =
Lo.getValueType();
4078 if (NVTBits < EVTBits) {
4081 EVTBits - NVTBits)));
4086 DAG.getShiftAmountConstant(NVTBits - 1, NVT, dl));
4090void DAGTypeLegalizer::ExpandIntRes_AssertZext(
SDNode *
N,
4093 GetExpandedInteger(
N->getOperand(0),
Lo,
Hi);
4094 EVT NVT =
Lo.getValueType();
4099 if (NVTBits < EVTBits) {
4102 EVTBits - NVTBits)));
4106 Hi = DAG.getConstant(0, dl, NVT);
4110void DAGTypeLegalizer::ExpandIntRes_BITREVERSE(
SDNode *
N,
4113 GetExpandedInteger(
N->getOperand(0),
Hi,
Lo);
4118void DAGTypeLegalizer::ExpandIntRes_BSWAP(
SDNode *
N,
4121 GetExpandedInteger(
N->getOperand(0),
Hi,
Lo);
4130 GetExpandedInteger(
N->getOperand(0),
Lo,
Hi);
4131 EVT NVT =
Lo.getValueType();
4134 Hi = DAG.getConstant(0, dl, NVT);
4137void DAGTypeLegalizer::ExpandIntRes_Constant(
SDNode *
N,
4139 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(),
N->getValueType(0));
4142 const APInt &Cst =
Constant->getAPIntValue();
4143 bool IsTarget =
Constant->isTargetOpcode();
4144 bool IsOpaque =
Constant->isOpaque();
4146 Lo = DAG.getConstant(Cst.
trunc(NBitWidth), dl, NVT, IsTarget, IsOpaque);
4147 Hi = DAG.getConstant(Cst.
lshr(NBitWidth).
trunc(NBitWidth), dl, NVT, IsTarget,
4154 SDValue N0 =
N->getOperand(0);
4155 GetExpandedInteger(N0,
Lo,
Hi);
4156 EVT NVT =
Lo.getValueType();
4161 unsigned NumSignBits = DAG.ComputeNumSignBits(N0);
4166 Lo = DAG.getNode(AbsOpc, dl, NVT,
Lo);
4167 Hi = DAG.getConstant(0, dl, NVT);
4177 bool HasSubCarry = TLI.isOperationLegalOrCustom(
4180 SDValue Sign = DAG.getNode(
4182 DAG.getShiftAmountConstant(NVT.
getSizeInBits() - 1, NVT, dl));
4183 SDVTList VTList = DAG.getVTList(NVT, getSetCCResultType(NVT));
4192 EVT VT =
N->getValueType(0);
4193 SDValue Neg = DAG.getNode(
ISD::SUB, dl, VT,
4194 DAG.getConstant(0, dl, VT), N0);
4195 SDValue NegLo, NegHi;
4196 SplitInteger(Neg, NegLo, NegHi);
4198 SDValue HiIsNeg = DAG.getSetCC(dl, getSetCCResultType(NVT),
Hi,
4200 Lo = DAG.getSelect(dl, NVT, HiIsNeg, NegLo,
Lo);
4201 Hi = DAG.getSelect(dl, NVT, HiIsNeg, NegHi,
Hi);
4204void DAGTypeLegalizer::ExpandIntRes_CTLZ(
SDNode *
N,
4208 GetExpandedInteger(
N->getOperand(0),
Lo,
Hi);
4209 EVT NVT =
Lo.getValueType();
4211 SDValue HiNotZero = DAG.getSetCC(dl, getSetCCResultType(NVT),
Hi,
4214 SDValue LoLZ = DAG.getNode(
N->getOpcode(), dl, NVT,
Lo);
4217 Lo = DAG.getSelect(dl, NVT, HiNotZero, HiLZ,
4218 DAG.getNode(
ISD::ADD, dl, NVT, LoLZ,
4221 Hi = DAG.getConstant(0, dl, NVT);
4229 GetExpandedInteger(
N->getOperand(0),
Lo,
Hi);
4230 EVT NVT =
Lo.getValueType();
4233 SDValue Constant0 = DAG.getConstant(0, dl, NVT);
4234 SDValue ConstantBWM1 = DAG.getConstant(NVTBits - 1, dl, NVT);
4236 SDValue HiCTLS = DAG.getNode(
ISD::CTLS, dl, NVT,
Hi);
4237 SDValue IsAllSignBits = DAG.getSetCC(dl, getSetCCResultType(NVT), HiCTLS,
4239 SDValue IsNegative =
4240 DAG.getSetCC(dl, getSetCCResultType(NVT),
Hi, Constant0,
ISD::SETLT);
4241 SDValue AdjustedLo =
4242 DAG.getSelect(dl, NVT, IsNegative, DAG.getNOT(dl,
Lo, NVT),
Lo);
4243 SDValue LoCLZ = DAG.getNode(
ISD::CTLZ, dl, NVT, AdjustedLo);
4244 Lo = DAG.getSelect(dl, NVT, IsAllSignBits,
4245 DAG.getNode(
ISD::ADD, dl, NVT, LoCLZ, ConstantBWM1),
4247 Hi = DAG.getConstant(0, dl, NVT);
4251 SDValue
Result = TLI.expandABD(
N, DAG);
4252 SplitInteger(Result,
Lo,
Hi);
4256 SDValue
Op =
N->getOperand(0);
4257 EVT VT =
N->getValueType(0);
4262 assert(LC != RTLIB::UNKNOWN_LIBCALL &&
4263 "LibCall explicitly requested, but not available");
4265 if (RTLIB::LibcallImpl LCImpl = DAG.getLibcalls().getLibcallImpl(LC)) {
4266 TargetLowering::MakeLibCallOptions CallOptions;
4270 TLI.makeLibCall(DAG, LCImpl, IntVT,
Op, CallOptions,
DL).first;
4271 SplitInteger(DAG.getSExtOrTrunc(Res,
DL, VT),
Lo,
Hi);
4279 GetExpandedInteger(
Op,
Lo,
Hi);
4280 EVT NVT =
Lo.getValueType();
4283 Hi = DAG.getConstant(0,
DL, NVT);
4286void DAGTypeLegalizer::ExpandIntRes_CTTZ(
SDNode *
N,
4290 GetExpandedInteger(
N->getOperand(0),
Lo,
Hi);
4291 EVT NVT =
Lo.getValueType();
4293 SDValue LoNotZero = DAG.getSetCC(dl, getSetCCResultType(NVT),
Lo,
4297 SDValue HiLZ = DAG.
getNode(
N->getOpcode(), dl, NVT,
Hi);
4299 Lo = DAG.getSelect(dl, NVT, LoNotZero, LoLZ,
4300 DAG.getNode(
ISD::ADD, dl, NVT, HiLZ,
4303 Hi = DAG.getConstant(0, dl, NVT);
4309 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(),
N->getValueType(0));
4316 DAG.getShiftAmountConstant(NBitWidth - 1, NVT, dl));
4320 ReplaceValueWith(SDValue(
N, 1), Chain);
4328 Chain =
Op.getValue(1);
4337 EVT VT =
N->getValueType(0);
4341 bool IsStrict =
N->isStrictFPOpcode();
4342 SDValue Chain = IsStrict ?
N->getOperand(0) : SDValue();
4343 SDValue
Op =
N->getOperand(IsStrict ? 1 : 0);
4347 Op.getValueType() == MVT::bf16) {
4353 EVT OpVT =
Op.getValueType();
4357 assert(LC != RTLIB::UNKNOWN_LIBCALL &&
"Unexpected fp-to-xint conversion!");
4358 TargetLowering::MakeLibCallOptions CallOptions;
4363 std::pair<SDValue, SDValue> Tmp = TLI.makeLibCall(DAG, LC, VT,
Op,
4364 CallOptions, dl, Chain);
4365 SplitInteger(Tmp.first,
Lo,
Hi);
4368 ReplaceValueWith(SDValue(
N, 1), Tmp.second);
4373 SDValue Res = TLI.expandFP_TO_INT_SAT(
N, DAG);
4374 SplitInteger(Res,
Lo,
Hi);
4380 bool IsStrict =
N->isStrictFPOpcode();
4381 SDValue
Op =
N->getOperand(IsStrict ? 1 : 0);
4382 SDValue Chain = IsStrict ?
N->getOperand(0) : SDValue();
4384 EVT VT =
Op.getValueType();
4386 if (VT == MVT::f16) {
4392 RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL;
4395 LC = RTLIB::getLROUND(VT);
4396 assert(LC != RTLIB::UNKNOWN_LIBCALL &&
"Unexpected lround input type!");
4399 LC = RTLIB::getLRINT(VT);
4400 assert(LC != RTLIB::UNKNOWN_LIBCALL &&
"Unexpected lrint input type!");
4403 LC = RTLIB::getLLROUND(VT);
4404 assert(LC != RTLIB::UNKNOWN_LIBCALL &&
"Unexpected llround input type!");
4407 LC = RTLIB::getLLRINT(VT);
4408 assert(LC != RTLIB::UNKNOWN_LIBCALL &&
"Unexpected llrint input type!");
4412 EVT RetVT =
N->getValueType(0);
4414 RTLIB::LibcallImpl LCImpl = DAG.getLibcalls().getLibcallImpl(LC);
4415 if (LCImpl == RTLIB::Unsupported) {
4416 DAG.getContext()->emitError(Twine(
"no libcall available for ") +
4417 N->getOperationName(&DAG));
4418 SDValue
Poison = DAG.getPOISON(
N->getValueType(0));
4419 SplitInteger(Poison,
Lo,
Hi);
4420 if (
N->isStrictFPOpcode())
4421 ReplaceValueWith(SDValue(
N, 1),
N->getOperand(0));
4425 TargetLowering::MakeLibCallOptions CallOptions;
4427 std::pair<SDValue, SDValue> Tmp =
4428 TLI.makeLibCall(DAG, LCImpl, RetVT,
Op, CallOptions, dl, Chain);
4429 SplitInteger(Tmp.first,
Lo,
Hi);
4431 if (
N->isStrictFPOpcode())
4432 ReplaceValueWith(SDValue(
N, 1), Tmp.second);
4435void DAGTypeLegalizer::ExpandIntRes_LOAD(
LoadSDNode *
N,
4437 assert(!
N->isAtomic() &&
"Should have been a ATOMIC_LOAD?");
4440 ExpandRes_NormalLoad(
N,
Lo,
Hi);
4446 EVT VT =
N->getValueType(0);
4447 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), VT);
4448 SDValue Ch =
N->getChain();
4449 SDValue Ptr =
N->getBasePtr();
4452 MMOMetadata
Metadata =
N->getMMOMetadataForSubAccess();
4457 if (
N->getMemoryVT().bitsLE(NVT)) {
4458 EVT MemVT =
N->getMemoryVT();
4460 Lo = DAG.getExtLoad(ExtType, dl, NVT, Ch, Ptr,
N->getPointerInfo(), MemVT,
4469 unsigned LoSize =
Lo.getValueSizeInBits();
4471 DAG.getShiftAmountConstant(LoSize - 1, NVT, dl));
4474 Hi = DAG.getConstant(0, dl, NVT);
4478 Hi = DAG.getUNDEF(NVT);
4480 }
else if (DAG.getDataLayout().isLittleEndian()) {
4482 Lo = DAG.getLoad(NVT, dl, Ch, Ptr,
N->getPointerInfo(),
N->getBaseAlign(),
4485 unsigned ExcessBits =
4492 Hi = DAG.getExtLoad(ExtType, dl, NVT, Ch, Ptr,
4493 N->getPointerInfo().getWithOffset(IncrementSize), NEVT,
4503 EVT MemVT =
N->getMemoryVT();
4506 unsigned ExcessBits = (EBytes - IncrementSize)*8;
4509 Hi = DAG.getExtLoad(ExtType, dl, NVT, Ch, Ptr,
N->getPointerInfo(),
4518 N->getPointerInfo().getWithOffset(IncrementSize),
4532 DAG.getShiftAmountConstant(ExcessBits, NVT, dl)));
4536 DAG.getShiftAmountConstant(
4543 ReplaceValueWith(SDValue(
N, 1), Ch);
4546void DAGTypeLegalizer::ExpandIntRes_Logical(
SDNode *
N,
4549 SDValue LL, LH, RL, RH;
4550 GetExpandedInteger(
N->getOperand(0), LL, LH);
4551 GetExpandedInteger(
N->getOperand(1), RL, RH);
4555 Flags.setDisjoint(
N->getFlags().hasDisjoint());
4557 Lo = DAG.getNode(
N->getOpcode(), dl, LL.
getValueType(), LL, RL, Flags);
4558 Hi = DAG.getNode(
N->getOpcode(), dl, LL.
getValueType(), LH, RH, Flags);
4561void DAGTypeLegalizer::ExpandIntRes_MUL(
SDNode *
N,
4563 EVT VT =
N->getValueType(0);
4564 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), VT);
4567 SDValue LL, LH, RL, RH;
4568 GetExpandedInteger(
N->getOperand(0), LL, LH);
4569 GetExpandedInteger(
N->getOperand(1), RL, RH);
4571 if (TLI.expandMUL(
N,
Lo,
Hi, NVT, DAG,
4578 RTLIB::LibcallImpl LCImpl = DAG.getLibcalls().getLibcallImpl(LC);
4579 if (LCImpl == RTLIB::Unsupported) {
4582 TLI.forceExpandMultiply(DAG, dl,
false,
Lo,
Hi, LL, RL, LH, RH);
4588 SDValue
Ops[2] = {
N->getOperand(0),
N->getOperand(1) };
4589 TargetLowering::MakeLibCallOptions CallOptions;
4591 SplitInteger(TLI.makeLibCall(DAG, LCImpl, VT,
Ops, CallOptions, dl).first,
Lo,
4598 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(),
N->getValueType(0));
4599 SDVTList VTs = DAG.getVTList(NVT, NVT, MVT::Other);
4600 SDValue
R = DAG.getNode(
N->getOpcode(),
DL, VTs,
N->getOperand(0));
4603 ReplaceValueWith(SDValue(
N, 1),
R.getValue(2));
4607 SDValue
Result = TLI.expandAVG(
N, DAG);
4608 SplitInteger(Result,
Lo,
Hi);
4613 SDValue
Result = TLI.expandAddSubSat(
N, DAG);
4614 SplitInteger(Result,
Lo,
Hi);
4619 SDValue
Result = TLI.expandShlSat(
N, DAG);
4620 SplitInteger(Result,
Lo,
Hi);
4631 EVT VT =
N->getValueType(0);
4633 SDValue
LHS =
N->getOperand(0);
4634 SDValue
RHS =
N->getOperand(1);
4635 uint64_t Scale =
N->getConstantOperandVal(2);
4647 EVT BoolVT = getSetCCResultType(VT);
4649 Result = DAG.getNode(MulOp, dl, DAG.getVTList(VT, BoolVT),
LHS,
RHS);
4650 SDValue Product =
Result.getValue(0);
4651 SDValue Overflow =
Result.getValue(1);
4655 SDValue SatMin = DAG.getConstant(MinVal, dl, VT);
4656 SDValue SatMax = DAG.getConstant(MaxVal, dl, VT);
4657 SDValue
Zero = DAG.getConstant(0, dl, VT);
4661 SDValue ProdNeg = DAG.getSetCC(dl, BoolVT,
Xor, Zero,
ISD::SETLT);
4662 Result = DAG.getSelect(dl, VT, ProdNeg, SatMin, SatMax);
4663 Result = DAG.getSelect(dl, VT, Overflow, Result, Product);
4668 SDValue SatMax = DAG.getConstant(MaxVal, dl, VT);
4669 Result = DAG.getSelect(dl, VT, Overflow, SatMax, Product);
4672 SplitInteger(Result,
Lo,
Hi);
4678 assert(Scale <= VTSize &&
"Scale can't be larger than the value type size.");
4680 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), VT);
4681 SDValue LL, LH, RL, RH;
4682 GetExpandedInteger(
LHS, LL, LH);
4683 GetExpandedInteger(
RHS, RL, RH);
4687 if (!TLI.expandMUL_LOHI(LoHiOp, VT, dl,
LHS,
RHS, Result, NVT, DAG,
4693 SDValue LoTmp, HiTmp;
4694 TLI.forceExpandWideMUL(DAG, dl,
Signed,
LHS,
RHS, LoTmp, HiTmp);
4695 SplitInteger(LoTmp, Result[0], Result[1]);
4696 SplitInteger(HiTmp, Result[2], Result[3]);
4698 assert(
Result.size() == 4 &&
"Unexpected number of partlets in the result");
4701 assert((VTSize == NVTSize * 2) &&
"Expected the new value type to be half "
4702 "the size of the current value type");
4724 if (Scale % NVTSize) {
4725 SDValue ShiftAmount = DAG.getShiftAmountConstant(Scale % NVTSize, NVT, dl);
4728 Hi = DAG.getNode(
ISD::FSHR, dl, NVT, Result[Part0 + 2], Result[Part0 + 1],
4740 if (Scale == VTSize)
4755 SDValue ResultHL =
Result[2];
4756 SDValue ResultHH =
Result[3];
4758 SDValue SatMax, SatMin;
4759 SDValue NVTZero = DAG.getConstant(0, dl, NVT);
4760 SDValue NVTNeg1 = DAG.getAllOnesConstant(dl, NVT);
4761 EVT BoolNVT = getSetCCResultType(NVT);
4764 if (Scale < NVTSize) {
4766 SDValue HLAdjusted =
4767 DAG.getNode(
ISD::SRL, dl, NVT, ResultHL,
4768 DAG.getShiftAmountConstant(Scale, NVT, dl));
4769 SDValue Tmp = DAG.getNode(
ISD::OR, dl, NVT, HLAdjusted, ResultHH);
4770 SatMax = DAG.getSetCC(dl, BoolNVT, Tmp, NVTZero,
ISD::SETNE);
4771 }
else if (Scale == NVTSize) {
4773 SatMax = DAG.getSetCC(dl, BoolNVT, ResultHH, NVTZero,
ISD::SETNE);
4774 }
else if (Scale < VTSize) {
4776 SDValue HHAdjusted =
4777 DAG.getNode(
ISD::SRL, dl, NVT, ResultHH,
4778 DAG.getShiftAmountConstant(Scale - NVTSize, NVT, dl));
4779 SatMax = DAG.getSetCC(dl, BoolNVT, HHAdjusted, NVTZero,
ISD::SETNE);
4782 "(and saturation can't happen with Scale==VTSize).");
4784 Hi = DAG.getSelect(dl, NVT, SatMax, NVTNeg1,
Hi);
4785 Lo = DAG.getSelect(dl, NVT, SatMax, NVTNeg1,
Lo);
4789 if (Scale < NVTSize) {
4794 unsigned OverflowBits = VTSize - Scale + 1;
4795 assert(OverflowBits <= VTSize && OverflowBits > NVTSize &&
4796 "Extent of overflow bits must start within HL");
4797 SDValue HLHiMask = DAG.getConstant(
4799 SDValue HLLoMask = DAG.getConstant(
4802 SDValue HHGT0 = DAG.getSetCC(dl, BoolNVT, ResultHH, NVTZero,
ISD::SETGT);
4803 SDValue HHEQ0 = DAG.getSetCC(dl, BoolNVT, ResultHH, NVTZero,
ISD::SETEQ);
4804 SDValue HLUGT = DAG.getSetCC(dl, BoolNVT, ResultHL, HLLoMask,
ISD::SETUGT);
4806 DAG.getNode(
ISD::AND, dl, BoolNVT, HHEQ0, HLUGT));
4808 SDValue HHLT = DAG.getSetCC(dl, BoolNVT, ResultHH, NVTNeg1,
ISD::SETLT);
4809 SDValue HHEQ = DAG.getSetCC(dl, BoolNVT, ResultHH, NVTNeg1,
ISD::SETEQ);
4810 SDValue HLULT = DAG.getSetCC(dl, BoolNVT, ResultHL, HLHiMask,
ISD::SETULT);
4812 DAG.getNode(
ISD::AND, dl, BoolNVT, HHEQ, HLULT));
4813 }
else if (Scale == NVTSize) {
4815 SDValue HHGT0 = DAG.getSetCC(dl, BoolNVT, ResultHH, NVTZero,
ISD::SETGT);
4816 SDValue HHEQ0 = DAG.getSetCC(dl, BoolNVT, ResultHH, NVTZero,
ISD::SETEQ);
4817 SDValue HLNeg = DAG.getSetCC(dl, BoolNVT, ResultHL, NVTZero,
ISD::SETLT);
4819 DAG.getNode(
ISD::AND, dl, BoolNVT, HHEQ0, HLNeg));
4821 SDValue HHLT = DAG.getSetCC(dl, BoolNVT, ResultHH, NVTNeg1,
ISD::SETLT);
4822 SDValue HHEQ = DAG.getSetCC(dl, BoolNVT, ResultHH, NVTNeg1,
ISD::SETEQ);
4823 SDValue HLPos = DAG.getSetCC(dl, BoolNVT, ResultHL, NVTZero,
ISD::SETGE);
4825 DAG.getNode(
ISD::AND, dl, BoolNVT, HHEQ, HLPos));
4826 }
else if (Scale < VTSize) {
4829 unsigned OverflowBits = VTSize - Scale + 1;
4830 SDValue HHHiMask = DAG.getConstant(
4832 SDValue HHLoMask = DAG.getConstant(
4834 SatMax = DAG.getSetCC(dl, BoolNVT, ResultHH, HHLoMask,
ISD::SETGT);
4835 SatMin = DAG.getSetCC(dl, BoolNVT, ResultHH, HHHiMask,
ISD::SETLT);
4842 Hi = DAG.getSelect(dl, NVT, SatMax, DAG.getConstant(MaxHi, dl, NVT),
Hi);
4843 Lo = DAG.getSelect(dl, NVT, SatMax, DAG.getConstant(MaxLo, dl, NVT),
Lo);
4846 Hi = DAG.getSelect(dl, NVT, SatMin, DAG.getConstant(MinHi, dl, NVT),
Hi);
4847 Lo = DAG.getSelect(dl, NVT, SatMin, NVTZero,
Lo);
4854 SDValue Res = TLI.expandFixedPointDiv(
N->getOpcode(), dl,
N->getOperand(0),
4856 N->getConstantOperandVal(2), DAG);
4860 N->getConstantOperandVal(2), TLI, DAG);
4861 SplitInteger(Res,
Lo,
Hi);
4864void DAGTypeLegalizer::ExpandIntRes_SADDSUBO(
SDNode *Node,
4867 "Node has unexpected Opcode");
4868 SDValue
LHS =
Node->getOperand(0);
4869 SDValue
RHS =
Node->getOperand(1);
4877 bool HasCarryOp = TLI.isOperationLegalOrCustom(
4878 CarryOp, TLI.getTypeToExpandTo(*DAG.getContext(),
LHS.getValueType()));
4882 SDValue LHSL, LHSH, RHSL, RHSH;
4883 GetExpandedInteger(
LHS, LHSL, LHSH);
4884 GetExpandedInteger(
RHS, RHSL, RHSH);
4885 SDVTList VTList = DAG.getVTList(LHSL.
getValueType(),
Node->getValueType(1));
4888 Hi = DAG.getNode(CarryOp, dl, VTList, { LHSH, RHSH,
Lo.
getValue(1) });
4897 SplitInteger(Sum,
Lo,
Hi);
4922 EVT VT =
LHS.getValueType();
4925 SignsMatch = DAG.getNOT(dl, SignsMatch, VT);
4929 EVT OType =
Node->getValueType(1);
4930 Ovf = DAG.getSetCC(dl, OType, Ovf, DAG.getConstant(0, dl, VT),
ISD::SETLT);
4934 ReplaceValueWith(SDValue(Node, 1), Ovf);
4937void DAGTypeLegalizer::ExpandIntRes_SDIV(
SDNode *
N,
4939 EVT VT =
N->getValueType(0);
4941 SDValue
Ops[2] = {
N->getOperand(0),
N->getOperand(1) };
4950 assert(LC != RTLIB::UNKNOWN_LIBCALL &&
"Unsupported SDIV!");
4952 TargetLowering::MakeLibCallOptions CallOptions;
4954 SplitInteger(TLI.makeLibCall(DAG, LC, VT,
Ops, CallOptions, dl).first,
Lo,
Hi);
4957void DAGTypeLegalizer::ExpandIntRes_ShiftThroughStack(
SDNode *
N,
SDValue &
Lo,
4960 SDValue Shiftee =
N->getOperand(0);
4962 SDValue ShAmt =
N->getOperand(1);
4967 LoadVT = TLI.getTypeToTransformTo(*DAG.getContext(), LoadVT);
4968 }
while (!TLI.isTypeLegal(LoadVT));
4973 "Shifting unit is not a a power of two!");
4975 const bool IsOneStepShift =
4976 DAG.computeKnownBits(ShAmt).countMinTrailingZeros() >=
4981 if (!IsOneStepShift)
4982 ShAmt = DAG.getFreeze(ShAmt);
4985 assert(VTBitWidth % 8 == 0 &&
"Shifting a not byte multiple value?");
4986 unsigned VTByteWidth = VTBitWidth / 8;
4988 "Shiftee type size is not a power of two!");
4989 unsigned StackSlotByteWidth = 2 * VTByteWidth;
4990 unsigned StackSlotBitWidth = 8 * StackSlotByteWidth;
4995 Align StackAlign = DAG.getReducedAlign(StackSlotVT,
false);
4997 DAG.CreateStackTemporary(StackSlotVT.
getStoreSize(), StackAlign);
4998 EVT PtrTy =
StackPtr.getValueType();
4999 SDValue Ch = DAG.getEntryNode();
5002 DAG.getMachineFunction(),
5008 unsigned WideningOpc =
5010 Init = DAG.
getNode(WideningOpc, dl, StackSlotVT, Shiftee);
5013 SDValue AllZeros = DAG.getConstant(0, dl, VT);
5017 Ch = DAG.getStore(Ch, dl, Init, StackPtr, StackPtrInfo, StackAlign);
5023 Flags.setExact(IsOneStepShift);
5024 SDValue SrlTmp = DAG.getNode(
5026 DAG.getConstant(
Log2_32(ShiftUnitInBits), dl, ShAmtVT), Flags);
5028 DAG.getNode(
ISD::SHL, dl, ShAmtVT, SrlTmp,
5029 DAG.getConstant(
Log2_32(ShiftUnitInBits), dl, ShAmtVT));
5031 SDValue ByteOffset =
5032 DAG.getNode(
ISD::SRL, dl, ShAmtVT, BitOffset,
5037 DAG.getConstant(VTByteWidth - 1, dl, ShAmtVT));
5044 if (DAG.getDataLayout().isBigEndian())
5045 WillIndexUpwards = !WillIndexUpwards;
5047 SDValue AdjStackPtr;
5048 if (WillIndexUpwards) {
5051 AdjStackPtr = DAG.getMemBasePlusOffset(
5052 StackPtr, DAG.getConstant(VTByteWidth, dl, PtrTy), dl);
5053 ByteOffset = DAG.getNegative(ByteOffset, dl, ShAmtVT);
5057 ByteOffset = DAG.getSExtOrTrunc(ByteOffset, dl, PtrTy);
5058 AdjStackPtr = DAG.getMemBasePlusOffset(AdjStackPtr, ByteOffset, dl);
5062 DAG.getLoad(VT, dl, Ch, AdjStackPtr,
5067 if (!IsOneStepShift) {
5069 DAG.getNode(
ISD::AND, dl, ShAmtVT, ShAmt,
5070 DAG.getConstant(ShiftUnitInBits - 1, dl, ShAmtVT));
5071 Res = DAG.
getNode(
N->getOpcode(), dl, VT, Res, ShAmtRem);
5075 SplitInteger(Res,
Lo,
Hi);
5078void DAGTypeLegalizer::ExpandIntRes_Shift(
SDNode *
N,
5080 EVT VT =
N->getValueType(0);
5081 unsigned Opc =
N->getOpcode();
5087 return ExpandShiftByConstant(
N, CN->getAPIntValue(),
Lo,
Hi);
5091 if (ExpandShiftWithKnownAmountBit(
N,
Lo,
Hi))
5108 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), VT);
5110 const bool LegalOrCustom =
5114 unsigned ExpansionFactor = 1;
5116 for (EVT TmpVT = NVT;;) {
5117 EVT NewTMPVT = TLI.getTypeToTransformTo(*DAG.getContext(), TmpVT);
5118 if (NewTMPVT == TmpVT)
5125 TLI.preferredShiftLegalizationStrategy(DAG,
N, ExpansionFactor);
5128 return ExpandIntRes_ShiftThroughStack(
N,
Lo,
Hi);
5130 if (LegalOrCustom &&
5134 GetExpandedInteger(
N->getOperand(0), LHSL, LHSH);
5140 SDValue ShiftOp =
N->getOperand(1);
5141 EVT ShiftTy = TLI.getShiftAmountTy(VT, DAG.getDataLayout());
5143 ShiftOp = DAG.getZExtOrTrunc(ShiftOp, dl, ShiftTy);
5145 SDValue
Ops[] = { LHSL, LHSH, ShiftOp };
5146 Lo = DAG.
getNode(PartsOpc, dl, DAG.getVTList(VT, VT),
Ops);
5147 Hi =
Lo.getValue(1);
5152 RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL;
5166 if (RTLIB::LibcallImpl LibcallImpl = DAG.getLibcalls().getLibcallImpl(LC)) {
5169 SDValue ShAmt = DAG.getZExtOrTrunc(
N->getOperand(1), dl, ShAmtTy);
5170 SDValue
Ops[2] = {
N->getOperand(0), ShAmt};
5171 TargetLowering::MakeLibCallOptions CallOptions;
5174 TLI.makeLibCall(DAG, LibcallImpl, VT,
Ops, CallOptions, dl).first,
Lo,
5179 if (!ExpandShiftWithUnknownAmountBit(
N,
Lo,
Hi))
5183void DAGTypeLegalizer::ExpandIntRes_SIGN_EXTEND(
SDNode *
N,
5185 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(),
N->getValueType(0));
5187 SDValue
Op =
N->getOperand(0);
5188 if (
Op.getValueType().bitsLE(NVT)) {
5194 DAG.getShiftAmountConstant(LoSize - 1, NVT, dl));
5198 assert(getTypeAction(
Op.getValueType()) ==
5200 "Only know how to promote this result!");
5201 SDValue Res = GetPromotedInteger(
Op);
5203 "Operand over promoted?");
5205 SplitInteger(Res,
Lo,
Hi);
5213void DAGTypeLegalizer::
5216 GetExpandedInteger(
N->getOperand(0),
Lo,
Hi);
5219 if (EVT.
bitsLE(
Lo.getValueType())) {
5227 DAG.getShiftAmountConstant(
Hi.getValueSizeInBits() - 1,
5228 Hi.getValueType(), dl));
5239void DAGTypeLegalizer::ExpandIntRes_SREM(
SDNode *
N,
5241 EVT VT =
N->getValueType(0);
5243 SDValue
Ops[2] = {
N->getOperand(0),
N->getOperand(1) };
5252 assert(LC != RTLIB::UNKNOWN_LIBCALL &&
"Unsupported SREM!");
5254 TargetLowering::MakeLibCallOptions CallOptions;
5256 SplitInteger(TLI.makeLibCall(DAG, LC, VT,
Ops, CallOptions, dl).first,
Lo,
Hi);
5259void DAGTypeLegalizer::ExpandIntRes_TRUNCATE(
SDNode *
N,
5261 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(),
N->getValueType(0));
5271void DAGTypeLegalizer::ExpandIntRes_XMULO(
SDNode *
N,
5273 EVT VT =
N->getValueType(0);
5291 SDValue
LHS =
N->getOperand(0),
RHS =
N->getOperand(1);
5292 SDValue LHSHigh, LHSLow, RHSHigh, RHSLow;
5293 GetExpandedInteger(
LHS, LHSLow, LHSHigh);
5294 GetExpandedInteger(
RHS, RHSLow, RHSHigh);
5296 EVT BitVT =
N->getValueType(1);
5297 SDVTList VTHalfWithO = DAG.getVTList(HalfVT, BitVT);
5299 SDValue HalfZero = DAG.getConstant(0, dl, HalfVT);
5301 DAG.getSetCC(dl, BitVT, LHSHigh, HalfZero,
ISD::SETNE),
5302 DAG.getSetCC(dl, BitVT, RHSHigh, HalfZero,
ISD::SETNE));
5304 SDValue One = DAG.getNode(
ISD::UMULO, dl, VTHalfWithO, LHSHigh, RHSLow);
5307 SDValue Two = DAG.getNode(
ISD::UMULO, dl, VTHalfWithO, RHSHigh, LHSLow);
5310 SDValue HighSum = DAG.getNode(
ISD::ADD, dl, HalfVT, One, Two);
5318 SDValue Three = DAG.getNode(
ISD::MUL, dl, VT,
5321 SplitInteger(Three,
Lo,
Hi);
5325 ReplaceValueWith(SDValue(
N, 1), Overflow);
5330 EVT PtrVT = TLI.getPointerTy(DAG.getDataLayout());
5335 RTLIB::LibcallImpl LCImpl = DAG.getLibcalls().getLibcallImpl(LC);
5339 if (LCImpl == RTLIB::Unsupported ||
5341 DAG.getMachineFunction().getName()) {
5343 SDValue MulLo, MulHi;
5344 TLI.forceExpandWideMUL(DAG, dl,
true,
N->getOperand(0),
5345 N->getOperand(1), MulLo, MulHi);
5346 SDValue
SRA = DAG.getNode(
5350 DAG.getSetCC(dl,
N->getValueType(1), MulHi, SRA,
ISD::SETNE);
5351 SplitInteger(MulLo,
Lo,
Hi);
5352 ReplaceValueWith(SDValue(
N, 1), Overflow);
5356 SDValue Temp = DAG.CreateStackTemporary(PtrVT);
5359 DAG.getStore(DAG.getEntryNode(), dl, DAG.getConstant(0, dl, PtrVT), Temp,
5360 MachinePointerInfo());
5363 for (
const SDValue &
Op :
N->op_values()) {
5364 EVT ArgVT =
Op.getValueType();
5366 TargetLowering::ArgListEntry
Entry(
Op, ArgTy);
5367 Entry.IsSExt =
true;
5368 Entry.IsZExt =
false;
5369 Args.push_back(Entry);
5373 TargetLowering::ArgListEntry
Entry(
5375 Entry.IsSExt =
true;
5376 Entry.IsZExt =
false;
5377 Args.push_back(Entry);
5379 SDValue
Func = DAG.getExternalSymbol(LCImpl, PtrVT);
5381 TargetLowering::CallLoweringInfo CLI(DAG);
5384 .setLibCallee(DAG.getLibcalls().getLibcallImplCallingConv(LCImpl), RetTy,
5385 Func, std::move(Args))
5388 std::pair<SDValue, SDValue> CallInfo = TLI.LowerCallTo(CLI);
5390 SplitInteger(CallInfo.first,
Lo,
Hi);
5392 DAG.getLoad(PtrVT, dl, CallInfo.second, Temp, MachinePointerInfo());
5393 SDValue Ofl = DAG.getSetCC(dl,
N->getValueType(1), Temp2,
5394 DAG.getConstant(0, dl, PtrVT),
5397 ReplaceValueWith(SDValue(
N, 1), Ofl);
5400void DAGTypeLegalizer::ExpandIntRes_UDIV(
SDNode *
N,
5402 EVT VT =
N->getValueType(0);
5404 SDValue
Ops[2] = {
N->getOperand(0),
N->getOperand(1) };
5414 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(),
N->getValueType(0));
5416 if (isTypeLegal(NVT)) {
5418 GetExpandedInteger(
N->getOperand(0), InL, InH);
5420 if (TLI.expandDIVREMByConstant(
N, Result, NVT, DAG, InL, InH)) {
5429 assert(LC != RTLIB::UNKNOWN_LIBCALL &&
"Unsupported UDIV!");
5431 TargetLowering::MakeLibCallOptions CallOptions;
5432 SplitInteger(TLI.makeLibCall(DAG, LC, VT,
Ops, CallOptions, dl).first,
Lo,
Hi);
5435void DAGTypeLegalizer::ExpandIntRes_UREM(
SDNode *
N,
5437 EVT VT =
N->getValueType(0);
5439 SDValue
Ops[2] = {
N->getOperand(0),
N->getOperand(1) };
5449 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(),
N->getValueType(0));
5451 if (isTypeLegal(NVT)) {
5453 GetExpandedInteger(
N->getOperand(0), InL, InH);
5455 if (TLI.expandDIVREMByConstant(
N, Result, NVT, DAG, InL, InH)) {
5464 assert(LC != RTLIB::UNKNOWN_LIBCALL &&
"Unsupported UREM!");
5466 TargetLowering::MakeLibCallOptions CallOptions;
5467 SplitInteger(TLI.makeLibCall(DAG, LC, VT,
Ops, CallOptions, dl).first,
Lo,
Hi);
5470void DAGTypeLegalizer::ExpandIntRes_ZERO_EXTEND(
SDNode *
N,
5472 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(),
N->getValueType(0));
5474 SDValue
Op =
N->getOperand(0);
5475 if (
Op.getValueType().bitsLE(NVT)) {
5478 Hi = DAG.getConstant(0, dl, NVT);
5482 assert(getTypeAction(
Op.getValueType()) ==
5484 "Only know how to promote this result!");
5485 SDValue Res = GetPromotedInteger(
Op);
5487 "Operand over promoted?");
5489 SplitInteger(Res,
Lo,
Hi);
5491 Hi = DAG.getZeroExtendInReg(
Hi, dl,
5497void DAGTypeLegalizer::ExpandIntRes_ATOMIC_LOAD(
SDNode *
N,
5501 SDVTList VTs = DAG.getVTList(VT, MVT::i1, MVT::Other);
5502 SDValue
Zero = DAG.getConstant(0, dl, VT);
5503 SDValue
Swap = DAG.getAtomicCmpSwap(
5508 ReplaceValueWith(SDValue(
N, 0),
Swap.getValue(0));
5509 ReplaceValueWith(SDValue(
N, 1),
Swap.getValue(2));
5512void DAGTypeLegalizer::ExpandIntRes_VECREDUCE(
SDNode *
N,
5516 SDValue Res = TLI.expandVecReduce(
N, DAG);
5517 SplitInteger(Res,
Lo,
Hi);
5520void DAGTypeLegalizer::ExpandIntRes_Rotate(
SDNode *
N,
5525 SDValue Res = DAG.
getNode(Opcode,
DL,
N->getValueType(0),
N->getOperand(0),
5526 N->getOperand(0),
N->getOperand(1));
5527 SplitInteger(Res,
Lo,
Hi);
5533 SDValue In1, In2, In3, In4;
5534 GetExpandedInteger(
N->getOperand(0), In3, In4);
5535 GetExpandedInteger(
N->getOperand(1), In1, In2);
5539 unsigned Opc =
N->getOpcode();
5542 EVT ShAmtCCVT = getSetCCResultType(ShAmtVT);
5546 SDValue AndNode = DAG.getNode(
ISD::AND,
DL, ShAmtVT, ShAmt,
5547 DAG.getConstant(HalfVTBits,
DL, ShAmtVT));
5549 DAG.getSetCC(
DL, ShAmtCCVT, AndNode, DAG.getConstant(0,
DL, ShAmtVT),
5553 EVT NewShAmtVT = TLI.getShiftAmountTy(HalfVT, DAG.getDataLayout());
5554 SDValue NewShAmt = DAG.getAnyExtOrTrunc(ShAmt,
DL, NewShAmtVT);
5559 Lo = DAG.getNode(
Opc,
DL, HalfVT, Select2, Select1, NewShAmt);
5560 Hi = DAG.getNode(
Opc,
DL, HalfVT, Select3, Select2, NewShAmt);
5565 SDValue Res = TLI.expandCLMUL(
N, DAG);
5566 return SplitInteger(Res,
Lo,
Hi);
5569 SDValue LL, LH, RL, RH;
5570 GetExpandedInteger(
N->getOperand(0), LL, LH);
5571 GetExpandedInteger(
N->getOperand(1), RL, RH);
5582 SDValue HiLoCross1 = DAG.getNode(
ISD::CLMUL,
DL, HalfVT, LL, RH);
5583 SDValue HiLoCross2 = DAG.getNode(
ISD::CLMUL,
DL, HalfVT, LH, RL);
5584 SDValue HiLoCross = DAG.getNode(
ISD::XOR,
DL, HalfVT, HiLoCross1, HiLoCross2);
5585 Hi = DAG.getNode(
ISD::XOR,
DL, HalfVT, LoH, HiLoCross);
5589 SDValue Res = TLI.expandPEXT(
N, DAG);
5590 SplitInteger(Res,
Lo,
Hi);
5594 SDValue Res = TLI.expandPDEP(
N, DAG);
5595 SplitInteger(Res,
Lo,
Hi);
5599 SDValue Res = TLI.expandMULH(
N, DAG);
5600 SplitInteger(Res,
Lo,
Hi);
5605 EVT VT =
N->getValueType(0);
5612 SDValue VScaleBase = DAG.getVScale(dl, HalfVT, One);
5615 SplitInteger(Res,
Lo,
Hi);
5622 "cannot use llvm.read_register with illegal type", Fn,
N->getDebugLoc()));
5623 ReplaceValueWith(SDValue(
N, 1),
N->getOperand(0));
5625 std::tie(LoVT, HiVT) = DAG.GetSplitDestVTs(
N->getValueType(0));
5626 Lo = DAG.getPOISON(LoVT);
5627 Hi = DAG.getPOISON(HiVT);
5634 EVT VT =
N->getSimpleValueType(0);
5635 EVT IdxVT = TLI.getVectorIdxTy(DAG.getDataLayout());
5637 "VectorIdxTy should be smaller than type to be expanded?");
5639 SDValue Res = DAG.
getNode(
N->getOpcode(), SDLoc(
N), IdxVT,
N->getOperand(0));
5641 SplitInteger(Res,
Lo,
Hi);
5652bool DAGTypeLegalizer::ExpandIntegerOperand(
SDNode *
N,
unsigned OpNo) {
5654 SDValue Res = SDValue();
5656 if (CustomLowerNode(
N,
N->getOperand(OpNo).getValueType(),
false))
5659 switch (
N->getOpcode()) {
5662 dbgs() <<
"ExpandIntegerOperand Op #" << OpNo <<
": ";
5663 N->dump(&DAG);
dbgs() <<
"\n";
5668 case ISD::BR_CC: Res = ExpandIntOp_BR_CC(
N);
break;
5672 Res = ExpandOp_FAKE_USE(
N);
5676 Res = TLI.expandLoopDependenceMask(
N, DAG);
5682 case ISD::SETCC: Res = ExpandIntOp_SETCC(
N);
break;
5695 case ISD::ROTR: Res = ExpandIntOp_Shift(
N);
break;
5700 case ISD::UCMP: Res = ExpandIntOp_CMP(
N);
break;
5704 Res = ExpandIntOp_STACKMAP(
N, OpNo);
5707 Res = ExpandIntOp_PATCHPOINT(
N, OpNo);
5709 case ISD::EXPERIMENTAL_VP_STRIDED_LOAD:
5710 case ISD::EXPERIMENTAL_VP_STRIDED_STORE:
5711 Res = ExpandIntOp_VP_STRIDED(
N, OpNo);
5714 Res = ExpandIntOp_WRITE_REGISTER(
N, OpNo);
5719 if (!Res.
getNode())
return false;
5727 "Invalid operand expansion");
5729 ReplaceValueWith(SDValue(
N, 0), Res);
5735void DAGTypeLegalizer::IntegerExpandSetCCOperands(
SDValue &NewLHS,
5739 SDValue LHSLo, LHSHi, RHSLo, RHSHi;
5740 GetExpandedInteger(NewLHS, LHSLo, LHSHi);
5741 GetExpandedInteger(NewRHS, RHSLo, RHSHi);
5754 NewRHS = DAG.getConstant(0, dl, NewLHS.
getValueType());
5761 if ((CCCode ==
ISD::SETLT && CST->isZero()) ||
5762 (CCCode ==
ISD::SETGT && CST->isAllOnes())) {
5790 SDValue LoCmp, HiCmp;
5792 LoCmp = TLI.SimplifySetCC(getSetCCResultType(LHSLo.
getValueType()), LHSLo,
5793 RHSLo, LowCC,
false, DagCombineInfo, dl);
5795 LoCmp = DAG.getSetCC(dl, getSetCCResultType(LHSLo.
getValueType()), LHSLo,
5798 HiCmp = TLI.SimplifySetCC(getSetCCResultType(LHSHi.
getValueType()), LHSHi,
5799 RHSHi, CCCode,
false, DagCombineInfo, dl);
5803 LHSHi, RHSHi, DAG.getCondCode(CCCode));
5812 if ((EqAllowed && (HiCmpC && HiCmpC->
isZero())) ||
5814 ((HiCmpC && HiCmpC->
isOne()) || (LoCmpC && LoCmpC->
isZero())))) {
5823 if (LHSHi == RHSHi) {
5832 EVT ExpandVT = TLI.getTypeToExpandTo(*DAG.getContext(), HiVT);
5833 bool HasSETCCCARRY = TLI.isOperationLegalOrCustom(
ISD::SETCCCARRY, ExpandVT);
5836 if (HasSETCCCARRY) {
5839 bool FlipOperands =
false;
5856 SDVTList VTList = DAG.getVTList(LoVT, getSetCCResultType(LoVT));
5857 SDValue LowCmp = DAG.getNode(
ISD::USUBO, dl, VTList, LHSLo, RHSLo);
5860 DAG.getCondCode(CCCode));
5866 NewLHS = TLI.SimplifySetCC(getSetCCResultType(HiVT), LHSHi, RHSHi,
ISD::SETEQ,
5867 false, DagCombineInfo, dl);
5870 DAG.getSetCC(dl, getSetCCResultType(HiVT), LHSHi, RHSHi,
ISD::SETEQ);
5871 NewLHS = DAG.getSelect(dl, LoCmp.
getValueType(), NewLHS, LoCmp, HiCmp);
5878 IntegerExpandSetCCOperands(NewLHS, NewRHS, CCCode, SDLoc(
N));
5883 NewRHS = DAG.getConstant(0, SDLoc(
N), NewLHS.
getValueType());
5888 return SDValue(DAG.UpdateNodeOperands(
N,
N->getOperand(0),
5889 DAG.getCondCode(CCCode), NewLHS, NewRHS,
5890 N->getOperand(4)), 0);
5896 IntegerExpandSetCCOperands(NewLHS, NewRHS, CCCode, SDLoc(
N));
5901 NewRHS = DAG.getConstant(0, SDLoc(
N), NewLHS.
getValueType());
5906 return SDValue(DAG.UpdateNodeOperands(
N, NewLHS, NewRHS,
5907 N->getOperand(2),
N->getOperand(3),
5908 DAG.getCondCode(CCCode)), 0);
5914 IntegerExpandSetCCOperands(NewLHS, NewRHS, CCCode, SDLoc(
N));
5919 "Unexpected setcc expansion!");
5925 DAG.UpdateNodeOperands(
N, NewLHS, NewRHS, DAG.getCondCode(CCCode)), 0);
5929 SDValue
LHS =
N->getOperand(0);
5930 SDValue
RHS =
N->getOperand(1);
5932 SDValue
Cond =
N->getOperand(3);
5933 SDLoc dl = SDLoc(
N);
5935 SDValue LHSLo, LHSHi, RHSLo, RHSHi;
5936 GetExpandedInteger(
LHS, LHSLo, LHSHi);
5937 GetExpandedInteger(
RHS, RHSLo, RHSHi);
5950 GetExpandedInteger(
N->getOperand(0),
Lo,
Hi);
5960 GetExpandedInteger(
N->getOperand(1),
Lo,
Hi);
5961 return SDValue(DAG.UpdateNodeOperands(
N,
N->getOperand(0),
Lo), 0);
5965 return TLI.expandCMP(
N, DAG);
5973 GetExpandedInteger(
N->getOperand(0),
Lo,
Hi);
5974 return SDValue(DAG.UpdateNodeOperands(
N,
Lo), 0);
5978 bool IsStrict =
N->isStrictFPOpcode();
5981 SDValue Chain = IsStrict ?
N->getOperand(0) : SDValue();
5982 SDValue
Op =
N->getOperand(IsStrict ? 1 : 0);
5983 EVT DstVT =
N->getValueType(0);
5986 assert(LC != RTLIB::UNKNOWN_LIBCALL &&
5987 "Don't know how to expand this XINT_TO_FP!");
5988 TargetLowering::MakeLibCallOptions CallOptions;
5990 std::pair<SDValue, SDValue> Tmp =
5991 TLI.makeLibCall(DAG, LC, DstVT,
Op, CallOptions, SDLoc(
N), Chain);
5996 ReplaceValueWith(SDValue(
N, 1), Tmp.second);
5997 ReplaceValueWith(SDValue(
N, 0), Tmp.first);
6002 assert(!
N->isAtomic() &&
"Should have been a ATOMIC_STORE?");
6005 return ExpandOp_NormalStore(
N, OpNo);
6008 assert(OpNo == 1 &&
"Can only expand the stored value so far");
6010 EVT VT =
N->getOperand(1).getValueType();
6011 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), VT);
6012 SDValue Ch =
N->getChain();
6013 SDValue Ptr =
N->getBasePtr();
6015 MMOMetadata
Metadata =
N->getMMOMetadataForSubAccess();
6021 if (
N->getMemoryVT().bitsLE(NVT)) {
6022 GetExpandedInteger(
N->getValue(),
Lo,
Hi);
6023 return DAG.getTruncStore(Ch, dl,
Lo, Ptr,
N->getPointerInfo(),
6024 N->getMemoryVT(),
N->getBaseAlign(), MMOFlags,
6028 if (DAG.getDataLayout().isLittleEndian()) {
6030 GetExpandedInteger(
N->getValue(),
Lo,
Hi);
6032 Lo = DAG.getStore(Ch, dl,
Lo, Ptr,
N->getPointerInfo(),
N->getBaseAlign(),
6035 unsigned ExcessBits =
6042 Hi = DAG.getTruncStore(Ch, dl,
Hi, Ptr,
6043 N->getPointerInfo().getWithOffset(IncrementSize),
6044 NEVT,
N->getBaseAlign(), MMOFlags,
Metadata);
6050 GetExpandedInteger(
N->getValue(),
Lo,
Hi);
6052 EVT ExtVT =
N->getMemoryVT();
6055 unsigned ExcessBits = (EBytes - IncrementSize)*8;
6063 DAG.getShiftAmountConstant(NVT.
getSizeInBits() - ExcessBits, NVT, dl));
6067 DAG.getShiftAmountConstant(ExcessBits, NVT, dl)));
6071 Hi = DAG.getTruncStore(Ch, dl,
Hi, Ptr,
N->getPointerInfo(), HiVT,
6077 Lo = DAG.getTruncStore(Ch, dl,
Lo, Ptr,
6078 N->getPointerInfo().getWithOffset(IncrementSize),
6086 GetExpandedInteger(
N->getOperand(0), InL, InH);
6095 N->getOperand(0),
N->getOperand(2),
N->getOperand(1),
6097 return Swap.getValue(1);
6100SDValue DAGTypeLegalizer::ExpandIntOp_VP_STRIDED(
SDNode *
N,
unsigned OpNo) {
6101 assert((
N->getOpcode() == ISD::EXPERIMENTAL_VP_STRIDED_LOAD && OpNo == 3) ||
6102 (
N->getOpcode() == ISD::EXPERIMENTAL_VP_STRIDED_STORE && OpNo == 4));
6106 GetExpandedInteger(NewOps[OpNo], NewOps[OpNo],
Hi);
6108 return SDValue(DAG.UpdateNodeOperands(
N, NewOps), 0);
6111SDValue DAGTypeLegalizer::ExpandIntOp_WRITE_REGISTER(
SDNode *
N,
unsigned OpNo) {
6114 "cannot use llvm.write_register with illegal type", Fn,
6117 return N->getOperand(0);
6120SDValue DAGTypeLegalizer::PromoteIntRes_VECTOR_SPLICE(
SDNode *
N) {
6123 SDValue
V0 = GetPromotedInteger(
N->getOperand(0));
6124 SDValue
V1 = GetPromotedInteger(
N->getOperand(1));
6125 EVT OutVT =
V0.getValueType();
6127 return DAG.getNode(
N->getOpcode(), dl, OutVT, V0,
V1,
N->getOperand(2));
6130SDValue DAGTypeLegalizer::PromoteIntRes_VECTOR_REPEAT(
SDNode *
N) {
6133 EVT OutVT =
N->getValueType(0);
6134 EVT NOutVT = TLI.getTypeToTransformTo(*DAG.getContext(), OutVT);
6139 return DAG.getNode(
N->getOpcode(),
DL, NOutVT,
Op);
6142SDValue DAGTypeLegalizer::PromoteIntRes_VECTOR_INTERLEAVE_DEINTERLEAVE(
SDNode *
N) {
6144 unsigned Factor =
N->getNumOperands();
6147 for (
unsigned i = 0; i != Factor; i++)
6148 Ops[i] = GetPromotedInteger(
N->getOperand(i));
6151 SDValue Res = DAG.
getNode(
N->getOpcode(),
DL, DAG.getVTList(ResVTs),
Ops);
6153 for (
unsigned i = 0; i != Factor; i++)
6154 SetPromotedInteger(SDValue(
N, i), Res.
getValue(i));
6159SDValue DAGTypeLegalizer::PromoteIntRes_EXTRACT_SUBVECTOR(
SDNode *
N) {
6161 EVT OutVT =
N->getValueType(0);
6162 EVT NOutVT = TLI.getTypeToTransformTo(*DAG.getContext(), OutVT);
6163 assert(NOutVT.
isVector() &&
"This type must be promoted to a vector type");
6167 SDValue BaseIdx =
N->getOperand(1);
6172 SDValue InOp0 =
N->getOperand(0);
6184 DAG.getConstant(
alignDown(IdxVal, NElts), dl,
6186 SDValue Step2 = DAG.getNode(
6188 DAG.getConstant(IdxVal % NElts, dl, BaseIdx.
getValueType()));
6194 SDValue
Ops[] = {GetWidenedVector(InOp0), BaseIdx};
6203 SDValue
Ops[] = { GetPromotedInteger(InOp0), BaseIdx };
6207 "Promoted operand has an element type greater than result");
6220 InOp0 = GetPromotedInteger(InOp0);
6227 Ops.reserve(OutNumElems);
6228 for (
unsigned i = 0; i != OutNumElems; ++i) {
6233 N->getOperand(0), Index);
6234 SDValue
Op = DAG.getAnyExtOrTrunc(Ext, dl, NOutVTElem);
6239 return DAG.getBuildVector(NOutVT, dl,
Ops);
6242SDValue DAGTypeLegalizer::PromoteIntRes_INSERT_SUBVECTOR(
SDNode *
N) {
6243 EVT OutVT =
N->getValueType(0);
6244 EVT NOutVT = TLI.getTypeToTransformTo(*DAG.getContext(), OutVT);
6245 assert(NOutVT.
isVector() &&
"This type must be promoted to a vector type");
6250 SDValue
Idx =
N->getOperand(2);
6257 Vec = GetPromotedInteger(Vec);
6263SDValue DAGTypeLegalizer::PromoteIntRes_VECTOR_REVERSE(
SDNode *
N) {
6266 SDValue
V0 = GetPromotedInteger(
N->getOperand(0));
6267 EVT OutVT =
V0.getValueType();
6272SDValue DAGTypeLegalizer::PromoteIntRes_VECTOR_SHUFFLE(
SDNode *
N) {
6274 EVT VT =
N->getValueType(0);
6279 SDValue
V0 = GetPromotedInteger(
N->getOperand(0));
6280 SDValue
V1 = GetPromotedInteger(
N->getOperand(1));
6281 EVT OutVT =
V0.getValueType();
6283 return DAG.getVectorShuffle(OutVT, dl, V0,
V1, NewMask);
6287 EVT OutVT =
N->getValueType(0);
6288 EVT NOutVT = TLI.getTypeToTransformTo(*DAG.getContext(), OutVT);
6289 assert(NOutVT.
isVector() &&
"This type must be promoted to a vector type");
6290 unsigned NumElems =
N->getNumOperands();
6297 Ops.reserve(NumElems);
6298 for (
unsigned i = 0; i != NumElems; ++i) {
6299 SDValue
Op =
N->getOperand(i);
6300 EVT OpVT =
Op.getValueType();
6305 if (OpVT.
bitsLT(NOutVTElem)) {
6311 ExtOpc = NOutExtOpc;
6312 Op = DAG.getNode(ExtOpc, dl, NOutVTElem,
Op);
6317 return DAG.getBuildVector(NOutVT, dl,
Ops);
6324 assert(!
N->getOperand(0).getValueType().isVector() &&
6325 "Input must be a scalar");
6327 EVT OutVT =
N->getValueType(0);
6328 EVT NOutVT = TLI.getTypeToTransformTo(*DAG.getContext(), OutVT);
6329 assert(NOutVT.
isVector() &&
"This type must be promoted to a vector type");
6333 return DAG.getNode(
N->getOpcode(), dl, NOutVT,
Op);
6338 EVT OutVT =
N->getValueType(0);
6339 EVT NOutVT = TLI.getTypeToTransformTo(*DAG.getContext(), OutVT);
6341 "Type must be promoted to a scalable vector type");
6342 const APInt &StepVal =
N->getConstantOperandAPInt(0);
6343 return DAG.getStepVector(dl, NOutVT,
6347SDValue DAGTypeLegalizer::PromoteIntRes_CONCAT_VECTORS(
SDNode *
N) {
6350 EVT OutVT =
N->getValueType(0);
6351 EVT NOutVT = TLI.getTypeToTransformTo(*DAG.getContext(), OutVT);
6352 assert(NOutVT.
isVector() &&
"This type must be promoted to a vector type");
6354 unsigned NumOperands =
N->getNumOperands();
6358 EVT OpVT =
N->getOperand(0).getValueType();
6363 "Unhandled legalization type");
6369 for (
unsigned I = 0;
I < NumOperands; ++
I) {
6370 SDValue
Op =
N->getOperand(
I);
6372 Op = GetPromotedInteger(
Op);
6381 *DAG.getContext(),
Ops[0].getValueType().getVectorElementType());
6382 return DAG.getAnyExtOrTrunc(
6386 unsigned NumElem =
N->getOperand(0).getValueType().getVectorNumElements();
6387 assert(NumElem * NumOperands == NumOutElem &&
6388 "Unexpected number of elements");
6392 for (
unsigned i = 0; i < NumOperands; ++i) {
6393 SDValue
Op =
N->getOperand(i);
6395 Op = GetPromotedInteger(
Op);
6396 EVT SclrTy =
Op.getValueType().getVectorElementType();
6397 assert(NumElem ==
Op.getValueType().getVectorNumElements() &&
6398 "Unexpected number of elements");
6400 for (
unsigned j = 0;
j < NumElem; ++
j) {
6402 DAG.getVectorIdxConstant(j, dl));
6403 Ops[i * NumElem +
j] = DAG.getAnyExtOrTrunc(Ext, dl, OutElemTy);
6407 return DAG.getBuildVector(NOutVT, dl,
Ops);
6410SDValue DAGTypeLegalizer::PromoteIntRes_EXTEND_VECTOR_INREG(
SDNode *
N) {
6411 EVT VT =
N->getValueType(0);
6412 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), VT);
6413 assert(NVT.
isVector() &&
"This type must be promoted to a vector type");
6421 if (getTypeAction(
N->getOperand(0).getValueType())
6425 switch(
N->getOpcode()) {
6427 Promoted = SExtPromotedInteger(
N->getOperand(0));
6430 Promoted = ZExtPromotedInteger(
N->getOperand(0));
6433 Promoted = GetPromotedInteger(
N->getOperand(0));
6445 DAG.getVectorIdxConstant(0, dl));
6447 return DAG.getNode(
N->getOpcode(), dl, NVT, Promoted);
6451 return DAG.getNode(
N->getOpcode(), dl, NVT,
N->getOperand(0));
6454SDValue DAGTypeLegalizer::PromoteIntRes_VECTOR_FIND_LAST_ACTIVE(
SDNode *
N) {
6455 EVT VT =
N->getValueType(0);
6456 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), VT);
6460SDValue DAGTypeLegalizer::PromoteIntRes_GET_ACTIVE_LANE_MASK(
SDNode *
N) {
6461 EVT VT =
N->getValueType(0);
6462 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), VT);
6466SDValue DAGTypeLegalizer::PromoteIntRes_MASK_BEFOREFIRST(
SDNode *
N) {
6467 EVT VT =
N->getValueType(0);
6468 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), VT);
6469 SDValue
Op = PromoteTargetBoolean(
N->getOperand(0), NVT);
6474 EVT VT =
N->getValueType(0);
6475 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), VT);
6477 NewOps[2] = PromoteTargetBoolean(
N->getOperand(2), NVT);
6481SDValue DAGTypeLegalizer::PromoteIntRes_PARTIAL_REDUCE_MLA(
SDNode *
N) {
6483 EVT VT =
N->getValueType(0);
6484 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), VT);
6485 SDValue ExtAcc = GetPromotedInteger(
N->getOperand(0));
6486 return DAG.getNode(
N->getOpcode(),
DL, NVT, ExtAcc,
N->getOperand(1),
6490SDValue DAGTypeLegalizer::PromoteIntRes_INSERT_VECTOR_ELT(
SDNode *
N) {
6491 EVT OutVT =
N->getValueType(0);
6492 EVT NOutVT = TLI.getTypeToTransformTo(*DAG.getContext(), OutVT);
6493 assert(NOutVT.
isVector() &&
"This type must be promoted to a vector type");
6498 SDValue
V0 = GetPromotedInteger(
N->getOperand(0));
6501 NOutVTElem,
N->getOperand(1));
6503 V0, ConvElem,
N->getOperand(2));
6510 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(),
N->getValueType(0));
6511 return DAG.getNode(
N->getOpcode(), dl, NVT,
N->ops());
6519 SDValue
Start = PromoteIntOpVectorReduction(
N,
N->getOperand(0));
6520 return DAG.getNode(
N->getOpcode(),
DL,
Start.getValueType(), Start,
6521 N->getOperand(1),
N->getOperand(2),
N->getOperand(3));
6525 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(),
N->getValueType(0));
6528 assert(
N->getNumValues() == 3 &&
"Expected 3 values for PATCHPOINT");
6529 SDVTList VTList = DAG.getVTList({NVT, MVT::Other, MVT::Glue});
6535 SDValue From[] = {SDValue(
N, 1), SDValue(
N, 2)};
6537 DAG.ReplaceAllUsesOfValuesWith(From, To, 2);
6542SDValue DAGTypeLegalizer::PromoteIntRes_READ_REGISTER(
SDNode *
N) {
6545 "cannot use llvm.read_register with illegal type", Fn,
N->getDebugLoc()));
6547 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(),
N->getValueType(0));
6548 ReplaceValueWith(SDValue(
N, 1),
N->getOperand(0));
6549 return DAG.getPOISON(NVT);
6552SDValue DAGTypeLegalizer::PromoteIntOp_EXTRACT_VECTOR_ELT(
SDNode *
N) {
6554 SDValue
V0 = GetPromotedInteger(
N->getOperand(0));
6555 SDValue
V1 = DAG.getZExtOrTrunc(
N->getOperand(1), dl,
6556 TLI.getVectorIdxTy(DAG.getDataLayout()));
6558 V0->getValueType(0).getScalarType(), V0,
V1);
6563 return DAG.getAnyExtOrTrunc(Ext, dl,
N->getValueType(0));
6566SDValue DAGTypeLegalizer::PromoteIntOp_INSERT_SUBVECTOR(
SDNode *
N) {
6570 SDValue
V0 =
N->getOperand(0);
6571 SDValue
V1 = GetPromotedInteger(
N->getOperand(1));
6572 SDValue
Idx =
N->getOperand(2);
6574 V1.getValueType().getVectorElementType(),
6575 V0.getValueType().getVectorElementCount());
6576 V0 = DAG.getAnyExtOrTrunc(V0, dl, PromVT);
6578 return DAG.getAnyExtOrTrunc(Ext, dl,
N->getValueType(0));
6585 SDValue
V0 =
N->getOperand(0);
6586 SDValue
V1 =
N->getOperand(1);
6587 EVT InVT1 =
V1.getValueType();
6590 TLI.getTypeToTransformTo(*DAG.getContext(), InVT1),
V1);
6591 return DAG.getNode(
N->getOpcode(), dl,
N->getValueType(0), V0, VPromoted);
6594SDValue DAGTypeLegalizer::PromoteIntOp_EXTRACT_SUBVECTOR(
SDNode *
N) {
6596 SDValue
V0 = GetPromotedInteger(
N->getOperand(0));
6597 MVT InVT =
V0.getValueType().getSimpleVT();
6604SDValue DAGTypeLegalizer::PromoteIntOp_CONCAT_VECTORS(
SDNode *
N) {
6607 EVT ResVT =
N->getValueType(0);
6608 unsigned NumElems =
N->getNumOperands();
6611 SDValue ResVec = DAG.getPOISON(ResVT);
6613 for (
unsigned OpIdx = 0; OpIdx < NumElems; ++OpIdx) {
6614 SDValue
Op =
N->getOperand(OpIdx);
6615 unsigned OpNumElts =
Op.getValueType().getVectorMinNumElements();
6617 DAG.getIntPtrConstant(OpIdx * OpNumElts, dl));
6629 for (
unsigned VecIdx = 0; VecIdx != NumElems; ++VecIdx) {
6630 SDValue Incoming = GetPromotedInteger(
N->getOperand(VecIdx));
6634 for (
unsigned i=0; i<NumElem; ++i) {
6637 DAG.getVectorIdxConstant(i, dl));
6643 return DAG.getBuildVector(
N->getValueType(0), dl, NewOps);
6646SDValue DAGTypeLegalizer::ExpandIntOp_STACKMAP(
SDNode *
N,
unsigned OpNo) {
6648 SDValue
Op =
N->getOperand(OpNo);
6659 for (
unsigned I = 0;
I < OpNo;
I++)
6662 EVT Ty =
Op.getValueType();
6663 SDLoc
DL = SDLoc(
N);
6666 DAG.getTargetConstant(StackMaps::ConstantOp,
DL, MVT::i64));
6674 for (
unsigned I = OpNo + 1;
I <
N->getNumOperands();
I++)
6677 SDValue
NewNode = DAG.getNode(
N->getOpcode(),
DL,
N->getVTList(), NewOps);
6679 for (
unsigned ResNum = 0; ResNum <
N->getNumValues(); ResNum++)
6680 ReplaceValueWith(SDValue(
N, ResNum),
NewNode.getValue(ResNum));
6685SDValue DAGTypeLegalizer::ExpandIntOp_PATCHPOINT(
SDNode *
N,
unsigned OpNo) {
6687 SDValue
Op =
N->getOperand(OpNo);
6698 for (
unsigned I = 0;
I < OpNo;
I++)
6701 EVT Ty =
Op.getValueType();
6702 SDLoc
DL = SDLoc(
N);
6705 DAG.getTargetConstant(StackMaps::ConstantOp,
DL, MVT::i64));
6713 for (
unsigned I = OpNo + 1;
I <
N->getNumOperands();
I++)
6716 SDValue
NewNode = DAG.getNode(
N->getOpcode(),
DL,
N->getVTList(), NewOps);
6718 for (
unsigned ResNum = 0; ResNum <
N->getNumValues(); ResNum++)
6719 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)