@@ -118,14 +118,7 @@ class SelectionDAGLegalize {
118
118
void LegalizeLoadOps (SDNode *Node);
119
119
void LegalizeStoreOps (SDNode *Node);
120
120
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);
129
122
130
123
// / Return a vector shuffle operation which
131
124
// / performs the same shuffe in terms of order or result bytes, but on a type
@@ -378,45 +371,12 @@ SDValue SelectionDAGLegalize::ExpandConstant(ConstantSDNode *CP) {
378
371
return Result;
379
372
}
380
373
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);
416
379
417
- SDValue SelectionDAGLegalize::ExpandINSERT_VECTOR_ELT (SDValue Vec, SDValue Val,
418
- SDValue Idx,
419
- const SDLoc &dl) {
420
380
if (ConstantSDNode *InsertPos = dyn_cast<ConstantSDNode>(Idx)) {
421
381
// SCALAR_TO_VECTOR requires that the type of the value being inserted
422
382
// match the element type of the vector being created, except for
@@ -438,7 +398,7 @@ SDValue SelectionDAGLegalize::ExpandINSERT_VECTOR_ELT(SDValue Vec, SDValue Val,
438
398
return DAG.getVectorShuffle (Vec.getValueType (), dl, Vec, ScVec, ShufOps);
439
399
}
440
400
}
441
- return PerformInsertVectorEltInMemory (Vec, Val, Idx, dl );
401
+ return ExpandInsertToVectorThroughStack (Op );
442
402
}
443
403
444
404
SDValue SelectionDAGLegalize::OptimizeFloatStore (StoreSDNode* ST) {
@@ -1486,7 +1446,7 @@ SDValue SelectionDAGLegalize::ExpandInsertToVectorThroughStack(SDValue Op) {
1486
1446
1487
1447
// Store the value to a temporary stack slot, then LOAD the returned part.
1488
1448
EVT VecVT = Vec.getValueType ();
1489
- EVT SubVecVT = Part.getValueType ();
1449
+ EVT PartVT = Part.getValueType ();
1490
1450
SDValue StackPtr = DAG.CreateStackTemporary (VecVT);
1491
1451
int FI = cast<FrameIndexSDNode>(StackPtr.getNode ())->getIndex ();
1492
1452
MachinePointerInfo PtrInfo =
@@ -1496,13 +1456,24 @@ SDValue SelectionDAGLegalize::ExpandInsertToVectorThroughStack(SDValue Op) {
1496
1456
SDValue Ch = DAG.getStore (DAG.getEntryNode (), dl, Vec, StackPtr, PtrInfo);
1497
1457
1498
1458
// 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);
1501
1470
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
+ }
1506
1477
1507
1478
// Finally, load the updated vector.
1508
1479
return DAG.getLoad (Op.getValueType (), dl, Ch, StackPtr, PtrInfo);
@@ -3416,9 +3387,7 @@ bool SelectionDAGLegalize::ExpandNode(SDNode *Node) {
3416
3387
Results.push_back (ExpandSCALAR_TO_VECTOR (Node));
3417
3388
break ;
3418
3389
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 )));
3422
3391
break ;
3423
3392
case ISD::VECTOR_SHUFFLE: {
3424
3393
SmallVector<int , 32 > NewMask;
0 commit comments