@@ -3472,6 +3472,59 @@ LegalizerHelper::fewerElementsVectorBuildVector(MachineInstr &MI,
3472
3472
return Legalized;
3473
3473
}
3474
3474
3475
+ LegalizerHelper::LegalizeResult
3476
+ LegalizerHelper::fewerElementsVectorExtractVectorElt (MachineInstr &MI,
3477
+ unsigned TypeIdx,
3478
+ LLT NarrowVecTy) {
3479
+ assert (TypeIdx == 1 && " not a vector type index" );
3480
+
3481
+ // TODO: Handle total scalarization case.
3482
+ if (!NarrowVecTy.isVector ())
3483
+ return UnableToLegalize;
3484
+
3485
+ Register DstReg = MI.getOperand (0 ).getReg ();
3486
+ Register SrcVec = MI.getOperand (1 ).getReg ();
3487
+ Register Idx = MI.getOperand (2 ).getReg ();
3488
+ LLT VecTy = MRI.getType (SrcVec);
3489
+
3490
+ // If the index is a constant, we can really break this down as you would
3491
+ // expect, and index into the target size pieces.
3492
+ int64_t IdxVal;
3493
+ if (mi_match (Idx, MRI, m_ICst (IdxVal))) {
3494
+ // Avoid out of bounds indexing the pieces.
3495
+ if (IdxVal >= VecTy.getNumElements ()) {
3496
+ MIRBuilder.buildUndef (DstReg);
3497
+ MI.eraseFromParent ();
3498
+ return Legalized;
3499
+ }
3500
+
3501
+ SmallVector<Register, 8 > VecParts;
3502
+ LLT GCDTy = extractGCDType (VecParts, VecTy, NarrowVecTy, SrcVec);
3503
+
3504
+ // Build a sequence of NarrowTy pieces in VecParts for this operand.
3505
+ buildLCMMergePieces (VecTy, NarrowVecTy, GCDTy, VecParts,
3506
+ TargetOpcode::G_ANYEXT);
3507
+
3508
+ unsigned NewNumElts = NarrowVecTy.getNumElements ();
3509
+
3510
+ LLT IdxTy = MRI.getType (Idx);
3511
+ int64_t PartIdx = IdxVal / NewNumElts;
3512
+ auto NewIdx =
3513
+ MIRBuilder.buildConstant (IdxTy, IdxVal - NewNumElts * PartIdx);
3514
+
3515
+ MIRBuilder.buildExtractVectorElement (DstReg, VecParts[PartIdx], NewIdx);
3516
+ MI.eraseFromParent ();
3517
+ return Legalized;
3518
+ }
3519
+
3520
+ // With a variable index, we can't perform the extract in a smaller type, so
3521
+ // we're forced to expand this.
3522
+ //
3523
+ // TODO: We could emit a chain of compare/select to figure out which piece to
3524
+ // index.
3525
+ return lowerExtractVectorElt (MI);
3526
+ }
3527
+
3475
3528
LegalizerHelper::LegalizeResult
3476
3529
LegalizerHelper::reduceLoadStoreWidth (MachineInstr &MI, unsigned TypeIdx,
3477
3530
LLT NarrowTy) {
@@ -3801,6 +3854,8 @@ LegalizerHelper::fewerElementsVector(MachineInstr &MI, unsigned TypeIdx,
3801
3854
return fewerElementsVectorUnmergeValues (MI, TypeIdx, NarrowTy);
3802
3855
case G_BUILD_VECTOR:
3803
3856
return fewerElementsVectorBuildVector (MI, TypeIdx, NarrowTy);
3857
+ case G_EXTRACT_VECTOR_ELT:
3858
+ return fewerElementsVectorExtractVectorElt (MI, TypeIdx, NarrowTy);
3804
3859
case G_LOAD:
3805
3860
case G_STORE:
3806
3861
return reduceLoadStoreWidth (MI, TypeIdx, NarrowTy);
0 commit comments