@@ -1618,20 +1618,34 @@ void MachineVerifier::verifyPreISelGenericInstruction(const MachineInstr *MI) {
1618
1618
1619
1619
// Don't check that all operands are vector because scalars are used in
1620
1620
// place of 1 element vectors.
1621
- int SrcNumElts = Src0Ty.isVector () ? Src0Ty.getNumElements () : 1 ;
1622
- int DstNumElts = DstTy.isVector () ? DstTy.getNumElements () : 1 ;
1621
+ ElementCount SrcNumElts = Src0Ty.isVector () ? Src0Ty.getElementCount ()
1622
+ : ElementCount::getFixed (1 );
1623
+ ElementCount DstNumElts =
1624
+ DstTy.isVector () ? DstTy.getElementCount () : ElementCount::getFixed (1 );
1623
1625
1624
1626
ArrayRef<int > MaskIdxes = MaskOp.getShuffleMask ();
1625
1627
1626
- if (static_cast <int >(MaskIdxes.size ()) != DstNumElts)
1628
+ // For scalable vectors, there is an entry in the Mask for each
1629
+ // KnownMinValue.
1630
+ if (MaskIdxes.size () != DstNumElts.getKnownMinValue ())
1627
1631
report (" Wrong result type for shufflemask" , MI);
1628
1632
1629
- for (int Idx : MaskIdxes) {
1630
- if (Idx < 0 )
1631
- continue ;
1632
-
1633
- if (Idx >= 2 * SrcNumElts)
1634
- report (" Out of bounds shuffle index" , MI);
1633
+ if (Src0Ty.isScalableVector ()) {
1634
+ if (!llvm::all_of (MaskIdxes,
1635
+ [&MaskIdxes](int M) { return M == MaskIdxes[0 ]; }))
1636
+ report (" Elements of a scalable G_SHUFFLE_VECTOR mask must match" , MI);
1637
+ if (MaskIdxes[0 ] != 0 && MaskIdxes[0 ] != -1 )
1638
+ report (" Elements of a scalable G_SHUFFLE_VECTOR mask be zero or undef" ,
1639
+ MI);
1640
+ } else {
1641
+ // Idxes for fixed vectors must be in bounds or undef, which is
1642
+ // represented as -1.
1643
+ for (int Idx : MaskIdxes) {
1644
+ if (Idx < 0 )
1645
+ continue ;
1646
+ if ((unsigned )Idx >= 2 * SrcNumElts.getFixedValue ())
1647
+ report (" Out of bounds shuffle index" , MI);
1648
+ }
1635
1649
}
1636
1650
1637
1651
break ;
0 commit comments