31#define DEBUG_TYPE "legalize-types"
41void 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";
63 case ISD::VP_BITREVERSE:
66 case ISD::BSWAP: Res = PromoteIntRes_BSWAP(
N);
break;
69 case ISD::VP_CTLZ_ZERO_UNDEF:
72 case ISD::CTLZ: Res = PromoteIntRes_CTLZ(
N);
break;
75 case ISD::CTPOP: Res = PromoteIntRes_CTPOP_PARITY(
N);
break;
76 case ISD::VP_CTTZ_ZERO_UNDEF:
79 case ISD::CTTZ: Res = PromoteIntRes_CTTZ(
N);
break;
81 Res = PromoteIntRes_EXTRACT_VECTOR_ELT(
N);
break;
82 case ISD::LOAD: Res = PromoteIntRes_LOAD(cast<LoadSDNode>(
N));
break;
83 case ISD::MLOAD: Res = PromoteIntRes_MLOAD(cast<MaskedLoadSDNode>(
N));
85 case ISD::MGATHER: Res = PromoteIntRes_MGATHER(cast<MaskedGatherSDNode>(
N));
91 Res = PromoteIntRes_Select(
N);
96 case ISD::SETCC: Res = PromoteIntRes_SETCC(
N);
break;
98 case ISD::SMAX: Res = PromoteIntRes_SExtIntBinOp(
N);
break;
100 case ISD::UMAX: Res = PromoteIntRes_UMINUMAX(
N);
break;
103 case ISD::VP_SHL: Res = PromoteIntRes_SHL(
N);
break;
105 Res = PromoteIntRes_SIGN_EXTEND_INREG(
N);
break;
107 case ISD::VP_ASHR: Res = PromoteIntRes_SRA(
N);
break;
109 case ISD::VP_LSHR: Res = PromoteIntRes_SRL(
N);
break;
110 case ISD::VP_TRUNCATE:
112 case ISD::UNDEF: Res = PromoteIntRes_UNDEF(
N);
break;
113 case ISD::VAARG: Res = PromoteIntRes_VAARG(
N);
break;
117 Res = PromoteIntRes_EXTRACT_SUBVECTOR(
N);
break;
119 Res = PromoteIntRes_INSERT_SUBVECTOR(
N);
break;
121 Res = PromoteIntRes_VECTOR_REVERSE(
N);
break;
123 Res = PromoteIntRes_VECTOR_SHUFFLE(
N);
break;
125 Res = PromoteIntRes_VECTOR_SPLICE(
N);
break;
128 Res = PromoteIntRes_VECTOR_INTERLEAVE_DEINTERLEAVE(
N);
131 Res = PromoteIntRes_INSERT_VECTOR_ELT(
N);
break;
133 Res = PromoteIntRes_BUILD_VECTOR(
N);
137 Res = PromoteIntRes_ScalarOp(
N);
141 Res = PromoteIntRes_CONCAT_VECTORS(
N);
break;
146 Res = PromoteIntRes_EXTEND_VECTOR_INREG(
N);
break;
149 case ISD::VP_SIGN_EXTEND:
151 case ISD::VP_ZERO_EXTEND:
154 case ISD::VP_FP_TO_SINT:
155 case ISD::VP_FP_TO_UINT:
163 Res = PromoteIntRes_FP_TO_XINT_SAT(
N);
break;
167 Res = PromoteIntRes_FP_TO_FP16_BF16(
N);
183 case ISD::VP_MUL: Res = PromoteIntRes_SimpleIntBinOp(
N);
break;
190 case ISD::VP_SREM: Res = PromoteIntRes_SExtIntBinOp(
N);
break;
197 case ISD::VP_UREM: Res = PromoteIntRes_ZExtIntBinOp(
N);
break;
200 case ISD::SSUBO: Res = PromoteIntRes_SADDSUBO(
N, ResNo);
break;
202 case ISD::USUBO: Res = PromoteIntRes_UADDSUBO(
N, ResNo);
break;
204 case ISD::UMULO: Res = PromoteIntRes_XMULO(
N, ResNo);
break;
219 case ISD::USHLSAT: Res = PromoteIntRes_ADDSUBSHLSAT(
N);
break;
231 case ISD::ABS: Res = PromoteIntRes_ABS(
N);
break;
234 Res = PromoteIntRes_Atomic0(cast<AtomicSDNode>(
N));
break;
248 Res = PromoteIntRes_Atomic1(cast<AtomicSDNode>(
N));
break;
252 Res = PromoteIntRes_AtomicCmpSwap(cast<AtomicSDNode>(
N), ResNo);
264 Res = PromoteIntRes_VECREDUCE(
N);
267 case ISD::VP_REDUCE_ADD:
268 case ISD::VP_REDUCE_MUL:
269 case ISD::VP_REDUCE_AND:
270 case ISD::VP_REDUCE_OR:
271 case ISD::VP_REDUCE_XOR:
272 case ISD::VP_REDUCE_SMAX:
273 case ISD::VP_REDUCE_SMIN:
274 case ISD::VP_REDUCE_UMAX:
275 case ISD::VP_REDUCE_UMIN:
276 Res = PromoteIntRes_VP_REDUCE(
N);
280 Res = PromoteIntRes_FREEZE(
N);
285 Res = PromoteIntRes_Rotate(
N);
290 Res = PromoteIntRes_FunnelShift(
N);
295 Res = PromoteIntRes_VPFunnelShift(
N);
299 Res = PromoteIntRes_IS_FPCLASS(
N);
302 Res = PromoteIntRes_FFREXP(
N);
308 SetPromotedInteger(
SDValue(
N, ResNo), Res);
313 SDValue Op = DisintegrateMERGE_VALUES(
N, ResNo);
314 return GetPromotedInteger(
Op);
319 SDValue Op = SExtPromotedInteger(
N->getOperand(0));
321 Op.getValueType(),
Op,
N->getOperand(1));
326 SDValue Op = ZExtPromotedInteger(
N->getOperand(0));
328 Op.getValueType(),
Op,
N->getOperand(1));
334 N->getMemoryVT(), ResVT,
335 N->getChain(),
N->getBasePtr(),
344 SDValue Op2 = GetPromotedInteger(
N->getOperand(2));
347 N->getChain(),
N->getBasePtr(),
348 Op2,
N->getMemOperand());
359 EVT SVT = getSetCCResultType(
N->getOperand(2).getValueType());
370 N->getChain(),
N->getBasePtr(),
N->getOperand(2),
N->getOperand(3),
380 SDValue Op3 = GetPromotedInteger(
N->getOperand(3));
383 Op2 = SExtPromotedInteger(Op2);
386 Op2 = ZExtPromotedInteger(Op2);
389 Op2 = GetPromotedInteger(Op2);
398 N->getOpcode(),
SDLoc(
N),
N->getMemoryVT(), VTs,
N->getChain(),
399 N->getBasePtr(), Op2, Op3,
N->getMemOperand());
401 for (
unsigned i = 1, NumResults =
N->getNumValues(); i < NumResults; ++i)
410 EVT OutVT =
N->getValueType(0);
414 switch (getTypeAction(InVT)) {
441 BitConvertToInteger(GetScalarizedVector(InOp)));
450 GetSplitVector(
N->getOperand(0),
Lo,
Hi);
451 Lo = BitConvertToInteger(
Lo);
452 Hi = BitConvertToInteger(
Hi);
460 JoinIntegers(
Lo,
Hi));
494 if (isTypeLegal(WideOutVT)) {
495 InOp = DAG.
getBitcast(WideOutVT, GetWidenedVector(InOp));
505 CreateStackStoreLoad(InOp, OutVT));
509 SDValue V = GetPromotedInteger(
N->getOperand(0));
511 V.getValueType(), V);
515 SDValue Op = GetPromotedInteger(
N->getOperand(0));
516 EVT OVT =
N->getValueType(0);
517 EVT NVT =
Op.getValueType();
537 return DAG.
getNode(ISD::VP_LSHR, dl, NVT,
538 DAG.
getNode(ISD::VP_BSWAP, dl, NVT,
Op, Mask, EVL), ShAmt,
543 SDValue Op = GetPromotedInteger(
N->getOperand(0));
544 EVT OVT =
N->getValueType(0);
545 EVT NVT =
Op.getValueType();
565 return DAG.
getNode(ISD::VP_LSHR, dl, NVT,
566 DAG.
getNode(ISD::VP_BITREVERSE, dl, NVT,
Op, Mask, EVL),
575 N->getValueType(0)), JoinIntegers(
N->getOperand(0),
580 EVT VT =
N->getValueType(0);
589 assert(isa<ConstantSDNode>(Result) &&
"Didn't constant fold ext?");
594 EVT OVT =
N->getValueType(0);
611 SDValue Op = ZExtPromotedInteger(
N->getOperand(0));
616 if (!
N->isVPOpcode())
622 return DAG.
getNode(ISD::VP_SUB, dl, NVT,
623 DAG.
getNode(
N->getOpcode(), dl, NVT,
Op, Mask, EVL),
624 ExtractLeadingBits, Mask, EVL);
628 EVT OVT =
N->getValueType(0);
645 SDValue Op = ZExtPromotedInteger(
N->getOperand(0));
646 if (!
N->isVPOpcode())
649 N->getOperand(1),
N->getOperand(2));
653 SDValue Op = GetPromotedInteger(
N->getOperand(0));
654 EVT OVT =
N->getValueType(0);
655 EVT NVT =
Op.getValueType();
673 if (
N->getOpcode() ==
ISD::CTTZ ||
N->getOpcode() == ISD::VP_CTTZ) {
684 N->getOperand(1),
N->getOperand(2));
686 if (!
N->isVPOpcode())
687 return DAG.
getNode(
N->getOpcode(), dl, NVT,
Op);
688 return DAG.
getNode(
N->getOpcode(), dl, NVT,
Op,
N->getOperand(1),
692SDValue DAGTypeLegalizer::PromoteIntRes_EXTRACT_VECTOR_ELT(
SDNode *
N) {
707 EVT SVT =
In.getValueType().getScalarType();
719 unsigned NewOpc =
N->getOpcode();
736 if (
N->getOpcode() == ISD::VP_FP_TO_UINT &&
739 NewOpc = ISD::VP_FP_TO_SINT;
742 if (
N->isStrictFPOpcode()) {
743 Res = DAG.
getNode(NewOpc, dl, {NVT, MVT::Other},
744 {
N->getOperand(0),
N->getOperand(1)});
748 }
else if (NewOpc == ISD::VP_FP_TO_SINT || NewOpc == ISD::VP_FP_TO_UINT) {
749 Res = DAG.
getNode(NewOpc, dl, NVT, {
N->getOperand(0),
N->getOperand(1),
752 Res = DAG.
getNode(NewOpc, dl, NVT,
N->getOperand(0));
764 N->getOpcode() == ISD::VP_FP_TO_UINT)
771SDValue DAGTypeLegalizer::PromoteIntRes_FP_TO_XINT_SAT(
SDNode *
N) {
775 return DAG.
getNode(
N->getOpcode(), dl, NVT,
N->getOperand(0),
779SDValue DAGTypeLegalizer::PromoteIntRes_FP_TO_FP16_BF16(
SDNode *
N) {
783 return DAG.
getNode(
N->getOpcode(), dl, NVT,
N->getOperand(0));
791 DAG.
getNode(
N->getOpcode(), dl, {NVT, MVT::Other},
N->getOperand(0));
803 if (getTypeAction(
N->getOperand(0).getValueType())
805 SDValue Res = GetPromotedInteger(
N->getOperand(0));
823 if (
N->getNumOperands() != 1) {
824 assert(
N->getNumOperands() == 3 &&
"Unexpected number of operands!");
825 assert(
N->isVPOpcode() &&
"Expected VP opcode");
826 return DAG.
getNode(
N->getOpcode(), dl, NVT,
N->getOperand(0),
827 N->getOperand(1),
N->getOperand(2));
829 return DAG.
getNode(
N->getOpcode(), dl, NVT,
N->getOperand(0));
839 N->getMemoryVT(),
N->getMemOperand());
849 SDValue ExtPassThru = GetPromotedInteger(
N->getPassThru());
857 N->getOffset(),
N->getMask(), ExtPassThru,
858 N->getMemoryVT(),
N->getMemOperand(),
859 N->getAddressingMode(), ExtType,
860 N->isExpandingLoad());
869 SDValue ExtPassThru = GetPromotedInteger(
N->getPassThru());
871 "Gather result type and the passThru argument type should be the same");
878 SDValue Ops[] = {
N->getChain(), ExtPassThru,
N->getMask(),
N->getBasePtr(),
879 N->getIndex(),
N->getScale() };
881 N->getMemoryVT(), dl, Ops,
882 N->getMemOperand(),
N->getIndexType(),
895 EVT VT =
N->getValueType(0);
896 EVT SVT = getSetCCResultType(VT);
897 SDValue Ops[3] = {
N->getOperand(0),
N->getOperand(1) };
898 unsigned NumOps =
N->getNumOperands();
899 assert(NumOps <= 3 &&
"Too many operands");
901 Ops[2] =
N->getOperand(2);
909 ReplaceValueWith(
SDValue(
N, 0), Res);
928 unsigned Opcode =
N->getOpcode();
931 SDValue Op1Promoted, Op2Promoted;
933 Op1Promoted = GetPromotedInteger(Op1);
934 Op2Promoted = ZExtPromotedInteger(Op2);
936 Op1Promoted = ZExtPromotedInteger(Op1);
937 Op2Promoted = ZExtPromotedInteger(Op2);
939 Op1Promoted = SExtPromotedInteger(Op1);
940 Op2Promoted = SExtPromotedInteger(Op2);
973 "addition, subtraction or left shift");
976 unsigned SHLAmount = NewBits - OldBits;
986 DAG.
getNode(Opcode, dl, PromotedType, Op1Promoted, Op2Promoted);
987 return DAG.
getNode(ShiftOp, dl, PromotedType, Result, ShiftAmount);
996 DAG.
getNode(AddOp, dl, PromotedType, Op1Promoted, Op2Promoted);
1005 SDValue Op1Promoted, Op2Promoted;
1011 Op1Promoted = SExtPromotedInteger(
N->getOperand(0));
1012 Op2Promoted = SExtPromotedInteger(
N->getOperand(1));
1014 Op1Promoted = ZExtPromotedInteger(
N->getOperand(0));
1015 Op2Promoted = ZExtPromotedInteger(
N->getOperand(1));
1017 EVT OldType =
N->getOperand(0).getValueType();
1031 Op2Promoted,
N->getOperand(2));
1033 return DAG.
getNode(ShiftOp, dl, PromotedType, Result,
1036 return DAG.
getNode(
N->getOpcode(), dl, PromotedType, Op1Promoted, Op2Promoted,
1041 unsigned SatW,
bool Signed,
1044 EVT VT = V.getValueType();
1071 EVT VT =
LHS.getValueType();
1089 assert(Res &&
"Expanding DIVFIX with wide type failed?");
1095 "Tried to saturate to more than the original type?");
1104 SDValue Op1Promoted, Op2Promoted;
1110 Op1Promoted = SExtPromotedInteger(
N->getOperand(0));
1111 Op2Promoted = SExtPromotedInteger(
N->getOperand(1));
1113 Op1Promoted = ZExtPromotedInteger(
N->getOperand(0));
1114 Op2Promoted = ZExtPromotedInteger(
N->getOperand(1));
1117 unsigned Scale =
N->getConstantOperandVal(2);
1126 N->getValueType(0).getScalarSizeInBits();
1131 SDValue Res = DAG.
getNode(
N->getOpcode(), dl, PromotedType, Op1Promoted,
1132 Op2Promoted,
N->getOperand(2));
1142 Op2Promoted, Scale, DAG)) {
1145 N->getValueType(0).getScalarSizeInBits(),
1153 N->getValueType(0).getScalarSizeInBits());
1156SDValue DAGTypeLegalizer::PromoteIntRes_SADDSUBO(
SDNode *
N,
unsigned ResNo) {
1158 return PromoteIntRes_Overflow(
N);
1162 SDValue LHS = SExtPromotedInteger(
N->getOperand(0));
1163 SDValue RHS = SExtPromotedInteger(
N->getOperand(1));
1164 EVT OVT =
N->getOperand(0).getValueType();
1165 EVT NVT =
LHS.getValueType();
1180 ReplaceValueWith(
SDValue(
N, 1), Ofl);
1188 SDValue LHS = GetPromotedInteger(
N->getOperand(1));
1189 SDValue RHS = GetPromotedInteger(
N->getOperand(2));
1191 unsigned Opcode =
N->getOpcode();
1192 if (Opcode == ISD::VP_SELECT || Opcode == ISD::VP_MERGE)
1199 SDValue LHS = GetPromotedInteger(
N->getOperand(2));
1200 SDValue RHS = GetPromotedInteger(
N->getOperand(3));
1202 LHS.getValueType(),
N->getOperand(0),
1203 N->getOperand(1), LHS, RHS,
N->getOperand(4));
1207 unsigned OpNo =
N->isStrictFPOpcode() ? 1 : 0;
1208 EVT InVT =
N->getOperand(OpNo).getValueType();
1211 EVT SVT = getSetCCResultType(InVT);
1219 SVT = getSetCCResultType(InVT);
1227 assert(SVT.
isVector() ==
N->getOperand(OpNo).getValueType().isVector() &&
1228 "Vector compare must return a vector result!");
1232 if (
N->isStrictFPOpcode()) {
1234 SDValue Opers[] = {
N->getOperand(0),
N->getOperand(1),
1235 N->getOperand(2),
N->getOperand(3)};
1236 SetCC = DAG.
getNode(
N->getOpcode(), dl, VTs, Opers,
N->getFlags());
1241 SetCC = DAG.
getNode(
N->getOpcode(), dl, SVT,
N->getOperand(0),
1242 N->getOperand(1),
N->getOperand(2),
N->getFlags());
1258 EVT VT =
N->getValueType(0);
1264 ReplaceValueWith(
SDValue(
N, 0), Res);
1269 SDValue LHS = GetPromotedInteger(
N->getOperand(0));
1272 RHS = ZExtPromotedInteger(RHS);
1273 if (
N->getOpcode() != ISD::VP_SHL)
1276 N->getOperand(2),
N->getOperand(3));
1279SDValue DAGTypeLegalizer::PromoteIntRes_SIGN_EXTEND_INREG(
SDNode *
N) {
1280 SDValue Op = GetPromotedInteger(
N->getOperand(0));
1282 Op.getValueType(),
Op,
N->getOperand(1));
1285SDValue DAGTypeLegalizer::PromoteIntRes_SimpleIntBinOp(
SDNode *
N) {
1289 SDValue LHS = GetPromotedInteger(
N->getOperand(0));
1290 SDValue RHS = GetPromotedInteger(
N->getOperand(1));
1291 if (
N->getNumOperands() == 2)
1293 assert(
N->getNumOperands() == 4 &&
"Unexpected number of operands!");
1294 assert(
N->isVPOpcode() &&
"Expected VP opcode");
1296 N->getOperand(2),
N->getOperand(3));
1301 SDValue LHS = SExtPromotedInteger(
N->getOperand(0));
1302 SDValue RHS = SExtPromotedInteger(
N->getOperand(1));
1303 if (
N->getNumOperands() == 2)
1305 assert(
N->getNumOperands() == 4 &&
"Unexpected number of operands!");
1306 assert(
N->isVPOpcode() &&
"Expected VP opcode");
1308 N->getOperand(2),
N->getOperand(3));
1313 SDValue LHS = ZExtPromotedInteger(
N->getOperand(0));
1314 SDValue RHS = ZExtPromotedInteger(
N->getOperand(1));
1315 if (
N->getNumOperands() == 2)
1317 assert(
N->getNumOperands() == 4 &&
"Unexpected number of operands!");
1318 assert(
N->isVPOpcode() &&
"Expected VP opcode");
1320 N->getOperand(2),
N->getOperand(3));
1326 SDValue LHS = SExtOrZExtPromotedInteger(
N->getOperand(0));
1327 SDValue RHS = SExtOrZExtPromotedInteger(
N->getOperand(1));
1329 LHS.getValueType(), LHS, RHS);
1334 SDValue LHS = SExtPromotedInteger(
N->getOperand(0));
1337 RHS = ZExtPromotedInteger(RHS);
1338 if (
N->getOpcode() != ISD::VP_ASHR)
1341 N->getOperand(2),
N->getOperand(3));
1346 SDValue LHS = ZExtPromotedInteger(
N->getOperand(0));
1349 RHS = ZExtPromotedInteger(RHS);
1350 if (
N->getOpcode() != ISD::VP_LSHR)
1353 N->getOperand(2),
N->getOperand(3));
1359 ReplaceValueWith(
SDValue(
N, 0), Res);
1364 SDValue Hi = GetPromotedInteger(
N->getOperand(0));
1365 SDValue Lo = GetPromotedInteger(
N->getOperand(1));
1368 Amt = ZExtPromotedInteger(Amt);
1372 EVT OldVT =
N->getOperand(0).getValueType();
1373 EVT VT =
Lo.getValueType();
1374 unsigned Opcode =
N->getOpcode();
1388 if (NewBits >= (2 * OldBits) && !isa<ConstantSDNode>(Amt) &&
1413SDValue DAGTypeLegalizer::PromoteIntRes_VPFunnelShift(
SDNode *
N) {
1414 SDValue Hi = GetPromotedInteger(
N->getOperand(0));
1415 SDValue Lo = GetPromotedInteger(
N->getOperand(1));
1420 Amt = ZExtPromotedInteger(Amt);
1424 EVT OldVT =
N->getOperand(0).getValueType();
1425 EVT VT =
Lo.getValueType();
1426 unsigned Opcode =
N->getOpcode();
1427 bool IsFSHR = Opcode == ISD::VP_FSHR;
1432 Amt = DAG.
getNode(ISD::VP_UREM,
DL, AmtVT, Amt,
1440 if (NewBits >= (2 * OldBits) && !isa<ConstantSDNode>(Amt) &&
1443 Hi = DAG.
getNode(ISD::VP_SHL,
DL, VT,
Hi, HiShift, Mask, EVL);
1447 Res = DAG.
getNode(IsFSHR ? ISD::VP_LSHR : ISD::VP_SHL,
DL, VT, Res, Amt,
1450 Res = DAG.
getNode(ISD::VP_LSHR,
DL, VT, Res, HiShift, Mask, EVL);
1456 Lo = DAG.
getNode(ISD::VP_SHL,
DL, VT,
Lo, ShiftOffset, Mask, EVL);
1461 Amt = DAG.
getNode(ISD::VP_ADD,
DL, AmtVT, Amt, ShiftOffset, Mask, EVL);
1479 Res = GetPromotedInteger(InOp);
1486 "Dst and Src must have the same number of elements");
1488 "Promoted vector type must be a power of two");
1491 GetSplitVector(InOp, EOp1, EOp2);
1499 assert(
N->getOpcode() == ISD::VP_TRUNCATE &&
1500 "Expected VP_TRUNCATE opcode");
1501 SDValue MaskLo, MaskHi, EVLLo, EVLHi;
1502 std::tie(MaskLo, MaskHi) = SplitMask(
N->getOperand(1));
1503 std::tie(EVLLo, EVLHi) =
1504 DAG.
SplitEVL(
N->getOperand(2),
N->getValueType(0), dl);
1505 EOp1 = DAG.
getNode(ISD::VP_TRUNCATE, dl, HalfNVT, EOp1, MaskLo, EVLLo);
1506 EOp2 = DAG.
getNode(ISD::VP_TRUNCATE, dl, HalfNVT, EOp2, MaskHi, EVLHi);
1513 SDValue WideInOp = GetWidenedVector(InOp);
1518 N->getValueType(0).getScalarType(), NumElem);
1533 if (
N->getOpcode() == ISD::VP_TRUNCATE)
1534 return DAG.
getNode(ISD::VP_TRUNCATE, dl, NVT, Res,
N->getOperand(1),
1539SDValue DAGTypeLegalizer::PromoteIntRes_UADDSUBO(
SDNode *
N,
unsigned ResNo) {
1541 return PromoteIntRes_Overflow(
N);
1545 SDValue LHS = ZExtPromotedInteger(
N->getOperand(0));
1546 SDValue RHS = ZExtPromotedInteger(
N->getOperand(1));
1547 EVT OVT =
N->getOperand(0).getValueType();
1548 EVT NVT =
LHS.getValueType();
1562 ReplaceValueWith(
SDValue(
N, 1), Ofl);
1573 return PromoteIntRes_Overflow(
N);
1585 SDValue LHS = SExtPromotedInteger(
N->getOperand(0));
1586 SDValue RHS = SExtPromotedInteger(
N->getOperand(1));
1588 EVT ValueVTs[] = {
LHS.getValueType(),
N->getValueType(1)};
1592 LHS, RHS,
N->getOperand(2));
1602 assert(ResNo == 1 &&
"Don't know how to promote other results yet.");
1603 return PromoteIntRes_Overflow(
N);
1607 EVT OVT =
N->getValueType(0);
1620 SDValue Op0 = SExtPromotedInteger(
N->getOperand(0));
1624SDValue DAGTypeLegalizer::PromoteIntRes_XMULO(
SDNode *
N,
unsigned ResNo) {
1627 return PromoteIntRes_Overflow(
N);
1631 EVT SmallVT =
LHS.getValueType();
1638 LHS = SExtPromotedInteger(LHS);
1639 RHS = SExtPromotedInteger(RHS);
1641 LHS = ZExtPromotedInteger(LHS);
1642 RHS = ZExtPromotedInteger(RHS);
1673 ReplaceValueWith(
SDValue(
N, 1), Overflow);
1679 N->getValueType(0)));
1685 const APInt &MulImm =
N->getConstantOperandAPInt(0);
1692 EVT VT =
N->getValueType(0);
1700 for (
unsigned i = 0; i < NumRegs; ++i) {
1701 Parts[i] = DAG.
getVAArg(RegVT, dl, Chain,
Ptr,
N->getOperand(2),
1702 N->getConstantOperandVal(3));
1708 std::reverse(Parts.begin(), Parts.end());
1713 for (
unsigned i = 1; i < NumRegs; ++i) {
1724 ReplaceValueWith(
SDValue(
N, 1), Chain);
1737bool DAGTypeLegalizer::PromoteIntegerOperand(
SDNode *
N,
unsigned OpNo) {
1741 if (CustomLowerNode(
N,
N->getOperand(OpNo).getValueType(),
false)) {
1746 switch (
N->getOpcode()) {
1749 dbgs() <<
"PromoteIntegerOperand Op #" << OpNo <<
": ";
1750 N->dump(&DAG);
dbgs() <<
"\n";
1756 Res = PromoteIntOp_ATOMIC_STORE(cast<AtomicSDNode>(
N));
1759 case ISD::BR_CC: Res = PromoteIntOp_BR_CC(
N, OpNo);
break;
1760 case ISD::BRCOND: Res = PromoteIntOp_BRCOND(
N, OpNo);
break;
1766 Res = PromoteIntOp_INSERT_VECTOR_ELT(
N, OpNo);
1770 Res = PromoteIntOp_ScalarOp(
N);
1773 case ISD::SELECT: Res = PromoteIntOp_SELECT(
N, OpNo);
break;
1776 case ISD::SETCC: Res = PromoteIntOp_SETCC(
N, OpNo);
break;
1778 case ISD::VP_SIGN_EXTEND: Res = PromoteIntOp_VP_SIGN_EXTEND(
N);
break;
1779 case ISD::VP_SINT_TO_FP:
1782 case ISD::STORE: Res = PromoteIntOp_STORE(cast<StoreSDNode>(
N),
1784 case ISD::MSTORE: Res = PromoteIntOp_MSTORE(cast<MaskedStoreSDNode>(
N),
1786 case ISD::MLOAD: Res = PromoteIntOp_MLOAD(cast<MaskedLoadSDNode>(
N),
1788 case ISD::MGATHER: Res = PromoteIntOp_MGATHER(cast<MaskedGatherSDNode>(
N),
1790 case ISD::MSCATTER: Res = PromoteIntOp_MSCATTER(cast<MaskedScatterSDNode>(
N),
1792 case ISD::VP_TRUNCATE:
1796 case ISD::VP_UINT_TO_FP:
1800 case ISD::VP_ZERO_EXTEND: Res = PromoteIntOp_VP_ZERO_EXTEND(
N);
break;
1808 case ISD::ROTR: Res = PromoteIntOp_Shift(
N);
break;
1811 case ISD::FSHR: Res = PromoteIntOp_FunnelShift(
N);
break;
1842 case ISD::VP_REDUCE_ADD:
1843 case ISD::VP_REDUCE_MUL:
1844 case ISD::VP_REDUCE_AND:
1845 case ISD::VP_REDUCE_OR:
1846 case ISD::VP_REDUCE_XOR:
1847 case ISD::VP_REDUCE_SMAX:
1848 case ISD::VP_REDUCE_SMIN:
1849 case ISD::VP_REDUCE_UMAX:
1850 case ISD::VP_REDUCE_UMIN:
1851 Res = PromoteIntOp_VP_REDUCE(
N, OpNo);
1856 Res = PromoteIntOp_STACKMAP(
N, OpNo);
1859 Res = PromoteIntOp_PATCHPOINT(
N, OpNo);
1861 case ISD::EXPERIMENTAL_VP_STRIDED_LOAD:
1862 case ISD::EXPERIMENTAL_VP_STRIDED_STORE:
1863 Res = PromoteIntOp_VP_STRIDED(
N, OpNo);
1868 if (!Res.getNode())
return false;
1872 if (Res.getNode() ==
N)
1875 const bool IsStrictFp =
N->isStrictFPOpcode();
1876 assert(Res.getValueType() ==
N->getValueType(0) &&
1877 N->getNumValues() == (IsStrictFp ? 2 : 1) &&
1878 "Invalid operand expansion");
1882 ReplaceValueWith(
SDValue(
N, 0), Res);
1891void DAGTypeLegalizer::PromoteSetCCOperands(
SDValue &LHS,
SDValue &RHS,
1900 LHS = SExtPromotedInteger(LHS);
1901 RHS = SExtPromotedInteger(RHS);
1906 "Unknown integer comparison!");
1908 SDValue OpL = GetPromotedInteger(LHS);
1909 SDValue OpR = GetPromotedInteger(RHS);
1915 unsigned OpLEffectiveBits =
1917 unsigned OpREffectiveBits =
1919 if (OpLEffectiveBits <=
LHS.getScalarValueSizeInBits() &&
1920 OpREffectiveBits <=
RHS.getScalarValueSizeInBits()) {
1927 LHS = SExtPromotedInteger(LHS);
1928 RHS = SExtPromotedInteger(RHS);
1939 if (OpLEffectiveBits <=
LHS.getScalarValueSizeInBits() &&
1940 OpREffectiveBits <=
RHS.getScalarValueSizeInBits()) {
1947 LHS = ZExtPromotedInteger(LHS);
1948 RHS = ZExtPromotedInteger(RHS);
1952 SDValue Op = GetPromotedInteger(
N->getOperand(0));
1957 SDValue Op1 = GetPromotedInteger(
N->getOperand(1));
1959 N->getChain(), Op1,
N->getBasePtr(),
N->getMemOperand());
1965 return CreateStackStoreLoad(
N->getOperand(0),
N->getValueType(0));
1968SDValue DAGTypeLegalizer::PromoteIntOp_BR_CC(
SDNode *
N,
unsigned OpNo) {
1969 assert(OpNo == 2 &&
"Don't know how to promote this operand!");
1973 PromoteSetCCOperands(LHS, RHS, cast<CondCodeSDNode>(
N->getOperand(1))->get());
1978 N->getOperand(1), LHS, RHS,
N->getOperand(4)),
1982SDValue DAGTypeLegalizer::PromoteIntOp_BRCOND(
SDNode *
N,
unsigned OpNo) {
1983 assert(OpNo == 1 &&
"only know how to promote condition");
1986 SDValue Cond = PromoteTargetBoolean(
N->getOperand(1), MVT::Other);
1990 N->getOperand(2)), 0);
1995 EVT OVT =
N->getOperand(0).getValueType();
1996 SDValue Lo = ZExtPromotedInteger(
N->getOperand(0));
1997 SDValue Hi = GetPromotedInteger(
N->getOperand(1));
1998 assert(
Lo.getValueType() ==
N->getValueType(0) &&
"Operand over promoted?");
2011 EVT VecVT =
N->getValueType(0);
2014 "Legal vector of one illegal element?");
2019 assert(
N->getOperand(0).getValueSizeInBits() >=
2020 N->getValueType(0).getScalarSizeInBits() &&
2021 "Type of inserted value narrower than vector element type!");
2024 for (
unsigned i = 0; i < NumElts; ++i)
2025 NewOps.
push_back(GetPromotedInteger(
N->getOperand(i)));
2030SDValue DAGTypeLegalizer::PromoteIntOp_INSERT_VECTOR_ELT(
SDNode *
N,
2037 assert(
N->getOperand(1).getValueSizeInBits() >=
2038 N->getValueType(0).getScalarSizeInBits() &&
2039 "Type of inserted value narrower than vector element type!");
2041 GetPromotedInteger(
N->getOperand(1)),
2046 assert(OpNo == 2 &&
"Different operand and result vector types?");
2052 N->getOperand(1),
Idx), 0);
2059 GetPromotedInteger(
N->getOperand(0))), 0);
2062SDValue DAGTypeLegalizer::PromoteIntOp_SELECT(
SDNode *
N,
unsigned OpNo) {
2063 assert(OpNo == 0 &&
"Only know how to promote the condition!");
2065 EVT OpTy =
N->getOperand(1).getValueType();
2068 if (
SDValue Res = WidenVSELECTMask(
N))
2070 Res,
N->getOperand(1),
N->getOperand(2));
2074 Cond = PromoteTargetBoolean(
Cond, OpVT);
2077 N->getOperand(2)), 0);
2080SDValue DAGTypeLegalizer::PromoteIntOp_SELECT_CC(
SDNode *
N,
unsigned OpNo) {
2081 assert(OpNo == 0 &&
"Don't know how to promote this operand!");
2085 PromoteSetCCOperands(LHS, RHS, cast<CondCodeSDNode>(
N->getOperand(4))->get());
2089 N->getOperand(3),
N->getOperand(4)), 0);
2092SDValue DAGTypeLegalizer::PromoteIntOp_SETCC(
SDNode *
N,
unsigned OpNo) {
2093 assert(OpNo == 0 &&
"Don't know how to promote this operand!");
2097 PromoteSetCCOperands(LHS, RHS, cast<CondCodeSDNode>(
N->getOperand(2))->get());
2103 assert(
N->getOpcode() == ISD::VP_SETCC &&
"Expected VP_SETCC opcode");
2106 N->getOperand(3),
N->getOperand(4)),
2112 ZExtPromotedInteger(
N->getOperand(1))), 0);
2117 ZExtPromotedInteger(
N->getOperand(2))), 0);
2121 SDValue Op = GetPromotedInteger(
N->getOperand(0));
2128SDValue DAGTypeLegalizer::PromoteIntOp_VP_SIGN_EXTEND(
SDNode *
N) {
2130 EVT VT =
N->getValueType(0);
2131 SDValue Op = GetPromotedInteger(
N->getOperand(0));
2133 Op = DAG.
getNode(ISD::VP_ZERO_EXTEND, dl, VT,
Op,
N->getOperand(1),
2141 return DAG.
getNode(ISD::VP_ASHR, dl, VT, Shl, ShAmt,
N->getOperand(1),
2146 if (
N->getOpcode() == ISD::VP_SINT_TO_FP)
2148 SExtPromotedInteger(
N->getOperand(0)),
2149 N->getOperand(1),
N->getOperand(2)),
2152 SExtPromotedInteger(
N->getOperand(0))), 0);
2155SDValue DAGTypeLegalizer::PromoteIntOp_STRICT_SINT_TO_FP(
SDNode *
N) {
2157 SExtPromotedInteger(
N->getOperand(1))), 0);
2165 SDValue Val = GetPromotedInteger(
N->getValue());
2169 N->getMemoryVT(),
N->getMemOperand());
2180 Mask = PromoteTargetBoolean(Mask, DataVT);
2186 assert(OpNo == 1 &&
"Unexpected operand for promotion");
2187 DataOp = GetPromotedInteger(DataOp);
2190 N->getOffset(), Mask,
N->getMemoryVT(),
2191 N->getMemOperand(),
N->getAddressingMode(),
2192 true,
N->isCompressingStore());
2197 assert(OpNo == 3 &&
"Only know how to promote the mask!");
2198 EVT DataVT =
N->getValueType(0);
2199 SDValue Mask = PromoteTargetBoolean(
N->getOperand(OpNo), DataVT);
2201 NewOps[OpNo] =
Mask;
2218 EVT DataVT =
N->getValueType(0);
2219 NewOps[OpNo] = PromoteTargetBoolean(
N->getOperand(OpNo), DataVT);
2220 }
else if (OpNo == 4) {
2222 if (
N->isIndexSigned())
2224 NewOps[OpNo] = SExtPromotedInteger(
N->getOperand(OpNo));
2226 NewOps[OpNo] = ZExtPromotedInteger(
N->getOperand(OpNo));
2228 NewOps[OpNo] = GetPromotedInteger(
N->getOperand(OpNo));
2242 bool TruncateStore =
N->isTruncatingStore();
2247 EVT DataVT =
N->getValue().getValueType();
2248 NewOps[OpNo] = PromoteTargetBoolean(
N->getOperand(OpNo), DataVT);
2249 }
else if (OpNo == 4) {
2251 if (
N->isIndexSigned())
2253 NewOps[OpNo] = SExtPromotedInteger(
N->getOperand(OpNo));
2255 NewOps[OpNo] = ZExtPromotedInteger(
N->getOperand(OpNo));
2257 NewOps[OpNo] = GetPromotedInteger(
N->getOperand(OpNo));
2258 TruncateStore =
true;
2262 SDLoc(
N), NewOps,
N->getMemOperand(),
2263 N->getIndexType(), TruncateStore);
2267 SDValue Op = GetPromotedInteger(
N->getOperand(0));
2268 if (
N->getOpcode() == ISD::VP_TRUNCATE)
2270 N->getOperand(1),
N->getOperand(2));
2275 if (
N->getOpcode() == ISD::VP_UINT_TO_FP)
2277 ZExtPromotedInteger(
N->getOperand(0)),
2278 N->getOperand(1),
N->getOperand(2)),
2281 ZExtPromotedInteger(
N->getOperand(0))), 0);
2284SDValue DAGTypeLegalizer::PromoteIntOp_STRICT_UINT_TO_FP(
SDNode *
N) {
2286 ZExtPromotedInteger(
N->getOperand(1))), 0);
2291 SDValue Op = GetPromotedInteger(
N->getOperand(0));
2296SDValue DAGTypeLegalizer::PromoteIntOp_VP_ZERO_EXTEND(
SDNode *
N) {
2298 EVT VT =
N->getValueType(0);
2299 SDValue Op = GetPromotedInteger(
N->getOperand(0));
2301 Op = DAG.
getNode(ISD::VP_ZERO_EXTEND, dl, VT,
Op,
N->getOperand(1),
2304 N->getOperand(0).getScalarValueSizeInBits());
2306 N->getOperand(1),
N->getOperand(2));
2309SDValue DAGTypeLegalizer::PromoteIntOp_ADDSUBO_CARRY(
SDNode *
N,
unsigned OpNo) {
2310 assert(OpNo == 2 &&
"Don't know how to promote this operand!");
2317 Carry = PromoteTargetBoolean(Carry,
LHS.getValueType());
2323 SDValue Op2 = ZExtPromotedInteger(
N->getOperand(2));
2328SDValue DAGTypeLegalizer::PromoteIntOp_FRAMERETURNADDR(
SDNode *
N) {
2330 SDValue Op = ZExtPromotedInteger(
N->getOperand(0));
2335 bool IsStrict =
N->isStrictFPOpcode();
2347 SDValue Op = SExtPromotedInteger(
N->getOperand(1));
2357 unsigned OpOffset = IsStrict ? 1 : 0;
2360 N->getOperand(1 + OpOffset).getValueType().getSizeInBits() &&
2361 "POWI exponent should match with sizeof(int) when doing the libcall.");
2364 SDValue Ops[2] = {
N->getOperand(0 + OpOffset),
N->getOperand(1 + OpOffset)};
2365 std::pair<SDValue, SDValue> Tmp = TLI.
makeLibCall(
2366 DAG, LC,
N->getValueType(0), Ops, CallOptions,
SDLoc(
N), Chain);
2367 ReplaceValueWith(
SDValue(
N, 0), Tmp.first);
2369 ReplaceValueWith(
SDValue(
N, 1), Tmp.second);
2374 switch (
N->getOpcode()) {
2382 case ISD::VP_REDUCE_ADD:
2383 case ISD::VP_REDUCE_MUL:
2384 case ISD::VP_REDUCE_AND:
2385 case ISD::VP_REDUCE_OR:
2386 case ISD::VP_REDUCE_XOR:
2390 case ISD::VP_REDUCE_SMAX:
2391 case ISD::VP_REDUCE_SMIN:
2395 case ISD::VP_REDUCE_UMAX:
2396 case ISD::VP_REDUCE_UMIN:
2406 return GetPromotedInteger(V);
2408 return SExtPromotedInteger(V);
2410 return ZExtPromotedInteger(V);
2416 SDValue Op = PromoteIntOpVectorReduction(
N,
N->getOperand(0));
2418 EVT OrigEltVT =
N->getOperand(0).getValueType().getVectorElementType();
2419 EVT InVT =
Op.getValueType();
2421 EVT ResVT =
N->getValueType(0);
2422 unsigned Opcode =
N->getOpcode();
2442 Op = ZExtPromotedInteger(
N->getOperand(0));
2445 Op = SExtPromotedInteger(
N->getOperand(0));
2461 Op = ZExtPromotedInteger(
N->getOperand(0));
2464 Op = SExtPromotedInteger(
N->getOperand(0));
2478SDValue DAGTypeLegalizer::PromoteIntOp_VP_REDUCE(
SDNode *
N,
unsigned OpNo) {
2485 NewOps[2] = PromoteTargetBoolean(
Op,
N->getOperand(1).getValueType());
2489 assert(OpNo == 1 &&
"Unexpected operand for promotion");
2491 Op = PromoteIntOpVectorReduction(
N,
Op);
2495 EVT VT =
N->getValueType(0);
2496 EVT EltVT =
Op.getValueType().getScalarType();
2511 SDValue Op = ZExtPromotedInteger(
N->getOperand(1));
2515SDValue DAGTypeLegalizer::PromoteIntOp_STACKMAP(
SDNode *
N,
unsigned OpNo) {
2518 SDValue Operand =
N->getOperand(OpNo);
2524SDValue DAGTypeLegalizer::PromoteIntOp_PATCHPOINT(
SDNode *
N,
unsigned OpNo) {
2527 SDValue Operand =
N->getOperand(OpNo);
2533SDValue DAGTypeLegalizer::PromoteIntOp_VP_STRIDED(
SDNode *
N,
unsigned OpNo) {
2534 assert((
N->getOpcode() == ISD::EXPERIMENTAL_VP_STRIDED_LOAD && OpNo == 3) ||
2535 (
N->getOpcode() == ISD::EXPERIMENTAL_VP_STRIDED_STORE && OpNo == 4));
2538 NewOps[OpNo] = SExtPromotedInteger(
N->getOperand(OpNo));
2551void DAGTypeLegalizer::ExpandIntegerResult(
SDNode *
N,
unsigned ResNo) {
2558 if (CustomLowerNode(
N,
N->getValueType(ResNo),
true))
2561 switch (
N->getOpcode()) {
2564 dbgs() <<
"ExpandIntegerResult #" << ResNo <<
": ";
2565 N->dump(&DAG);
dbgs() <<
"\n";
2611 case ISD::LOAD: ExpandIntRes_LOAD(cast<LoadSDNode>(
N),
Lo,
Hi);
break;
2637 std::pair<SDValue, SDValue> Tmp = ExpandAtomic(
N);
2638 SplitInteger(Tmp.first,
Lo,
Hi);
2639 ReplaceValueWith(
SDValue(
N, 1), Tmp.second);
2647 N->getOperand(0),
N->getOperand(1),
N->getOperand(2),
N->getOperand(3),
2656 SplitInteger(Tmp,
Lo,
Hi);
2727 ExpandIntRes_Rotate(
N,
Lo,
Hi);
2732 ExpandIntRes_FunnelShift(
N,
Lo,
Hi);
2736 ExpandIntRes_VSCALE(
N,
Lo,
Hi);
2746std::pair <SDValue, SDValue> DAGTypeLegalizer::ExpandAtomic(
SDNode *
Node) {
2747 unsigned Opc =
Node->getOpcode();
2753 EVT RetVT =
Node->getValueType(0);
2761 assert(LC != RTLIB::UNKNOWN_LIBCALL &&
2762 "Unexpected atomic op or value type!");
2766 Node->getOperand(0));
2771void DAGTypeLegalizer::ExpandShiftByConstant(
SDNode *
N,
const APInt &Amt,
2776 GetExpandedInteger(
N->getOperand(0), InL, InH);
2787 unsigned VTBits =
N->getValueType(0).getSizeInBits();
2789 EVT ShTy =
N->getOperand(1).getValueType();
2792 if (Amt.
uge(VTBits)) {
2794 }
else if (Amt.
ugt(NVTBits)) {
2798 }
else if (Amt == NVTBits) {
2813 if (Amt.
uge(VTBits)) {
2815 }
else if (Amt.
ugt(NVTBits)) {
2819 }
else if (Amt == NVTBits) {
2834 if (Amt.
uge(VTBits)) {
2837 }
else if (Amt.
ugt(NVTBits)) {
2842 }
else if (Amt == NVTBits) {
2860bool DAGTypeLegalizer::
2868 "Expanded integer type size not a power of two!");
2875 if (((Known.
Zero|Known.
One) & HighBitMask) == 0)
2880 GetExpandedInteger(
N->getOperand(0), InL, InH);
2889 switch (
N->getOpcode()) {
2917 switch (
N->getOpcode()) {
2934 Lo = DAG.
getNode(
N->getOpcode(), dl, NVT, InL, Amt);
2947bool DAGTypeLegalizer::
2954 "Expanded integer type size not a power of two!");
2959 GetExpandedInteger(
N->getOperand(0), InL, InH);
2971 switch (
N->getOpcode()) {
2986 DAG.
getSelect(dl, NVT, isShort, HiS, HiL));
3002 DAG.
getSelect(dl, NVT, isShort, LoS, LoL));
3018 DAG.
getSelect(dl, NVT, isShort, LoS, LoL));
3039void DAGTypeLegalizer::ExpandIntRes_MINMAX(
SDNode *
N,
3048 unsigned NumBits =
N->getValueType(0).getScalarSizeInBits();
3049 unsigned NumHalfBits = NumBits / 2;
3052 SDValue LHSL, LHSH, RHSL, RHSH;
3053 GetExpandedInteger(LHS, LHSL, LHSH);
3054 GetExpandedInteger(RHS, RHSL, RHSH);
3067 SDValue LHSL, LHSH, RHSL, RHSH;
3068 GetExpandedInteger(LHS, LHSL, LHSH);
3069 GetExpandedInteger(RHS, RHSL, RHSH);
3071 EVT CCT = getSetCCResultType(NVT);
3080 Hi = DAG.
getNode(
N->getOpcode(),
DL, NVT, {LHSH, RHSH});
3084 const APInt *RHSVal =
nullptr;
3085 if (
auto *RHSConst = dyn_cast<ConstantSDNode>(RHS))
3086 RHSVal = &RHSConst->getAPIntValue();
3093 SDValue LHSL, LHSH, RHSL, RHSH;
3094 GetExpandedInteger(LHS, LHSL, LHSH);
3095 GetExpandedInteger(RHS, RHSL, RHSH);
3097 EVT CCT = getSetCCResultType(NVT);
3103 Hi = DAG.
getNode(
N->getOpcode(),
DL, NVT, {LHSH, RHSH});
3122 switch (
N->getOpcode()) {
3149 EVT VT =
N->getValueType(0);
3150 EVT CCT = getSetCCResultType(VT);
3153 SplitInteger(Result,
Lo,
Hi);
3156void DAGTypeLegalizer::ExpandIntRes_ADDSUB(
SDNode *
N,
3160 SDValue LHSL, LHSH, RHSL, RHSH;
3161 GetExpandedInteger(
N->getOperand(0), LHSL, LHSH);
3162 GetExpandedInteger(
N->getOperand(1), RHSL, RHSH);
3165 SDValue LoOps[2] = { LHSL, RHSL };
3166 SDValue HiOps[3] = { LHSH, RHSH };
3175 HiOps[2] =
Lo.getValue(1);
3181 HiOps[2] =
Lo.getValue(1);
3203 HiOps[2] =
Lo.getValue(1);
3207 HiOps[2] =
Lo.getValue(1);
3220 EVT OvfVT = getSetCCResultType(NVT);
3260 Cmp = DAG.
getSetCC(dl, getSetCCResultType(NVT), LoOps[0],
3263 Cmp = DAG.
getSetCC(dl, getSetCCResultType(NVT), LoOps[0],
3266 Cmp = DAG.
getSetCC(dl, getSetCCResultType(NVT),
Lo, LoOps[0],
3284 DAG.
getSetCC(dl, getSetCCResultType(LoOps[0].getValueType()),
3298void DAGTypeLegalizer::ExpandIntRes_ADDSUBC(
SDNode *
N,
3301 SDValue LHSL, LHSH, RHSL, RHSH;
3303 GetExpandedInteger(
N->getOperand(0), LHSL, LHSH);
3304 GetExpandedInteger(
N->getOperand(1), RHSL, RHSH);
3306 SDValue LoOps[2] = { LHSL, RHSL };
3307 SDValue HiOps[3] = { LHSH, RHSH };
3311 HiOps[2] =
Lo.getValue(1);
3315 HiOps[2] =
Lo.getValue(1);
3321 ReplaceValueWith(
SDValue(
N, 1),
Hi.getValue(1));
3324void DAGTypeLegalizer::ExpandIntRes_ADDSUBE(
SDNode *
N,
3327 SDValue LHSL, LHSH, RHSL, RHSH;
3329 GetExpandedInteger(
N->getOperand(0), LHSL, LHSH);
3330 GetExpandedInteger(
N->getOperand(1), RHSL, RHSH);
3332 SDValue LoOps[3] = { LHSL, RHSL,
N->getOperand(2) };
3333 SDValue HiOps[3] = { LHSH, RHSH };
3335 Lo = DAG.
getNode(
N->getOpcode(), dl, VTList, LoOps);
3336 HiOps[2] =
Lo.getValue(1);
3337 Hi = DAG.
getNode(
N->getOpcode(), dl, VTList, HiOps);
3341 ReplaceValueWith(
SDValue(
N, 1),
Hi.getValue(1));
3344void DAGTypeLegalizer::ExpandIntRes_UADDSUBO(
SDNode *
N,
3352 unsigned CarryOp, NoCarryOp;
3354 switch(
N->getOpcode()) {
3374 SDValue LHSL, LHSH, RHSL, RHSH;
3375 GetExpandedInteger(LHS, LHSL, LHSH);
3376 GetExpandedInteger(RHS, RHSL, RHSH);
3378 SDValue LoOps[2] = { LHSL, RHSL };
3379 SDValue HiOps[3] = { LHSH, RHSH };
3381 Lo = DAG.
getNode(
N->getOpcode(), dl, VTList, LoOps);
3382 HiOps[2] =
Lo.getValue(1);
3383 Hi = DAG.
getNode(CarryOp, dl, VTList, HiOps);
3385 Ovf =
Hi.getValue(1);
3390 SplitInteger(Sum,
Lo,
Hi);
3401 DAG.
getSetCC(dl,
N->getValueType(1), LHS,
3412 ReplaceValueWith(
SDValue(
N, 1), Ovf);
3418 SDValue LHSL, LHSH, RHSL, RHSH;
3420 GetExpandedInteger(
N->getOperand(0), LHSL, LHSH);
3421 GetExpandedInteger(
N->getOperand(1), RHSL, RHSH);
3423 SDValue LoOps[3] = { LHSL, RHSL,
N->getOperand(2) };
3426 Lo = DAG.
getNode(
N->getOpcode(), dl, VTList, LoOps);
3427 HiOps[2] =
Lo.getValue(1);
3428 Hi = DAG.
getNode(
N->getOpcode(), dl, VTList, HiOps);
3432 ReplaceValueWith(
SDValue(
N, 1),
Hi.getValue(1));
3435void DAGTypeLegalizer::ExpandIntRes_SADDSUBO_CARRY(
SDNode *
N,
3438 SDValue LHSL, LHSH, RHSL, RHSH;
3440 GetExpandedInteger(
N->getOperand(0), LHSL, LHSH);
3441 GetExpandedInteger(
N->getOperand(1), RHSL, RHSH);
3447 Lo = DAG.
getNode(CarryOp, dl, VTList, { LHSL, RHSL,
N->getOperand(2) });
3448 Hi = DAG.
getNode(
N->getOpcode(), dl, VTList, { LHSH, RHSH, Lo.getValue(1) });
3452 ReplaceValueWith(
SDValue(
N, 1),
Hi.getValue(1));
3455void DAGTypeLegalizer::ExpandIntRes_ANY_EXTEND(
SDNode *
N,
3460 if (
Op.getValueType().bitsLE(NVT)) {
3467 assert(getTypeAction(
Op.getValueType()) ==
3469 "Only know how to promote this result!");
3472 "Operand over promoted?");
3474 SplitInteger(Res,
Lo,
Hi);
3478void DAGTypeLegalizer::ExpandIntRes_AssertSext(
SDNode *
N,
3481 GetExpandedInteger(
N->getOperand(0),
Lo,
Hi);
3482 EVT NVT =
Lo.getValueType();
3483 EVT EVT = cast<VTSDNode>(
N->getOperand(1))->getVT();
3487 if (NVTBits < EVTBits) {
3490 EVTBits - NVTBits)));
3500void DAGTypeLegalizer::ExpandIntRes_AssertZext(
SDNode *
N,
3503 GetExpandedInteger(
N->getOperand(0),
Lo,
Hi);
3504 EVT NVT =
Lo.getValueType();
3505 EVT EVT = cast<VTSDNode>(
N->getOperand(1))->getVT();
3509 if (NVTBits < EVTBits) {
3512 EVTBits - NVTBits)));
3520void DAGTypeLegalizer::ExpandIntRes_BITREVERSE(
SDNode *
N,
3523 GetExpandedInteger(
N->getOperand(0),
Hi,
Lo);
3528void DAGTypeLegalizer::ExpandIntRes_BSWAP(
SDNode *
N,
3531 GetExpandedInteger(
N->getOperand(0),
Hi,
Lo);
3540 GetExpandedInteger(
N->getOperand(0),
Lo,
Hi);
3541 EVT NVT =
Lo.getValueType();
3547void DAGTypeLegalizer::ExpandIntRes_Constant(
SDNode *
N,
3551 auto Constant = cast<ConstantSDNode>(
N);
3553 bool IsTarget =
Constant->isTargetOpcode();
3554 bool IsOpaque =
Constant->isOpaque();
3565 GetExpandedInteger(N0,
Lo,
Hi);
3566 EVT NVT =
Lo.getValueType();
3597 EVT VT =
N->getValueType(0);
3601 SplitInteger(Neg, NegLo, NegHi);
3609void DAGTypeLegalizer::ExpandIntRes_CTLZ(
SDNode *
N,
3613 GetExpandedInteger(
N->getOperand(0),
Lo,
Hi);
3614 EVT NVT =
Lo.getValueType();
3629void DAGTypeLegalizer::ExpandIntRes_CTPOP(
SDNode *
N,
3633 GetExpandedInteger(
N->getOperand(0),
Lo,
Hi);
3634 EVT NVT =
Lo.getValueType();
3640void DAGTypeLegalizer::ExpandIntRes_CTTZ(
SDNode *
N,
3644 GetExpandedInteger(
N->getOperand(0),
Lo,
Hi);
3645 EVT NVT =
Lo.getValueType();
3674 ReplaceValueWith(
SDValue(
N, 1), Chain);
3682 Chain =
Op.getValue(1);
3691 EVT VT =
N->getValueType(0);
3695 bool IsStrict =
N->isStrictFPOpcode();
3697 SDValue Op =
N->getOperand(IsStrict ? 1 : 0);
3699 Op = GetPromotedFloat(
Op);
3702 EVT OFPVT =
Op.getValueType();
3704 Op = GetSoftPromotedHalf(
Op);
3708 SplitInteger(
Op,
Lo,
Hi);
3712 if (
Op.getValueType() == MVT::bf16) {
3719 assert(LC != RTLIB::UNKNOWN_LIBCALL &&
"Unexpected fp-to-xint conversion!");
3722 std::pair<SDValue, SDValue> Tmp = TLI.
makeLibCall(DAG, LC, VT,
Op,
3723 CallOptions, dl, Chain);
3724 SplitInteger(Tmp.first,
Lo,
Hi);
3727 ReplaceValueWith(
SDValue(
N, 1), Tmp.second);
3733 SplitInteger(Res,
Lo,
Hi);
3739 bool IsStrict =
N->isStrictFPOpcode();
3740 SDValue Op =
N->getOperand(IsStrict ? 1 : 0);
3744 "Input type needs to be promoted!");
3746 EVT VT =
Op.getValueType();
3748 if (VT == MVT::f16) {
3758 LC = RTLIB::LROUND_F32;
3759 else if (VT == MVT::f64)
3760 LC = RTLIB::LROUND_F64;
3761 else if (VT == MVT::f80)
3762 LC = RTLIB::LROUND_F80;
3763 else if (VT == MVT::f128)
3764 LC = RTLIB::LROUND_F128;
3765 else if (VT == MVT::ppcf128)
3766 LC = RTLIB::LROUND_PPCF128;
3767 assert(LC != RTLIB::UNKNOWN_LIBCALL &&
"Unexpected lround input type!");
3771 LC = RTLIB::LRINT_F32;
3772 else if (VT == MVT::f64)
3773 LC = RTLIB::LRINT_F64;
3774 else if (VT == MVT::f80)
3775 LC = RTLIB::LRINT_F80;
3776 else if (VT == MVT::f128)
3777 LC = RTLIB::LRINT_F128;
3778 else if (VT == MVT::ppcf128)
3779 LC = RTLIB::LRINT_PPCF128;
3780 assert(LC != RTLIB::UNKNOWN_LIBCALL &&
"Unexpected lrint input type!");
3784 LC = RTLIB::LLROUND_F32;
3785 else if (VT == MVT::f64)
3786 LC = RTLIB::LLROUND_F64;
3787 else if (VT == MVT::f80)
3788 LC = RTLIB::LLROUND_F80;
3789 else if (VT == MVT::f128)
3790 LC = RTLIB::LLROUND_F128;
3791 else if (VT == MVT::ppcf128)
3792 LC = RTLIB::LLROUND_PPCF128;
3793 assert(LC != RTLIB::UNKNOWN_LIBCALL &&
"Unexpected llround input type!");
3797 LC = RTLIB::LLRINT_F32;
3798 else if (VT == MVT::f64)
3799 LC = RTLIB::LLRINT_F64;
3800 else if (VT == MVT::f80)
3801 LC = RTLIB::LLRINT_F80;
3802 else if (VT == MVT::f128)
3803 LC = RTLIB::LLRINT_F128;
3804 else if (VT == MVT::ppcf128)
3805 LC = RTLIB::LLRINT_PPCF128;
3806 assert(LC != RTLIB::UNKNOWN_LIBCALL &&
"Unexpected llrint input type!");
3810 EVT RetVT =
N->getValueType(0);
3814 std::pair<SDValue, SDValue> Tmp = TLI.
makeLibCall(DAG, LC, RetVT,
3815 Op, CallOptions, dl,
3817 SplitInteger(Tmp.first,
Lo,
Hi);
3819 if (
N->isStrictFPOpcode())
3820 ReplaceValueWith(
SDValue(
N, 1), Tmp.second);
3823void DAGTypeLegalizer::ExpandIntRes_LOAD(
LoadSDNode *
N,
3825 if (
N->isAtomic()) {
3828 EVT VT =
N->getMemoryVT();
3833 VT, VTs,
N->getOperand(0),
3834 N->getOperand(1), Zero, Zero,
N->getMemOperand());
3841 ExpandRes_NormalLoad(
N,
Lo,
Hi);
3847 EVT VT =
N->getValueType(0);
3858 if (
N->getMemoryVT().bitsLE(NVT)) {
3859 EVT MemVT =
N->getMemoryVT();
3862 N->getOriginalAlign(), MMOFlags, AAInfo);
3865 Ch =
Lo.getValue(1);
3870 unsigned LoSize =
Lo.getValueSizeInBits();