@@ -1247,28 +1247,31 @@ Value *InstCombiner::SimplifyDemandedVectorElts(Value *V, APInt DemandedElts,
1247
1247
break ;
1248
1248
}
1249
1249
case Instruction::ShuffleVector: {
1250
- ShuffleVectorInst *Shuffle = cast<ShuffleVectorInst>(I);
1251
- unsigned LHSVWidth =
1252
- Shuffle->getOperand (0 )->getType ()->getVectorNumElements ();
1253
- APInt LeftDemanded (LHSVWidth, 0 ), RightDemanded (LHSVWidth, 0 );
1250
+ auto *Shuffle = cast<ShuffleVectorInst>(I);
1251
+ assert (Shuffle->getOperand (0 )->getType () ==
1252
+ Shuffle->getOperand (1 )->getType () &&
1253
+ " Expected shuffle operands to have same type" );
1254
+ unsigned OpWidth =
1255
+ Shuffle->getOperand (0 )->getType ()->getVectorNumElements ();
1256
+ APInt LeftDemanded (OpWidth, 0 ), RightDemanded (OpWidth, 0 );
1254
1257
for (unsigned i = 0 ; i < VWidth; i++) {
1255
1258
if (DemandedElts[i]) {
1256
1259
unsigned MaskVal = Shuffle->getMaskValue (i);
1257
1260
if (MaskVal != -1u ) {
1258
- assert (MaskVal < LHSVWidth * 2 &&
1261
+ assert (MaskVal < OpWidth * 2 &&
1259
1262
" shufflevector mask index out of range!" );
1260
- if (MaskVal < LHSVWidth )
1263
+ if (MaskVal < OpWidth )
1261
1264
LeftDemanded.setBit (MaskVal);
1262
1265
else
1263
- RightDemanded.setBit (MaskVal - LHSVWidth );
1266
+ RightDemanded.setBit (MaskVal - OpWidth );
1264
1267
}
1265
1268
}
1266
1269
}
1267
1270
1268
- APInt LHSUndefElts (LHSVWidth , 0 );
1271
+ APInt LHSUndefElts (OpWidth , 0 );
1269
1272
simplifyAndSetOp (I, 0 , LeftDemanded, LHSUndefElts);
1270
1273
1271
- APInt RHSUndefElts (LHSVWidth , 0 );
1274
+ APInt RHSUndefElts (OpWidth , 0 );
1272
1275
simplifyAndSetOp (I, 1 , RightDemanded, RHSUndefElts);
1273
1276
1274
1277
bool NewUndefElts = false ;
@@ -1283,23 +1286,23 @@ Value *InstCombiner::SimplifyDemandedVectorElts(Value *V, APInt DemandedElts,
1283
1286
} else if (!DemandedElts[i]) {
1284
1287
NewUndefElts = true ;
1285
1288
UndefElts.setBit (i);
1286
- } else if (MaskVal < LHSVWidth ) {
1289
+ } else if (MaskVal < OpWidth ) {
1287
1290
if (LHSUndefElts[MaskVal]) {
1288
1291
NewUndefElts = true ;
1289
1292
UndefElts.setBit (i);
1290
1293
} else {
1291
- LHSIdx = LHSIdx == -1u ? i : LHSVWidth ;
1292
- LHSValIdx = LHSValIdx == -1u ? MaskVal : LHSVWidth ;
1294
+ LHSIdx = LHSIdx == -1u ? i : OpWidth ;
1295
+ LHSValIdx = LHSValIdx == -1u ? MaskVal : OpWidth ;
1293
1296
LHSUniform = LHSUniform && (MaskVal == i);
1294
1297
}
1295
1298
} else {
1296
- if (RHSUndefElts[MaskVal - LHSVWidth ]) {
1299
+ if (RHSUndefElts[MaskVal - OpWidth ]) {
1297
1300
NewUndefElts = true ;
1298
1301
UndefElts.setBit (i);
1299
1302
} else {
1300
- RHSIdx = RHSIdx == -1u ? i : LHSVWidth ;
1301
- RHSValIdx = RHSValIdx == -1u ? MaskVal - LHSVWidth : LHSVWidth ;
1302
- RHSUniform = RHSUniform && (MaskVal - LHSVWidth == i);
1303
+ RHSIdx = RHSIdx == -1u ? i : OpWidth ;
1304
+ RHSValIdx = RHSValIdx == -1u ? MaskVal - OpWidth : OpWidth ;
1305
+ RHSUniform = RHSUniform && (MaskVal - OpWidth == i);
1303
1306
}
1304
1307
}
1305
1308
}
@@ -1308,20 +1311,20 @@ Value *InstCombiner::SimplifyDemandedVectorElts(Value *V, APInt DemandedElts,
1308
1311
// this constant vector to single insertelement instruction.
1309
1312
// shufflevector V, C, <v1, v2, .., ci, .., vm> ->
1310
1313
// insertelement V, C[ci], ci-n
1311
- if (LHSVWidth == Shuffle->getType ()->getNumElements ()) {
1314
+ if (OpWidth == Shuffle->getType ()->getNumElements ()) {
1312
1315
Value *Op = nullptr ;
1313
1316
Constant *Value = nullptr ;
1314
1317
unsigned Idx = -1u ;
1315
1318
1316
1319
// Find constant vector with the single element in shuffle (LHS or RHS).
1317
- if (LHSIdx < LHSVWidth && RHSUniform) {
1320
+ if (LHSIdx < OpWidth && RHSUniform) {
1318
1321
if (auto *CV = dyn_cast<ConstantVector>(Shuffle->getOperand (0 ))) {
1319
1322
Op = Shuffle->getOperand (1 );
1320
1323
Value = CV->getOperand (LHSValIdx);
1321
1324
Idx = LHSIdx;
1322
1325
}
1323
1326
}
1324
- if (RHSIdx < LHSVWidth && LHSUniform) {
1327
+ if (RHSIdx < OpWidth && LHSUniform) {
1325
1328
if (auto *CV = dyn_cast<ConstantVector>(Shuffle->getOperand (1 ))) {
1326
1329
Op = Shuffle->getOperand (0 );
1327
1330
Value = CV->getOperand (RHSValIdx);
0 commit comments