@@ -118,14 +118,7 @@ class SelectionDAGLegalize {
118118 void LegalizeLoadOps (SDNode *Node);
119119 void LegalizeStoreOps (SDNode *Node);
120120
121- // / Some targets cannot handle a variable
122- // / insertion index for the INSERT_VECTOR_ELT instruction. In this case, it
123- // / is necessary to spill the vector being inserted into to memory, perform
124- // / the insert there, and then read the result back.
125- SDValue PerformInsertVectorEltInMemory (SDValue Vec, SDValue Val, SDValue Idx,
126- const SDLoc &dl);
127- SDValue ExpandINSERT_VECTOR_ELT (SDValue Vec, SDValue Val, SDValue Idx,
128- const SDLoc &dl);
121+ SDValue ExpandINSERT_VECTOR_ELT (SDValue Op);
129122
130123 // / Return a vector shuffle operation which
131124 // / performs the same shuffe in terms of order or result bytes, but on a type
@@ -378,45 +371,12 @@ SDValue SelectionDAGLegalize::ExpandConstant(ConstantSDNode *CP) {
378371 return Result;
379372}
380373
381- // / Some target cannot handle a variable insertion index for the
382- // / INSERT_VECTOR_ELT instruction. In this case, it
383- // / is necessary to spill the vector being inserted into to memory, perform
384- // / the insert there, and then read the result back.
385- SDValue SelectionDAGLegalize::PerformInsertVectorEltInMemory (SDValue Vec,
386- SDValue Val,
387- SDValue Idx,
388- const SDLoc &dl) {
389- // If the target doesn't support this, we have to spill the input vector
390- // to a temporary stack slot, update the element, then reload it. This is
391- // badness. We could also load the value into a vector register (either
392- // with a "move to register" or "extload into register" instruction, then
393- // permute it into place, if the idx is a constant and if the idx is
394- // supported by the target.
395- EVT VT = Vec.getValueType ();
396- EVT EltVT = VT.getVectorElementType ();
397- SDValue StackPtr = DAG.CreateStackTemporary (VT);
398-
399- int SPFI = cast<FrameIndexSDNode>(StackPtr.getNode ())->getIndex ();
400-
401- // Store the vector.
402- SDValue Ch = DAG.getStore (
403- DAG.getEntryNode (), dl, Vec, StackPtr,
404- MachinePointerInfo::getFixedStack (DAG.getMachineFunction (), SPFI));
405-
406- SDValue StackPtr2 = TLI.getVectorElementPointer (DAG, StackPtr, VT, Idx);
407-
408- // Store the scalar value.
409- Ch = DAG.getTruncStore (
410- Ch, dl, Val, StackPtr2,
411- MachinePointerInfo::getUnknownStack (DAG.getMachineFunction ()), EltVT);
412- // Load the updated vector.
413- return DAG.getLoad (VT, dl, Ch, StackPtr, MachinePointerInfo::getFixedStack (
414- DAG.getMachineFunction (), SPFI));
415- }
374+ SDValue SelectionDAGLegalize::ExpandINSERT_VECTOR_ELT (SDValue Op) {
375+ SDValue Vec = Op.getOperand (0 );
376+ SDValue Val = Op.getOperand (1 );
377+ SDValue Idx = Op.getOperand (2 );
378+ SDLoc dl (Op);
416379
417- SDValue SelectionDAGLegalize::ExpandINSERT_VECTOR_ELT (SDValue Vec, SDValue Val,
418- SDValue Idx,
419- const SDLoc &dl) {
420380 if (ConstantSDNode *InsertPos = dyn_cast<ConstantSDNode>(Idx)) {
421381 // SCALAR_TO_VECTOR requires that the type of the value being inserted
422382 // match the element type of the vector being created, except for
@@ -438,7 +398,7 @@ SDValue SelectionDAGLegalize::ExpandINSERT_VECTOR_ELT(SDValue Vec, SDValue Val,
438398 return DAG.getVectorShuffle (Vec.getValueType (), dl, Vec, ScVec, ShufOps);
439399 }
440400 }
441- return PerformInsertVectorEltInMemory (Vec, Val, Idx, dl );
401+ return ExpandInsertToVectorThroughStack (Op );
442402}
443403
444404SDValue SelectionDAGLegalize::OptimizeFloatStore (StoreSDNode* ST) {
@@ -1486,7 +1446,7 @@ SDValue SelectionDAGLegalize::ExpandInsertToVectorThroughStack(SDValue Op) {
14861446
14871447 // Store the value to a temporary stack slot, then LOAD the returned part.
14881448 EVT VecVT = Vec.getValueType ();
1489- EVT SubVecVT = Part.getValueType ();
1449+ EVT PartVT = Part.getValueType ();
14901450 SDValue StackPtr = DAG.CreateStackTemporary (VecVT);
14911451 int FI = cast<FrameIndexSDNode>(StackPtr.getNode ())->getIndex ();
14921452 MachinePointerInfo PtrInfo =
@@ -1496,13 +1456,24 @@ SDValue SelectionDAGLegalize::ExpandInsertToVectorThroughStack(SDValue Op) {
14961456 SDValue Ch = DAG.getStore (DAG.getEntryNode (), dl, Vec, StackPtr, PtrInfo);
14971457
14981458 // Then store the inserted part.
1499- SDValue SubStackPtr =
1500- TLI.getVectorSubVecPointer (DAG, StackPtr, VecVT, SubVecVT, Idx);
1459+ if (PartVT.isVector ()) {
1460+ SDValue SubStackPtr =
1461+ TLI.getVectorSubVecPointer (DAG, StackPtr, VecVT, PartVT, Idx);
1462+
1463+ // Store the subvector.
1464+ Ch = DAG.getStore (
1465+ Ch, dl, Part, SubStackPtr,
1466+ MachinePointerInfo::getUnknownStack (DAG.getMachineFunction ()));
1467+ } else {
1468+ SDValue SubStackPtr =
1469+ TLI.getVectorElementPointer (DAG, StackPtr, VecVT, Idx);
15011470
1502- // Store the subvector.
1503- Ch = DAG.getStore (
1504- Ch, dl, Part, SubStackPtr,
1505- MachinePointerInfo::getUnknownStack (DAG.getMachineFunction ()));
1471+ // Store the scalar value.
1472+ Ch = DAG.getTruncStore (
1473+ Ch, dl, Part, SubStackPtr,
1474+ MachinePointerInfo::getUnknownStack (DAG.getMachineFunction ()),
1475+ VecVT.getVectorElementType ());
1476+ }
15061477
15071478 // Finally, load the updated vector.
15081479 return DAG.getLoad (Op.getValueType (), dl, Ch, StackPtr, PtrInfo);
@@ -3416,9 +3387,7 @@ bool SelectionDAGLegalize::ExpandNode(SDNode *Node) {
34163387 Results.push_back (ExpandSCALAR_TO_VECTOR (Node));
34173388 break ;
34183389 case ISD::INSERT_VECTOR_ELT:
3419- Results.push_back (ExpandINSERT_VECTOR_ELT (Node->getOperand (0 ),
3420- Node->getOperand (1 ),
3421- Node->getOperand (2 ), dl));
3390+ Results.push_back (ExpandINSERT_VECTOR_ELT (SDValue (Node, 0 )));
34223391 break ;
34233392 case ISD::VECTOR_SHUFFLE: {
34243393 SmallVector<int , 32 > NewMask;
0 commit comments