31#define DEBUG_TYPE "legalize-types"
41void DAGTypeLegalizer::PromoteIntegerResult(
SDNode *
N,
unsigned ResNo) {
46 if (CustomLowerNode(
N,
N->getValueType(ResNo),
true)) {
51 switch (
N->getOpcode()) {
54 dbgs() <<
"PromoteIntegerResult #" << ResNo <<
": ";
55 N->dump(&DAG);
dbgs() <<
"\n";
62 case ISD::VP_BITREVERSE:
65 case ISD::BSWAP: Res = PromoteIntRes_BSWAP(
N);
break;
68 case ISD::VP_CTLZ_ZERO_UNDEF:
71 case ISD::CTLZ: Res = PromoteIntRes_CTLZ(
N);
break;
74 case ISD::CTPOP: Res = PromoteIntRes_CTPOP_PARITY(
N);
break;
75 case ISD::VP_CTTZ_ZERO_UNDEF:
78 case ISD::CTTZ: Res = PromoteIntRes_CTTZ(
N);
break;
79 case ISD::VP_CTTZ_ELTS_ZERO_UNDEF:
80 case ISD::VP_CTTZ_ELTS:
81 Res = PromoteIntRes_VP_CttzElements(
N);
84 Res = PromoteIntRes_EXTRACT_VECTOR_ELT(
N);
break;
85 case ISD::LOAD: Res = PromoteIntRes_LOAD(cast<LoadSDNode>(
N));
break;
86 case ISD::MLOAD: Res = PromoteIntRes_MLOAD(cast<MaskedLoadSDNode>(
N));
88 case ISD::MGATHER: Res = PromoteIntRes_MGATHER(cast<MaskedGatherSDNode>(
N));
91 Res = PromoteIntRes_VECTOR_COMPRESS(
N);
97 Res = PromoteIntRes_Select(
N);
102 case ISD::SETCC: Res = PromoteIntRes_SETCC(
N);
break;
104 case ISD::SMAX: Res = PromoteIntRes_SExtIntBinOp(
N);
break;
106 case ISD::UMAX: Res = PromoteIntRes_UMINUMAX(
N);
break;
109 case ISD::VP_SHL: Res = PromoteIntRes_SHL(
N);
break;
111 Res = PromoteIntRes_SIGN_EXTEND_INREG(
N);
break;
113 case ISD::VP_SRA: Res = PromoteIntRes_SRA(
N);
break;
115 case ISD::VP_SRL: Res = PromoteIntRes_SRL(
N);
break;
116 case ISD::VP_TRUNCATE:
118 case ISD::UNDEF: Res = PromoteIntRes_UNDEF(
N);
break;
119 case ISD::VAARG: Res = PromoteIntRes_VAARG(
N);
break;
123 Res = PromoteIntRes_EXTRACT_SUBVECTOR(
N);
break;
125 Res = PromoteIntRes_INSERT_SUBVECTOR(
N);
break;
127 Res = PromoteIntRes_VECTOR_REVERSE(
N);
break;
129 Res = PromoteIntRes_VECTOR_SHUFFLE(
N);
break;
131 Res = PromoteIntRes_VECTOR_SPLICE(
N);
break;
134 Res = PromoteIntRes_VECTOR_INTERLEAVE_DEINTERLEAVE(
N);
137 Res = PromoteIntRes_INSERT_VECTOR_ELT(
N);
break;
139 Res = PromoteIntRes_BUILD_VECTOR(
N);
143 case ISD::EXPERIMENTAL_VP_SPLAT:
144 Res = PromoteIntRes_ScalarOp(
N);
148 Res = PromoteIntRes_CONCAT_VECTORS(
N);
break;
153 Res = PromoteIntRes_EXTEND_VECTOR_INREG(
N);
break;
156 case ISD::VP_SIGN_EXTEND:
158 case ISD::VP_ZERO_EXTEND:
161 case ISD::VP_FP_TO_SINT:
162 case ISD::VP_FP_TO_UINT:
170 Res = PromoteIntRes_FP_TO_XINT_SAT(
N);
break;
174 Res = PromoteIntRes_FP_TO_FP16_BF16(
N);
178 Res = PromoteIntRes_STRICT_FP_TO_FP16_BF16(
N);
193 case ISD::VP_MUL: Res = PromoteIntRes_SimpleIntBinOp(
N);
break;
203 case ISD::VP_SREM: Res = PromoteIntRes_SExtIntBinOp(
N);
break;
213 case ISD::VP_UREM: Res = PromoteIntRes_ZExtIntBinOp(
N);
break;
216 case ISD::SSUBO: Res = PromoteIntRes_SADDSUBO(
N, ResNo);
break;
218 case ISD::USUBO: Res = PromoteIntRes_UADDSUBO(
N, ResNo);
break;
220 case ISD::UMULO: Res = PromoteIntRes_XMULO(
N, ResNo);
break;
236 Res = PromoteIntRes_ADDSUBSHLSAT<EmptyMatchContext>(
N);
238 case ISD::VP_SADDSAT:
239 case ISD::VP_UADDSAT:
240 case ISD::VP_SSUBSAT:
241 case ISD::VP_USUBSAT:
242 Res = PromoteIntRes_ADDSUBSHLSAT<VPMatchContext>(
N);
247 Res = PromoteIntRes_CMP(
N);
260 case ISD::ABS: Res = PromoteIntRes_ABS(
N);
break;
263 Res = PromoteIntRes_Atomic0(cast<AtomicSDNode>(
N));
break;
277 Res = PromoteIntRes_Atomic1(cast<AtomicSDNode>(
N));
break;
281 Res = PromoteIntRes_AtomicCmpSwap(cast<AtomicSDNode>(
N), ResNo);
293 Res = PromoteIntRes_VECREDUCE(
N);
296 case ISD::VP_REDUCE_ADD:
297 case ISD::VP_REDUCE_MUL:
298 case ISD::VP_REDUCE_AND:
299 case ISD::VP_REDUCE_OR:
300 case ISD::VP_REDUCE_XOR:
301 case ISD::VP_REDUCE_SMAX:
302 case ISD::VP_REDUCE_SMIN:
303 case ISD::VP_REDUCE_UMAX:
304 case ISD::VP_REDUCE_UMIN:
305 Res = PromoteIntRes_VP_REDUCE(
N);
309 Res = PromoteIntRes_FREEZE(
N);
314 Res = PromoteIntRes_Rotate(
N);
319 Res = PromoteIntRes_FunnelShift(
N);
324 Res = PromoteIntRes_VPFunnelShift(
N);
328 Res = PromoteIntRes_IS_FPCLASS(
N);
331 Res = PromoteIntRes_FFREXP(
N);
336 Res = PromoteIntRes_XRINT(
N);
340 Res = PromoteIntRes_PATCHPOINT(
N);
346 SetPromotedInteger(
SDValue(
N, ResNo), Res);
351 SDValue Op = DisintegrateMERGE_VALUES(
N, ResNo);
352 return GetPromotedInteger(
Op);
357 SDValue Op = SExtPromotedInteger(
N->getOperand(0));
359 Op.getValueType(),
Op,
N->getOperand(1));
364 SDValue Op = ZExtPromotedInteger(
N->getOperand(0));
366 Op.getValueType(),
Op,
N->getOperand(1));
372 N->getMemoryVT(), ResVT,
373 N->getChain(),
N->getBasePtr(),
392 cast<AtomicSDNode>(Res)->setExtensionType(ETy);
402 SDValue Op2 = GetPromotedInteger(
N->getOperand(2));
405 N->getChain(),
N->getBasePtr(),
406 Op2,
N->getMemOperand());
417 EVT SVT = getSetCCResultType(
N->getOperand(2).getValueType());
428 N->getChain(),
N->getBasePtr(),
N->getOperand(2),
N->getOperand(3),
438 SDValue Op3 = GetPromotedInteger(
N->getOperand(3));
441 Op2 = SExtPromotedInteger(Op2);
444 Op2 = ZExtPromotedInteger(Op2);
447 Op2 = GetPromotedInteger(Op2);
456 N->getOpcode(),
SDLoc(
N),
N->getMemoryVT(), VTs,
N->getChain(),
457 N->getBasePtr(), Op2, Op3,
N->getMemOperand());
459 for (
unsigned i = 1, NumResults =
N->getNumValues(); i < NumResults; ++i)
468 EVT OutVT =
N->getValueType(0);
472 switch (getTypeAction(InVT)) {
499 BitConvertToInteger(GetScalarizedVector(InOp)));
508 GetSplitVector(
N->getOperand(0),
Lo,
Hi);
509 Lo = BitConvertToInteger(
Lo);
510 Hi = BitConvertToInteger(
Hi);
518 JoinIntegers(
Lo,
Hi));
552 if (isTypeLegal(WideOutVT)) {
553 InOp = DAG.
getBitcast(WideOutVT, GetWidenedVector(InOp));
563 CreateStackStoreLoad(InOp, OutVT));
567 SDValue V = GetPromotedInteger(
N->getOperand(0));
569 V.getValueType(), V);
573 SDValue Op = GetPromotedInteger(
N->getOperand(0));
574 EVT OVT =
N->getValueType(0);
575 EVT NVT =
Op.getValueType();
595 return DAG.
getNode(ISD::VP_SRL, dl, NVT,
596 DAG.
getNode(ISD::VP_BSWAP, dl, NVT,
Op, Mask, EVL), ShAmt,
601 SDValue Op = GetPromotedInteger(
N->getOperand(0));
602 EVT OVT =
N->getValueType(0);
603 EVT NVT =
Op.getValueType();
623 return DAG.
getNode(ISD::VP_SRL, dl, NVT,
624 DAG.
getNode(ISD::VP_BITREVERSE, dl, NVT,
Op, Mask, EVL),
633 N->getValueType(0)), JoinIntegers(
N->getOperand(0),
638 EVT VT =
N->getValueType(0);
647 assert(isa<ConstantSDNode>(Result) &&
"Didn't constant fold ext?");
652 EVT OVT =
N->getValueType(0);
668 unsigned CtlzOpcode =
N->getOpcode();
669 if (CtlzOpcode ==
ISD::CTLZ || CtlzOpcode == ISD::VP_CTLZ) {
674 if (!
N->isVPOpcode()) {
676 SDValue Op = ZExtPromotedInteger(
N->getOperand(0));
684 SDValue Op = VPZExtPromotedInteger(
N->getOperand(0), Mask, EVL);
685 return DAG.
getNode(ISD::VP_SUB, dl, NVT,
686 DAG.
getNode(
N->getOpcode(), dl, NVT,
Op, Mask, EVL),
687 ExtractLeadingBits, Mask, EVL);
690 CtlzOpcode == ISD::VP_CTLZ_ZERO_UNDEF) {
692 SDValue Op = GetPromotedInteger(
N->getOperand(0));
697 if (!
N->isVPOpcode()) {
699 return DAG.
getNode(CtlzOpcode, dl, NVT,
Op);
704 Op = DAG.
getNode(ISD::VP_SHL, dl, NVT,
Op, ShiftConst, Mask, EVL);
705 return DAG.
getNode(CtlzOpcode, dl, NVT,
Op, Mask, EVL);
711 EVT OVT =
N->getValueType(0);
728 if (!
N->isVPOpcode()) {
729 SDValue Op = ZExtPromotedInteger(
N->getOperand(0));
735 SDValue Op = VPZExtPromotedInteger(
N->getOperand(0), Mask, EVL);
741 SDValue Op = GetPromotedInteger(
N->getOperand(0));
742 EVT OVT =
N->getValueType(0);
743 EVT NVT =
Op.getValueType();
761 unsigned NewOpc =
N->getOpcode();
762 if (NewOpc ==
ISD::CTTZ || NewOpc == ISD::VP_CTTZ) {
774 N->getOperand(1),
N->getOperand(2));
775 NewOpc = ISD::VP_CTTZ_ZERO_UNDEF;
778 if (!
N->isVPOpcode())
780 return DAG.
getNode(NewOpc, dl, NVT,
Op,
N->getOperand(1),
N->getOperand(2));
783SDValue DAGTypeLegalizer::PromoteIntRes_VP_CttzElements(
SDNode *
N) {
786 return DAG.
getNode(
N->getOpcode(),
DL, NewVT,
N->ops());
789SDValue DAGTypeLegalizer::PromoteIntRes_EXTRACT_VECTOR_ELT(
SDNode *
N) {
804 EVT SVT =
In.getValueType().getScalarType();
816 unsigned NewOpc =
N->getOpcode();
833 if (
N->getOpcode() == ISD::VP_FP_TO_UINT &&
836 NewOpc = ISD::VP_FP_TO_SINT;
839 if (
N->isStrictFPOpcode()) {
840 Res = DAG.
getNode(NewOpc, dl, {NVT, MVT::Other},
841 {
N->getOperand(0),
N->getOperand(1)});
845 }
else if (NewOpc == ISD::VP_FP_TO_SINT || NewOpc == ISD::VP_FP_TO_UINT) {
846 Res = DAG.
getNode(NewOpc, dl, NVT, {
N->getOperand(0),
N->getOperand(1),
849 Res = DAG.
getNode(NewOpc, dl, NVT,
N->getOperand(0));
861 N->getOpcode() == ISD::VP_FP_TO_UINT)
868SDValue DAGTypeLegalizer::PromoteIntRes_FP_TO_XINT_SAT(
SDNode *
N) {
872 return DAG.
getNode(
N->getOpcode(), dl, NVT,
N->getOperand(0),
876SDValue DAGTypeLegalizer::PromoteIntRes_FP_TO_FP16_BF16(
SDNode *
N) {
880 return DAG.
getNode(
N->getOpcode(), dl, NVT,
N->getOperand(0));
883SDValue DAGTypeLegalizer::PromoteIntRes_STRICT_FP_TO_FP16_BF16(
SDNode *
N) {
888 N->getOperand(0),
N->getOperand(1));
896 return DAG.
getNode(
N->getOpcode(), dl, NVT,
N->getOperand(0));
904 DAG.
getNode(
N->getOpcode(), dl, {NVT, MVT::Other},
N->getOperand(0));
916 if (getTypeAction(
N->getOperand(0).getValueType())
918 SDValue Res = GetPromotedInteger(
N->getOperand(0));
936 if (
N->getNumOperands() != 1) {
937 assert(
N->getNumOperands() == 3 &&
"Unexpected number of operands!");
938 assert(
N->isVPOpcode() &&
"Expected VP opcode");
939 return DAG.
getNode(
N->getOpcode(), dl, NVT,
N->getOperand(0),
940 N->getOperand(1),
N->getOperand(2));
942 return DAG.
getNode(
N->getOpcode(), dl, NVT,
N->getOperand(0));
952 N->getMemoryVT(),
N->getMemOperand());
962 SDValue ExtPassThru = GetPromotedInteger(
N->getPassThru());
970 N->getOffset(),
N->getMask(), ExtPassThru,
971 N->getMemoryVT(),
N->getMemOperand(),
972 N->getAddressingMode(), ExtType,
973 N->isExpandingLoad());
982 SDValue ExtPassThru = GetPromotedInteger(
N->getPassThru());
984 "Gather result type and the passThru argument type should be the same");
991 SDValue Ops[] = {
N->getChain(), ExtPassThru,
N->getMask(),
N->getBasePtr(),
992 N->getIndex(),
N->getScale() };
994 N->getMemoryVT(), dl, Ops,
995 N->getMemOperand(),
N->getIndexType(),
1003SDValue DAGTypeLegalizer::PromoteIntRes_VECTOR_COMPRESS(
SDNode *
N) {
1004 SDValue Vec = GetPromotedInteger(
N->getOperand(0));
1005 SDValue Passthru = GetPromotedInteger(
N->getOperand(2));
1007 N->getOperand(1), Passthru);
1015 EVT VT =
N->getValueType(0);
1016 EVT SVT = getSetCCResultType(VT);
1017 SDValue Ops[3] = {
N->getOperand(0),
N->getOperand(1) };
1018 unsigned NumOps =
N->getNumOperands();
1019 assert(NumOps <= 3 &&
"Too many operands");
1021 Ops[2] = PromoteTargetBoolean(
N->getOperand(2), VT);
1029 ReplaceValueWith(
SDValue(
N, 0), Res);
1035template <
class MatchContextClass>
1047 MatchContextClass matcher(DAG, TLI,
N);
1049 unsigned Opcode = matcher.getRootBaseOpcode();
1055 SExtOrZExtPromotedOperands(Op1, Op2);
1064 Op1 = SExtPromotedInteger(Op1);
1065 Op2 = SExtPromotedInteger(Op2);
1066 return matcher.getNode(
ISD::UADDSAT, dl, NVT, Op1, Op2);
1069 Op1 = ZExtPromotedInteger(Op1);
1070 Op2 = ZExtPromotedInteger(Op2);
1075 return matcher.getNode(
ISD::UMIN, dl, NVT,
Add, SatMax);
1082 Op1 = GetPromotedInteger(Op1);
1083 Op2 = ZExtPromotedInteger(Op2);
1085 Op1 = SExtPromotedInteger(Op1);
1086 Op2 = SExtPromotedInteger(Op2);
1093 if (IsShift || matcher.isOperationLegal(Opcode, PromotedType)) {
1106 "addition, subtraction or left shift");
1109 unsigned SHLAmount = NewBits - OldBits;
1116 SDValue Result = matcher.getNode(Opcode, dl, PromotedType, Op1, Op2);
1117 return matcher.getNode(ShiftOp, dl, PromotedType, Result, ShiftAmount);
1125 SDValue Result = matcher.getNode(AddOp, dl, PromotedType, Op1, Op2);
1126 Result = matcher.getNode(
ISD::SMIN, dl, PromotedType, Result, SatMax);
1127 Result = matcher.getNode(
ISD::SMAX, dl, PromotedType, Result, SatMin);
1134 SDValue Op1Promoted, Op2Promoted;
1140 Op1Promoted = SExtPromotedInteger(
N->getOperand(0));
1141 Op2Promoted = SExtPromotedInteger(
N->getOperand(1));
1143 Op1Promoted = ZExtPromotedInteger(
N->getOperand(0));
1144 Op2Promoted = ZExtPromotedInteger(
N->getOperand(1));
1146 EVT OldType =
N->getOperand(0).getValueType();
1160 Op2Promoted,
N->getOperand(2));
1162 return DAG.
getNode(ShiftOp, dl, PromotedType, Result,
1165 return DAG.
getNode(
N->getOpcode(), dl, PromotedType, Op1Promoted, Op2Promoted,
1170 unsigned SatW,
bool Signed,
1173 EVT VT = V.getValueType();
1200 EVT VT =
LHS.getValueType();
1218 assert(Res &&
"Expanding DIVFIX with wide type failed?");
1224 "Tried to saturate to more than the original type?");
1233 SDValue Op1Promoted, Op2Promoted;
1239 Op1Promoted = SExtPromotedInteger(
N->getOperand(0));
1240 Op2Promoted = SExtPromotedInteger(
N->getOperand(1));
1242 Op1Promoted = ZExtPromotedInteger(
N->getOperand(0));
1243 Op2Promoted = ZExtPromotedInteger(
N->getOperand(1));
1246 unsigned Scale =
N->getConstantOperandVal(2);
1255 N->getValueType(0).getScalarSizeInBits();
1260 SDValue Res = DAG.
getNode(
N->getOpcode(), dl, PromotedType, Op1Promoted,
1261 Op2Promoted,
N->getOperand(2));
1271 Op2Promoted, Scale, DAG)) {
1274 N->getValueType(0).getScalarSizeInBits(),
1282 N->getValueType(0).getScalarSizeInBits());
1285SDValue DAGTypeLegalizer::PromoteIntRes_SADDSUBO(
SDNode *
N,
unsigned ResNo) {
1287 return PromoteIntRes_Overflow(
N);
1291 SDValue LHS = SExtPromotedInteger(
N->getOperand(0));
1292 SDValue RHS = SExtPromotedInteger(
N->getOperand(1));
1293 EVT OVT =
N->getOperand(0).getValueType();
1294 EVT NVT =
LHS.getValueType();
1309 ReplaceValueWith(
SDValue(
N, 1), Ofl);
1315 EVT PromotedResultTy =
1318 N->getOperand(0),
N->getOperand(1));
1324 SDValue LHS = GetPromotedInteger(
N->getOperand(1));
1325 SDValue RHS = GetPromotedInteger(
N->getOperand(2));
1327 unsigned Opcode =
N->getOpcode();
1328 if (Opcode == ISD::VP_SELECT || Opcode == ISD::VP_MERGE)
1335 SDValue LHS = GetPromotedInteger(
N->getOperand(2));
1336 SDValue RHS = GetPromotedInteger(
N->getOperand(3));
1338 LHS.getValueType(),
N->getOperand(0),
1339 N->getOperand(1), LHS, RHS,
N->getOperand(4));
1343 unsigned OpNo =
N->isStrictFPOpcode() ? 1 : 0;
1344 EVT InVT =
N->getOperand(OpNo).getValueType();
1347 EVT SVT = getSetCCResultType(InVT);
1355 SVT = getSetCCResultType(InVT);
1363 assert(SVT.
isVector() ==
N->getOperand(OpNo).getValueType().isVector() &&
1364 "Vector compare must return a vector result!");
1368 if (
N->isStrictFPOpcode()) {
1370 SDValue Opers[] = {
N->getOperand(0),
N->getOperand(1),
1371 N->getOperand(2),
N->getOperand(3)};
1372 SetCC = DAG.
getNode(
N->getOpcode(), dl, VTs, Opers,
N->getFlags());
1377 SetCC = DAG.
getNode(
N->getOpcode(), dl, SVT,
N->getOperand(0),
1378 N->getOperand(1),
N->getOperand(2),
N->getFlags());
1394 EVT VT =
N->getValueType(0);
1400 ReplaceValueWith(
SDValue(
N, 0), Res);
1405 SDValue LHS = GetPromotedInteger(
N->getOperand(0));
1407 if (
N->getOpcode() != ISD::VP_SHL) {
1409 RHS = ZExtPromotedInteger(RHS);
1417 RHS = VPZExtPromotedInteger(RHS, Mask, EVL);
1422SDValue DAGTypeLegalizer::PromoteIntRes_SIGN_EXTEND_INREG(
SDNode *
N) {
1423 SDValue Op = GetPromotedInteger(
N->getOperand(0));
1425 Op.getValueType(),
Op,
N->getOperand(1));
1428SDValue DAGTypeLegalizer::PromoteIntRes_SimpleIntBinOp(
SDNode *
N) {
1432 SDValue LHS = GetPromotedInteger(
N->getOperand(0));
1433 SDValue RHS = GetPromotedInteger(
N->getOperand(1));
1434 if (
N->getNumOperands() == 2)
1436 assert(
N->getNumOperands() == 4 &&
"Unexpected number of operands!");
1437 assert(
N->isVPOpcode() &&
"Expected VP opcode");
1439 N->getOperand(2),
N->getOperand(3));
1443 if (
N->getNumOperands() == 2) {
1445 SDValue LHS = SExtPromotedInteger(
N->getOperand(0));
1446 SDValue RHS = SExtPromotedInteger(
N->getOperand(1));
1449 assert(
N->getNumOperands() == 4 &&
"Unexpected number of operands!");
1450 assert(
N->isVPOpcode() &&
"Expected VP opcode");
1454 SDValue LHS = VPSExtPromotedInteger(
N->getOperand(0), Mask, EVL);
1455 SDValue RHS = VPSExtPromotedInteger(
N->getOperand(1), Mask, EVL);
1461 if (
N->getNumOperands() == 2) {
1463 SDValue LHS = ZExtPromotedInteger(
N->getOperand(0));
1464 SDValue RHS = ZExtPromotedInteger(
N->getOperand(1));
1467 assert(
N->getNumOperands() == 4 &&
"Unexpected number of operands!");
1468 assert(
N->isVPOpcode() &&
"Expected VP opcode");
1472 SDValue LHS = VPZExtPromotedInteger(
N->getOperand(0), Mask, EVL);
1473 SDValue RHS = VPZExtPromotedInteger(
N->getOperand(1), Mask, EVL);
1484 SExtOrZExtPromotedOperands(LHS, RHS);
1487 LHS.getValueType(), LHS, RHS);
1492 if (
N->getOpcode() != ISD::VP_SRA) {
1494 SDValue LHS = SExtPromotedInteger(
N->getOperand(0));
1496 RHS = ZExtPromotedInteger(RHS);
1503 SDValue LHS = VPSExtPromotedInteger(
N->getOperand(0), Mask, EVL);
1505 RHS = VPZExtPromotedInteger(RHS, Mask, EVL);
1512 if (
N->getOpcode() != ISD::VP_SRL) {
1514 SDValue LHS = ZExtPromotedInteger(
N->getOperand(0));
1516 RHS = ZExtPromotedInteger(RHS);
1523 SDValue LHS = VPZExtPromotedInteger(
N->getOperand(0), Mask, EVL);
1525 RHS = VPZExtPromotedInteger(RHS, Mask, EVL);
1533 ReplaceValueWith(
SDValue(
N, 0), Res);
1538 SDValue Hi = GetPromotedInteger(
N->getOperand(0));
1539 SDValue Lo = GetPromotedInteger(
N->getOperand(1));
1542 Amt = ZExtPromotedInteger(Amt);
1546 EVT OldVT =
N->getOperand(0).getValueType();
1547 EVT VT =
Lo.getValueType();
1548 unsigned Opcode =
N->getOpcode();
1562 if (NewBits >= (2 * OldBits) && !isa<ConstantSDNode>(Amt) &&
1587SDValue DAGTypeLegalizer::PromoteIntRes_VPFunnelShift(
SDNode *
N) {
1588 SDValue Hi = GetPromotedInteger(
N->getOperand(0));
1589 SDValue Lo = GetPromotedInteger(
N->getOperand(1));
1594 Amt = VPZExtPromotedInteger(Amt, Mask, EVL);
1598 EVT OldVT =
N->getOperand(0).getValueType();
1599 EVT VT =
Lo.getValueType();
1600 unsigned Opcode =
N->getOpcode();
1601 bool IsFSHR = Opcode == ISD::VP_FSHR;
1606 Amt = DAG.
getNode(ISD::VP_UREM,
DL, AmtVT, Amt,
1614 if (NewBits >= (2 * OldBits) && !isa<ConstantSDNode>(Amt) &&
1617 Hi = DAG.
getNode(ISD::VP_SHL,
DL, VT,
Hi, HiShift, Mask, EVL);
1620 Res = DAG.
getNode(IsFSHR ? ISD::VP_SRL : ISD::VP_SHL,
DL, VT, Res, Amt,
1623 Res = DAG.
getNode(ISD::VP_SRL,
DL, VT, Res, HiShift, Mask, EVL);
1629 Lo = DAG.
getNode(ISD::VP_SHL,
DL, VT,
Lo, ShiftOffset, Mask, EVL);
1634 Amt = DAG.
getNode(ISD::VP_ADD,
DL, AmtVT, Amt, ShiftOffset, Mask, EVL);
1652 Res = GetPromotedInteger(InOp);
1659 "Dst and Src must have the same number of elements");
1661 "Promoted vector type must be a power of two");
1664 GetSplitVector(InOp, EOp1, EOp2);
1672 assert(
N->getOpcode() == ISD::VP_TRUNCATE &&
1673 "Expected VP_TRUNCATE opcode");
1674 SDValue MaskLo, MaskHi, EVLLo, EVLHi;
1675 std::tie(MaskLo, MaskHi) = SplitMask(
N->getOperand(1));
1676 std::tie(EVLLo, EVLHi) =
1677 DAG.
SplitEVL(
N->getOperand(2),
N->getValueType(0), dl);
1678 EOp1 = DAG.
getNode(ISD::VP_TRUNCATE, dl, HalfNVT, EOp1, MaskLo, EVLLo);
1679 EOp2 = DAG.
getNode(ISD::VP_TRUNCATE, dl, HalfNVT, EOp2, MaskHi, EVLHi);
1686 SDValue WideInOp = GetWidenedVector(InOp);
1691 N->getValueType(0).getScalarType(), NumElem);
1706 if (
N->getOpcode() == ISD::VP_TRUNCATE)
1707 return DAG.
getNode(ISD::VP_TRUNCATE, dl, NVT, Res,
N->getOperand(1),
1712SDValue DAGTypeLegalizer::PromoteIntRes_UADDSUBO(
SDNode *
N,
unsigned ResNo) {
1714 return PromoteIntRes_Overflow(
N);
1718 SDValue LHS = ZExtPromotedInteger(
N->getOperand(0));
1719 SDValue RHS = ZExtPromotedInteger(
N->getOperand(1));
1720 EVT OVT =
N->getOperand(0).getValueType();
1721 EVT NVT =
LHS.getValueType();
1735 ReplaceValueWith(
SDValue(
N, 1), Ofl);
1746 return PromoteIntRes_Overflow(
N);
1758 SDValue LHS = SExtPromotedInteger(
N->getOperand(0));
1759 SDValue RHS = SExtPromotedInteger(
N->getOperand(1));
1761 EVT ValueVTs[] = {
LHS.getValueType(),
N->getValueType(1)};
1765 LHS, RHS,
N->getOperand(2));
1775 assert(ResNo == 1 &&
"Don't know how to promote other results yet.");
1776 return PromoteIntRes_Overflow(
N);
1780 EVT OVT =
N->getValueType(0);
1793 SDValue Op0 = SExtPromotedInteger(
N->getOperand(0));
1797SDValue DAGTypeLegalizer::PromoteIntRes_XMULO(
SDNode *
N,
unsigned ResNo) {
1800 return PromoteIntRes_Overflow(
N);
1804 EVT SmallVT =
LHS.getValueType();
1811 LHS = SExtPromotedInteger(LHS);
1812 RHS = SExtPromotedInteger(RHS);
1814 LHS = ZExtPromotedInteger(LHS);
1815 RHS = ZExtPromotedInteger(RHS);
1846 ReplaceValueWith(
SDValue(
N, 1), Overflow);
1852 N->getValueType(0)));
1858 const APInt &MulImm =
N->getConstantOperandAPInt(0);
1865 EVT VT =
N->getValueType(0);
1873 for (
unsigned i = 0; i < NumRegs; ++i) {
1874 Parts[i] = DAG.
getVAArg(RegVT, dl, Chain,
Ptr,
N->getOperand(2),
1875 N->getConstantOperandVal(3));
1881 std::reverse(Parts.begin(), Parts.end());
1886 for (
unsigned i = 1; i < NumRegs; ++i) {
1897 ReplaceValueWith(
SDValue(
N, 1), Chain);
1910bool DAGTypeLegalizer::PromoteIntegerOperand(
SDNode *
N,
unsigned OpNo) {
1913 if (CustomLowerNode(
N,
N->getOperand(OpNo).getValueType(),
false)) {
1918 switch (
N->getOpcode()) {
1921 dbgs() <<
"PromoteIntegerOperand Op #" << OpNo <<
": ";
1922 N->dump(&DAG);
dbgs() <<
"\n";
1928 Res = PromoteIntOp_ATOMIC_STORE(cast<AtomicSDNode>(
N));
1931 case ISD::BR_CC: Res = PromoteIntOp_BR_CC(
N, OpNo);
break;
1932 case ISD::BRCOND: Res = PromoteIntOp_BRCOND(
N, OpNo);
break;
1938 Res = PromoteIntOp_INSERT_VECTOR_ELT(
N, OpNo);
1942 case ISD::EXPERIMENTAL_VP_SPLAT:
1943 Res = PromoteIntOp_ScalarOp(
N);
1946 case ISD::SELECT: Res = PromoteIntOp_SELECT(
N, OpNo);
break;
1949 case ISD::SETCC: Res = PromoteIntOp_SETCC(
N, OpNo);
break;
1951 case ISD::VP_SIGN_EXTEND: Res = PromoteIntOp_VP_SIGN_EXTEND(
N);
break;
1952 case ISD::VP_SINT_TO_FP:
1955 case ISD::STORE: Res = PromoteIntOp_STORE(cast<StoreSDNode>(
N),
1957 case ISD::MSTORE: Res = PromoteIntOp_MSTORE(cast<MaskedStoreSDNode>(
N),
1959 case ISD::MLOAD: Res = PromoteIntOp_MLOAD(cast<MaskedLoadSDNode>(
N),
1961 case ISD::MGATHER: Res = PromoteIntOp_MGATHER(cast<MaskedGatherSDNode>(
N),
1963 case ISD::MSCATTER: Res = PromoteIntOp_MSCATTER(cast<MaskedScatterSDNode>(
N),
1966 Res = PromoteIntOp_VECTOR_COMPRESS(
N, OpNo);
1968 case ISD::VP_TRUNCATE:
1972 case ISD::VP_UINT_TO_FP:
1977 case ISD::VP_ZERO_EXTEND: Res = PromoteIntOp_VP_ZERO_EXTEND(
N);
break;
1985 case ISD::ROTR: Res = PromoteIntOp_Shift(
N);
break;
1988 case ISD::UCMP: Res = PromoteIntOp_CMP(
N);
break;
1991 case ISD::FSHR: Res = PromoteIntOp_FunnelShift(
N);
break;
2017 case ISD::VP_REDUCE_ADD:
2018 case ISD::VP_REDUCE_MUL:
2019 case ISD::VP_REDUCE_AND:
2020 case ISD::VP_REDUCE_OR:
2021 case ISD::VP_REDUCE_XOR:
2022 case ISD::VP_REDUCE_SMAX:
2023 case ISD::VP_REDUCE_SMIN:
2024 case ISD::VP_REDUCE_UMAX:
2025 case ISD::VP_REDUCE_UMIN:
2026 Res = PromoteIntOp_VP_REDUCE(
N, OpNo);
2031 Res = PromoteIntOp_STACKMAP(
N, OpNo);
2034 Res = PromoteIntOp_PATCHPOINT(
N, OpNo);
2036 case ISD::EXPERIMENTAL_VP_STRIDED_LOAD:
2037 case ISD::EXPERIMENTAL_VP_STRIDED_STORE:
2038 Res = PromoteIntOp_VP_STRIDED(
N, OpNo);
2040 case ISD::EXPERIMENTAL_VP_SPLICE:
2041 Res = PromoteIntOp_VP_SPLICE(
N, OpNo);
2046 if (!Res.
getNode())
return false;
2053 const bool IsStrictFp =
N->isStrictFPOpcode();
2055 N->getNumValues() == (IsStrictFp ? 2 : 1) &&
2056 "Invalid operand expansion");
2060 ReplaceValueWith(
SDValue(
N, 0), Res);
2070void DAGTypeLegalizer::SExtOrZExtPromotedOperands(
SDValue &LHS,
SDValue &RHS) {
2071 SDValue OpL = GetPromotedInteger(LHS);
2072 SDValue OpR = GetPromotedInteger(RHS);
2078 unsigned OpLEffectiveBits =
2080 unsigned OpREffectiveBits =
2082 if (OpLEffectiveBits <=
LHS.getScalarValueSizeInBits() &&
2083 OpREffectiveBits <=
RHS.getScalarValueSizeInBits()) {
2090 LHS = SExtPromotedInteger(LHS);
2091 RHS = SExtPromotedInteger(RHS);
2102 if (OpLEffectiveBits <=
LHS.getScalarValueSizeInBits() &&
2103 OpREffectiveBits <=
RHS.getScalarValueSizeInBits()) {
2110 LHS = ZExtPromotedInteger(LHS);
2111 RHS = ZExtPromotedInteger(RHS);
2116void DAGTypeLegalizer::PromoteSetCCOperands(
SDValue &LHS,
SDValue &RHS,
2125 LHS = SExtPromotedInteger(LHS);
2126 RHS = SExtPromotedInteger(RHS);
2131 "Unknown integer comparison!");
2133 SExtOrZExtPromotedOperands(LHS, RHS);
2137 SDValue Op = GetPromotedInteger(
N->getOperand(0));
2142 SDValue Op1 = GetPromotedInteger(
N->getOperand(1));
2144 N->getChain(), Op1,
N->getBasePtr(),
N->getMemOperand());
2150 return CreateStackStoreLoad(
N->getOperand(0),
N->getValueType(0));
2153SDValue DAGTypeLegalizer::PromoteIntOp_BR_CC(
SDNode *
N,
unsigned OpNo) {
2154 assert(OpNo == 2 &&
"Don't know how to promote this operand!");
2158 PromoteSetCCOperands(LHS, RHS, cast<CondCodeSDNode>(
N->getOperand(1))->get());
2163 N->getOperand(1), LHS, RHS,
N->getOperand(4)),
2167SDValue DAGTypeLegalizer::PromoteIntOp_BRCOND(
SDNode *
N,
unsigned OpNo) {
2168 assert(OpNo == 1 &&
"only know how to promote condition");
2171 SDValue Cond = PromoteTargetBoolean(
N->getOperand(1), MVT::Other);
2175 N->getOperand(2)), 0);
2180 EVT OVT =
N->getOperand(0).getValueType();
2181 SDValue Lo = ZExtPromotedInteger(
N->getOperand(0));
2182 SDValue Hi = GetPromotedInteger(
N->getOperand(1));
2183 assert(
Lo.getValueType() ==
N->getValueType(0) &&
"Operand over promoted?");
2196 EVT VecVT =
N->getValueType(0);
2199 "Legal vector of one illegal element?");
2204 assert(
N->getOperand(0).getValueSizeInBits() >=
2205 N->getValueType(0).getScalarSizeInBits() &&
2206 "Type of inserted value narrower than vector element type!");
2209 for (
unsigned i = 0; i < NumElts; ++i)
2210 NewOps.
push_back(GetPromotedInteger(
N->getOperand(i)));
2215SDValue DAGTypeLegalizer::PromoteIntOp_INSERT_VECTOR_ELT(
SDNode *
N,
2222 assert(
N->getOperand(1).getValueSizeInBits() >=
2223 N->getValueType(0).getScalarSizeInBits() &&
2224 "Type of inserted value narrower than vector element type!");
2226 GetPromotedInteger(
N->getOperand(1)),
2231 assert(OpNo == 2 &&
"Different operand and result vector types?");
2237 N->getOperand(1),
Idx), 0);
2241 SDValue Op = GetPromotedInteger(
N->getOperand(0));
2242 if (
N->getOpcode() == ISD::EXPERIMENTAL_VP_SPLAT)
2251SDValue DAGTypeLegalizer::PromoteIntOp_SELECT(
SDNode *
N,
unsigned OpNo) {
2252 assert(OpNo == 0 &&
"Only know how to promote the condition!");
2254 EVT OpTy =
N->getOperand(1).getValueType();
2257 if (
SDValue Res = WidenVSELECTMask(
N))
2259 Res,
N->getOperand(1),
N->getOperand(2));
2263 Cond = PromoteTargetBoolean(
Cond, OpVT);
2266 N->getOperand(2)), 0);
2269SDValue DAGTypeLegalizer::PromoteIntOp_SELECT_CC(
SDNode *
N,
unsigned OpNo) {
2270 assert(OpNo == 0 &&
"Don't know how to promote this operand!");
2274 PromoteSetCCOperands(LHS, RHS, cast<CondCodeSDNode>(
N->getOperand(4))->get());
2278 N->getOperand(3),
N->getOperand(4)), 0);
2281SDValue DAGTypeLegalizer::PromoteIntOp_SETCC(
SDNode *
N,
unsigned OpNo) {
2282 assert(OpNo == 0 &&
"Don't know how to promote this operand!");
2286 PromoteSetCCOperands(LHS, RHS, cast<CondCodeSDNode>(
N->getOperand(2))->get());
2292 assert(
N->getOpcode() == ISD::VP_SETCC &&
"Expected VP_SETCC opcode");
2295 N->getOperand(3),
N->getOperand(4)),
2301 ZExtPromotedInteger(
N->getOperand(1))), 0);
2309 LHS = SExtPromotedInteger(LHS);
2310 RHS = SExtPromotedInteger(RHS);
2312 SExtOrZExtPromotedOperands(LHS, RHS);
2320 ZExtPromotedInteger(
N->getOperand(2))), 0);
2324 SDValue Op = GetPromotedInteger(
N->getOperand(0));
2331SDValue DAGTypeLegalizer::PromoteIntOp_VP_SIGN_EXTEND(
SDNode *
N) {
2333 EVT VT =
N->getValueType(0);
2334 SDValue Op = GetPromotedInteger(
N->getOperand(0));
2336 Op = DAG.
getNode(ISD::VP_ZERO_EXTEND, dl, VT,
Op,
N->getOperand(1),
2344 return DAG.
getNode(ISD::VP_SRA, dl, VT, Shl, ShAmt,
N->getOperand(1),
2349 if (
N->getOpcode() == ISD::VP_SINT_TO_FP)
2351 SExtPromotedInteger(
N->getOperand(0)),
2352 N->getOperand(1),
N->getOperand(2)),
2355 SExtPromotedInteger(
N->getOperand(0))), 0);
2358SDValue DAGTypeLegalizer::PromoteIntOp_STRICT_SINT_TO_FP(
SDNode *
N) {
2360 SExtPromotedInteger(
N->getOperand(1))), 0);
2368 SDValue Val = GetPromotedInteger(
N->getValue());
2372 N->getMemoryVT(),
N->getMemOperand());
2383 Mask = PromoteTargetBoolean(Mask, DataVT);
2389 assert(OpNo == 1 &&
"Unexpected operand for promotion");
2390 DataOp = GetPromotedInteger(DataOp);
2393 N->getOffset(), Mask,
N->getMemoryVT(),
2394 N->getMemOperand(),
N->getAddressingMode(),
2395 true,
N->isCompressingStore());
2400 assert(OpNo == 3 &&
"Only know how to promote the mask!");
2401 EVT DataVT =
N->getValueType(0);
2402 SDValue Mask = PromoteTargetBoolean(
N->getOperand(OpNo), DataVT);
2404 NewOps[OpNo] =
Mask;
2421 EVT DataVT =
N->getValueType(0);
2422 NewOps[OpNo] = PromoteTargetBoolean(
N->getOperand(OpNo), DataVT);
2423 }
else if (OpNo == 4) {
2425 if (
N->isIndexSigned())
2427 NewOps[OpNo] = SExtPromotedInteger(
N->getOperand(OpNo));
2429 NewOps[OpNo] = ZExtPromotedInteger(
N->getOperand(OpNo));
2431 NewOps[OpNo] = GetPromotedInteger(
N->getOperand(OpNo));
2445 bool TruncateStore =
N->isTruncatingStore();
2450 EVT DataVT =
N->getValue().getValueType();
2451 NewOps[OpNo] = PromoteTargetBoolean(
N->getOperand(OpNo), DataVT);
2452 }
else if (OpNo == 4) {
2454 if (
N->isIndexSigned())
2456 NewOps[OpNo] = SExtPromotedInteger(
N->getOperand(OpNo));
2458 NewOps[OpNo] = ZExtPromotedInteger(
N->getOperand(OpNo));
2460 NewOps[OpNo] = GetPromotedInteger(
N->getOperand(OpNo));
2461 TruncateStore =
true;
2465 SDLoc(
N), NewOps,
N->getMemOperand(),
2466 N->getIndexType(), TruncateStore);
2471 assert(OpNo == 1 &&
"Can only promote VECTOR_COMPRESS mask.");
2474 SDValue Passthru =
N->getOperand(2);
2475 SDValue Mask = PromoteTargetBoolean(
N->getOperand(1), VT);
2480 SDValue Op = GetPromotedInteger(
N->getOperand(0));
2481 if (
N->getOpcode() == ISD::VP_TRUNCATE)
2483 N->getOperand(1),
N->getOperand(2));
2488 if (
N->getOpcode() == ISD::VP_UINT_TO_FP)
2490 ZExtPromotedInteger(
N->getOperand(0)),
2491 N->getOperand(1),
N->getOperand(2)),
2494 ZExtPromotedInteger(
N->getOperand(0))), 0);
2497SDValue DAGTypeLegalizer::PromoteIntOp_STRICT_UINT_TO_FP(
SDNode *
N) {
2499 ZExtPromotedInteger(
N->getOperand(1))), 0);
2504 SDValue Op = GetPromotedInteger(
N->getOperand(0));
2509SDValue DAGTypeLegalizer::PromoteIntOp_VP_ZERO_EXTEND(
SDNode *
N) {
2511 EVT VT =
N->getValueType(0);
2512 SDValue Op = GetPromotedInteger(
N->getOperand(0));
2514 Op = DAG.
getNode(ISD::VP_ZERO_EXTEND, dl, VT,
Op,
N->getOperand(1),
2517 N->getOperand(0).getValueType());
2521 SDValue Op2 = ZExtPromotedInteger(
N->getOperand(2));
2526SDValue DAGTypeLegalizer::PromoteIntOp_FRAMERETURNADDR(
SDNode *
N) {
2528 SDValue Op = ZExtPromotedInteger(
N->getOperand(0));
2533 bool IsStrict =
N->isStrictFPOpcode();
2545 SDValue Op = SExtPromotedInteger(
N->getOperand(1));
2555 unsigned OpOffset = IsStrict ? 1 : 0;
2558 N->getOperand(1 + OpOffset).getValueType().getSizeInBits() &&
2559 "POWI exponent should match with sizeof(int) when doing the libcall.");
2562 SDValue Ops[2] = {
N->getOperand(0 + OpOffset),
N->getOperand(1 + OpOffset)};
2563 std::pair<SDValue, SDValue> Tmp = TLI.
makeLibCall(
2564 DAG, LC,
N->getValueType(0), Ops, CallOptions,
SDLoc(
N), Chain);
2565 ReplaceValueWith(
SDValue(
N, 0), Tmp.first);
2567 ReplaceValueWith(
SDValue(
N, 1), Tmp.second);
2572 switch (
N->getOpcode()) {
2580 case ISD::VP_REDUCE_ADD:
2581 case ISD::VP_REDUCE_MUL:
2582 case ISD::VP_REDUCE_AND:
2583 case ISD::VP_REDUCE_OR:
2584 case ISD::VP_REDUCE_XOR:
2588 case ISD::VP_REDUCE_SMAX:
2589 case ISD::VP_REDUCE_SMIN:
2593 case ISD::VP_REDUCE_UMAX:
2594 case ISD::VP_REDUCE_UMIN:
2604 return GetPromotedInteger(V);
2606 return SExtPromotedInteger(V);
2608 return ZExtPromotedInteger(V);
2614 SDValue Op = PromoteIntOpVectorReduction(
N,
N->getOperand(0));
2616 EVT OrigEltVT =
N->getOperand(0).getValueType().getVectorElementType();
2617 EVT InVT =
Op.getValueType();
2619 EVT ResVT =
N->getValueType(0);
2620 unsigned Opcode =
N->getOpcode();
2640 Op = ZExtPromotedInteger(
N->getOperand(0));
2643 Op = SExtPromotedInteger(
N->getOperand(0));
2659 Op = ZExtPromotedInteger(
N->getOperand(0));
2662 Op = SExtPromotedInteger(
N->getOperand(0));
2676SDValue DAGTypeLegalizer::PromoteIntOp_VP_REDUCE(
SDNode *
N,
unsigned OpNo) {
2683 NewOps[2] = PromoteTargetBoolean(
Op,
N->getOperand(1).getValueType());
2687 assert(OpNo == 1 &&
"Unexpected operand for promotion");
2689 Op = PromoteIntOpVectorReduction(
N,
Op);
2693 EVT VT =
N->getValueType(0);
2694 EVT EltVT =
Op.getValueType().getScalarType();
2709 SDValue Op = ZExtPromotedInteger(
N->getOperand(1));
2713SDValue DAGTypeLegalizer::PromoteIntOp_STACKMAP(
SDNode *
N,
unsigned OpNo) {
2716 SDValue Operand =
N->getOperand(OpNo);
2722SDValue DAGTypeLegalizer::PromoteIntOp_PATCHPOINT(
SDNode *
N,
unsigned OpNo) {
2725 SDValue Operand =
N->getOperand(OpNo);
2731SDValue DAGTypeLegalizer::PromoteIntOp_VP_STRIDED(
SDNode *
N,
unsigned OpNo) {
2732 assert((
N->getOpcode() == ISD::EXPERIMENTAL_VP_STRIDED_LOAD && OpNo == 3) ||
2733 (
N->getOpcode() == ISD::EXPERIMENTAL_VP_STRIDED_STORE && OpNo == 4));
2736 NewOps[OpNo] = SExtPromotedInteger(
N->getOperand(OpNo));
2741SDValue DAGTypeLegalizer::PromoteIntOp_VP_SPLICE(
SDNode *
N,
unsigned OpNo) {
2745 NewOps[OpNo] = SExtPromotedInteger(
N->getOperand(OpNo));
2749 assert((OpNo == 4 || OpNo == 5) &&
"Unexpected operand for promotion");
2751 NewOps[OpNo] = ZExtPromotedInteger(
N->getOperand(OpNo));
2763void DAGTypeLegalizer::ExpandIntegerResult(
SDNode *
N,
unsigned ResNo) {
2769 if (CustomLowerNode(
N,
N->getValueType(ResNo),
true))
2772 switch (
N->getOpcode()) {
2775 dbgs() <<
"ExpandIntegerResult #" << ResNo <<
": ";
2776 N->dump(&DAG);
dbgs() <<
"\n";
2824 case ISD::LOAD: ExpandIntRes_LOAD(cast<LoadSDNode>(
N),
Lo,
Hi);
break;
2851 std::pair<SDValue, SDValue> Tmp = ExpandAtomic(
N);
2852 SplitInteger(Tmp.first,
Lo,
Hi);
2853 ReplaceValueWith(
SDValue(
N, 1), Tmp.second);
2861 N->getOperand(0),
N->getOperand(1),
N->getOperand(2),
N->getOperand(3),
2870 SplitInteger(Tmp,
Lo,
Hi);
2949 ExpandIntRes_Rotate(
N,
Lo,
Hi);
2954 ExpandIntRes_FunnelShift(
N,
Lo,
Hi);
2958 ExpandIntRes_VSCALE(
N,
Lo,
Hi);
2968std::pair <SDValue, SDValue> DAGTypeLegalizer::ExpandAtomic(
SDNode *
Node) {
2969 unsigned Opc =
Node->getOpcode();
2975 EVT RetVT =
Node->getValueType(0);
2983 assert(LC != RTLIB::UNKNOWN_LIBCALL &&
2984 "Unexpected atomic op or value type!");
2988 Node->getOperand(0));
2993void DAGTypeLegalizer::ExpandShiftByConstant(
SDNode *
N,
const APInt &Amt,
2998 GetExpandedInteger(
N->getOperand(0), InL, InH);
3009 unsigned VTBits =
N->getValueType(0).getSizeInBits();
3013 if (Amt.
uge(VTBits)) {
3015 }
else if (Amt.
ugt(NVTBits)) {
3019 }
else if (Amt == NVTBits) {
3036 if (Amt.
uge(VTBits)) {
3038 }
else if (Amt.
ugt(NVTBits)) {
3042 }
else if (Amt == NVTBits) {
3059 if (Amt.
uge(VTBits)) {
3062 }
else if (Amt.
ugt(NVTBits)) {
3067 }
else if (Amt == NVTBits) {
3087bool DAGTypeLegalizer::
3089 unsigned Opc =
N->getOpcode();
3097 "Expanded integer type size not a power of two!");
3104 if (((Known.
Zero | Known.
One) & HighBitMask) == 0)
3109 GetExpandedInteger(In, InL, InH);
3163 Lo = DAG.
getNode(Opc, dl, NVT, InL, Amt);
3176bool DAGTypeLegalizer::
3183 "Expanded integer type size not a power of two!");
3188 GetExpandedInteger(
N->getOperand(0), InL, InH);
3200 switch (
N->getOpcode()) {
3215 DAG.
getSelect(dl, NVT, isShort, HiS, HiL));
3231 DAG.
getSelect(dl, NVT, isShort, LoS, LoL));
3247 DAG.
getSelect(dl, NVT, isShort, LoS, LoL));
3268void DAGTypeLegalizer::ExpandIntRes_MINMAX(
SDNode *
N,
3277 unsigned NumBits =
N->getValueType(0).getScalarSizeInBits();
3278 unsigned NumHalfBits = NumBits / 2;
3281 SDValue LHSL, LHSH, RHSL, RHSH;
3282 GetExpandedInteger(LHS, LHSL, LHSH);
3283 GetExpandedInteger(RHS, RHSL, RHSH);
3296 SDValue LHSL, LHSH, RHSL, RHSH;
3297 GetExpandedInteger(LHS, LHSL, LHSH);
3298 GetExpandedInteger(RHS, RHSL, RHSH);
3300 EVT CCT = getSetCCResultType(NVT);
3309 Hi = DAG.
getNode(
N->getOpcode(),
DL, NVT, {LHSH, RHSH});
3313 const APInt *RHSVal =
nullptr;
3314 if (
auto *RHSConst = dyn_cast<ConstantSDNode>(RHS))
3315 RHSVal = &RHSConst->getAPIntValue();
3322 SDValue LHSL, LHSH, RHSL, RHSH;
3323 GetExpandedInteger(LHS, LHSL, LHSH);
3324 GetExpandedInteger(RHS, RHSL, RHSH);
3326 EVT CCT = getSetCCResultType(NVT);
3332 Hi = DAG.
getNode(
N->getOpcode(),
DL, NVT, {LHSH, RHSH});
3351 switch (
N->getOpcode()) {
3378 EVT VT =
N->getValueType(0);
3379 EVT CCT = getSetCCResultType(VT);
3382 SplitInteger(Result,
Lo,
Hi);
3387 SplitInteger(ExpandedCMP,
Lo,
Hi);
3390void DAGTypeLegalizer::ExpandIntRes_ADDSUB(
SDNode *
N,
3394 SDValue LHSL, LHSH, RHSL, RHSH;
3395 GetExpandedInteger(
N->getOperand(0), LHSL, LHSH);
3396 GetExpandedInteger(
N->getOperand(1), RHSL, RHSH);
3399 SDValue LoOps[2] = { LHSL, RHSL };
3400 SDValue HiOps[3] = { LHSH, RHSH };
3409 HiOps[2] =
Lo.getValue(1);
3415 HiOps[2] =
Lo.getValue(1);
3437 HiOps[2] =
Lo.getValue(1);
3441 HiOps[2] =
Lo.getValue(1);
3454 EVT OvfVT = getSetCCResultType(NVT);
3494 Cmp = DAG.
getSetCC(dl, getSetCCResultType(NVT), LoOps[0],
3497 Cmp = DAG.
getSetCC(dl, getSetCCResultType(NVT), LoOps[0],
3500 Cmp = DAG.
getSetCC(dl, getSetCCResultType(NVT),
Lo, LoOps[0],
3518 DAG.
getSetCC(dl, getSetCCResultType(LoOps[0].getValueType()),
3532void DAGTypeLegalizer::ExpandIntRes_ADDSUBC(
SDNode *
N,
3535 SDValue LHSL, LHSH, RHSL, RHSH;
3537 GetExpandedInteger(
N->getOperand(0), LHSL, LHSH);
3538 GetExpandedInteger(
N->getOperand(1), RHSL, RHSH);
3540 SDValue LoOps[2] = { LHSL, RHSL };
3541 SDValue HiOps[3] = { LHSH, RHSH };
3545 HiOps[2] =
Lo.getValue(1);
3549 HiOps[2] =
Lo.getValue(1);
3555 ReplaceValueWith(
SDValue(
N, 1),
Hi.getValue(1));
3558void DAGTypeLegalizer::ExpandIntRes_ADDSUBE(
SDNode *
N,
3561 SDValue LHSL, LHSH, RHSL, RHSH;
3563 GetExpandedInteger(
N->getOperand(0), LHSL, LHSH);
3564 GetExpandedInteger(
N->getOperand(1), RHSL, RHSH);
3566 SDValue LoOps[3] = { LHSL, RHSL,
N->getOperand(2) };
3567 SDValue HiOps[3] = { LHSH, RHSH };
3569 Lo = DAG.
getNode(
N->getOpcode(), dl, VTList, LoOps);
3570 HiOps[2] =
Lo.getValue(1);
3571 Hi = DAG.
getNode(
N->getOpcode(), dl, VTList, HiOps);
3575 ReplaceValueWith(
SDValue(
N, 1),
Hi.getValue(1));
3578void DAGTypeLegalizer::ExpandIntRes_UADDSUBO(
SDNode *
N,
3586 unsigned CarryOp, NoCarryOp;
3588 switch(
N->getOpcode()) {
3608 SDValue LHSL, LHSH, RHSL, RHSH;
3609 GetExpandedInteger(LHS, LHSL, LHSH);
3610 GetExpandedInteger(RHS, RHSL, RHSH);
3612 SDValue LoOps[2] = { LHSL, RHSL };
3613 SDValue HiOps[3] = { LHSH, RHSH };
3615 Lo = DAG.
getNode(
N->getOpcode(), dl, VTList, LoOps);
3616 HiOps[2] =
Lo.getValue(1);
3617 Hi = DAG.
getNode(CarryOp, dl, VTList, HiOps);
3619 Ovf =
Hi.getValue(1);
3624 SplitInteger(Sum,
Lo,
Hi);
3635 DAG.
getSetCC(dl,
N->getValueType(1), LHS,
3646 ReplaceValueWith(
SDValue(
N, 1), Ovf);
3652 SDValue LHSL, LHSH, RHSL, RHSH;
3654 GetExpandedInteger(
N->getOperand(0), LHSL, LHSH);
3655 GetExpandedInteger(
N->getOperand(1), RHSL, RHSH);
3657 SDValue LoOps[3] = { LHSL, RHSL,
N->getOperand(2) };
3660 Lo = DAG.
getNode(
N->getOpcode(), dl, VTList, LoOps);
3661 HiOps[2] =
Lo.getValue(1);
3662 Hi = DAG.
getNode(
N->getOpcode(), dl, VTList, HiOps);
3666 ReplaceValueWith(
SDValue(
N, 1),
Hi.getValue(1));
3669void DAGTypeLegalizer::ExpandIntRes_SADDSUBO_CARRY(
SDNode *
N,
3672 SDValue LHSL, LHSH, RHSL, RHSH;
3674 GetExpandedInteger(
N->getOperand(0), LHSL, LHSH);
3675 GetExpandedInteger(
N->getOperand(1), RHSL, RHSH);
3681 Lo = DAG.
getNode(CarryOp, dl, VTList, { LHSL, RHSL,
N->getOperand(2) });
3682 Hi = DAG.
getNode(
N->getOpcode(), dl, VTList, { LHSH, RHSH, Lo.getValue(1) });
3686 ReplaceValueWith(
SDValue(
N, 1),
Hi.getValue(1));
3689void DAGTypeLegalizer::ExpandIntRes_ANY_EXTEND(
SDNode *
N,
3694 if (
Op.getValueType().bitsLE(NVT)) {
3701 assert(getTypeAction(
Op.getValueType()) ==
3703 "Only know how to promote this result!");
3706 "Operand over promoted?");
3708 SplitInteger(Res,
Lo,
Hi);
3712void DAGTypeLegalizer::ExpandIntRes_AssertSext(
SDNode *
N,
3715 GetExpandedInteger(
N->getOperand(0),
Lo,
Hi);
3716 EVT NVT =
Lo.getValueType();
3717 EVT EVT = cast<VTSDNode>(
N->getOperand(1))->getVT();
3721 if (NVTBits < EVTBits) {
3724 EVTBits - NVTBits)));
3734void DAGTypeLegalizer::ExpandIntRes_AssertZext(
SDNode *
N,
3737 GetExpandedInteger(
N->getOperand(0),
Lo,
Hi);
3738 EVT NVT =
Lo.getValueType();
3739 EVT EVT = cast<VTSDNode>(
N->getOperand(1))->getVT();
3743 if (NVTBits < EVTBits) {
3746 EVTBits - NVTBits)));
3754void DAGTypeLegalizer::ExpandIntRes_BITREVERSE(
SDNode *
N,
3757 GetExpandedInteger(
N->getOperand(0),
Hi,
Lo);
3762void DAGTypeLegalizer::ExpandIntRes_BSWAP(
SDNode *
N,
3765 GetExpandedInteger(
N->getOperand(0),
Hi,
Lo);
3774 GetExpandedInteger(
N->getOperand(0),
Lo,
Hi);
3775 EVT NVT =
Lo.getValueType();
3781void DAGTypeLegalizer::ExpandIntRes_Constant(
SDNode *
N,
3785 auto Constant = cast<ConstantSDNode>(
N);
3787 bool IsTarget =
Constant->isTargetOpcode();
3788 bool IsOpaque =
Constant->isOpaque();
3799 GetExpandedInteger(N0,
Lo,
Hi);
3800 EVT NVT =
Lo.getValueType();
3831 EVT VT =
N->getValueType(0);
3835 SplitInteger(Neg, NegLo, NegHi);
3843void DAGTypeLegalizer::ExpandIntRes_CTLZ(
SDNode *
N,
3847 GetExpandedInteger(
N->getOperand(0),
Lo,
Hi);
3848 EVT NVT =
Lo.getValueType();
3865 SplitInteger(Result,
Lo,
Hi);
3868void DAGTypeLegalizer::ExpandIntRes_CTPOP(
SDNode *
N,
3872 GetExpandedInteger(
N->getOperand(0),
Lo,
Hi);
3873 EVT NVT =
Lo.getValueType();
3879void DAGTypeLegalizer::ExpandIntRes_CTTZ(
SDNode *
N,
3883 GetExpandedInteger(
N->getOperand(0),
Lo,
Hi);
3884 EVT NVT =
Lo.getValueType();
3899void DAGTypeLegalizer::ExpandIntRes_GET_ROUNDING(
SDNode *
N,
SDValue &