@@ -5222,53 +5222,59 @@ LegalizerHelper::fewerElementsVectorExtractInsertVectorElt(MachineInstr &MI,
5222
5222
InsertVal = MI.getOperand (2 ).getReg ();
5223
5223
5224
5224
Register Idx = MI.getOperand (MI.getNumOperands () - 1 ).getReg ();
5225
-
5226
- // TODO: Handle total scalarization case.
5227
- if (!NarrowVecTy.isVector ())
5228
- return UnableToLegalize;
5229
-
5230
5225
LLT VecTy = MRI.getType (SrcVec);
5231
5226
5232
5227
// If the index is a constant, we can really break this down as you would
5233
5228
// expect, and index into the target size pieces.
5234
- int64_t IdxVal;
5235
5229
auto MaybeCst = getIConstantVRegValWithLookThrough (Idx, MRI);
5236
5230
if (MaybeCst) {
5237
- IdxVal = MaybeCst->Value .getSExtValue ();
5231
+ uint64_t IdxVal = MaybeCst->Value .getZExtValue ();
5238
5232
// Avoid out of bounds indexing the pieces.
5239
5233
if (IdxVal >= VecTy.getNumElements ()) {
5240
5234
MIRBuilder.buildUndef (DstReg);
5241
5235
MI.eraseFromParent ();
5242
5236
return Legalized;
5243
5237
}
5244
5238
5245
- SmallVector<Register, 8 > VecParts;
5246
- LLT GCDTy = extractGCDType (VecParts, VecTy, NarrowVecTy, SrcVec);
5239
+ if (!NarrowVecTy.isVector ()) {
5240
+ SmallVector<Register, 8 > SplitPieces;
5241
+ extractParts (MI.getOperand (1 ).getReg (), NarrowVecTy,
5242
+ VecTy.getNumElements (), SplitPieces, MIRBuilder, MRI);
5243
+ if (IsInsert) {
5244
+ SplitPieces[IdxVal] = InsertVal;
5245
+ MIRBuilder.buildMergeLikeInstr (MI.getOperand (0 ).getReg (), SplitPieces);
5246
+ } else {
5247
+ MIRBuilder.buildCopy (MI.getOperand (0 ).getReg (), SplitPieces[IdxVal]);
5248
+ }
5249
+ } else {
5250
+ SmallVector<Register, 8 > VecParts;
5251
+ LLT GCDTy = extractGCDType (VecParts, VecTy, NarrowVecTy, SrcVec);
5247
5252
5248
- // Build a sequence of NarrowTy pieces in VecParts for this operand.
5249
- LLT LCMTy = buildLCMMergePieces (VecTy, NarrowVecTy, GCDTy, VecParts,
5250
- TargetOpcode::G_ANYEXT);
5253
+ // Build a sequence of NarrowTy pieces in VecParts for this operand.
5254
+ LLT LCMTy = buildLCMMergePieces (VecTy, NarrowVecTy, GCDTy, VecParts,
5255
+ TargetOpcode::G_ANYEXT);
5251
5256
5252
- unsigned NewNumElts = NarrowVecTy.getNumElements ();
5257
+ unsigned NewNumElts = NarrowVecTy.getNumElements ();
5253
5258
5254
- LLT IdxTy = MRI.getType (Idx);
5255
- int64_t PartIdx = IdxVal / NewNumElts;
5256
- auto NewIdx =
5257
- MIRBuilder.buildConstant (IdxTy, IdxVal - NewNumElts * PartIdx);
5259
+ LLT IdxTy = MRI.getType (Idx);
5260
+ int64_t PartIdx = IdxVal / NewNumElts;
5261
+ auto NewIdx =
5262
+ MIRBuilder.buildConstant (IdxTy, IdxVal - NewNumElts * PartIdx);
5258
5263
5259
- if (IsInsert) {
5260
- LLT PartTy = MRI.getType (VecParts[PartIdx]);
5264
+ if (IsInsert) {
5265
+ LLT PartTy = MRI.getType (VecParts[PartIdx]);
5261
5266
5262
- // Use the adjusted index to insert into one of the subvectors.
5263
- auto InsertPart = MIRBuilder.buildInsertVectorElement (
5264
- PartTy, VecParts[PartIdx], InsertVal, NewIdx);
5265
- VecParts[PartIdx] = InsertPart.getReg (0 );
5267
+ // Use the adjusted index to insert into one of the subvectors.
5268
+ auto InsertPart = MIRBuilder.buildInsertVectorElement (
5269
+ PartTy, VecParts[PartIdx], InsertVal, NewIdx);
5270
+ VecParts[PartIdx] = InsertPart.getReg (0 );
5266
5271
5267
- // Recombine the inserted subvector with the others to reform the result
5268
- // vector.
5269
- buildWidenedRemergeToDst (DstReg, LCMTy, VecParts);
5270
- } else {
5271
- MIRBuilder.buildExtractVectorElement (DstReg, VecParts[PartIdx], NewIdx);
5272
+ // Recombine the inserted subvector with the others to reform the result
5273
+ // vector.
5274
+ buildWidenedRemergeToDst (DstReg, LCMTy, VecParts);
5275
+ } else {
5276
+ MIRBuilder.buildExtractVectorElement (DstReg, VecParts[PartIdx], NewIdx);
5277
+ }
5272
5278
}
5273
5279
5274
5280
MI.eraseFromParent ();
0 commit comments