[llvm] [IA] Recognize repeated masks which come from shuffle vectors (PR #150285)

Luke Lau via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 24 09:21:27 PDT 2025


================
@@ -587,6 +587,19 @@ static Value *getMask(Value *WideMask, unsigned Factor,
     }
   }
 
+  if (auto *SVI = dyn_cast<ShuffleVectorInst>(WideMask)) {
+    unsigned LeafMaskLen = LeafValueEC.getFixedValue();
+    if (SVI->isInterleave(Factor) &&
+        llvm::all_of(SVI->getShuffleMask(),
+                     [&](int Idx) { return Idx < (int)LeafMaskLen; })) {
+      auto *LeafMaskTy =
+          FixedVectorType::get(Type::getInt1Ty(SVI->getContext()), LeafMaskLen);
+      IRBuilder<> Builder(SVI);
+      return Builder.CreateExtractVector(LeafMaskTy, SVI->getOperand(0),
+                                         uint64_t(0));
----------------
lukel97 wrote:

Ah right, looking at the constant handling case does clarify things. But the bit that's throwing me off is that do we not need to check the width of SVI->getOperand(0) somewhere? For factor 2, WideMask.width = 8, I think `%interleaved.mask = shufflevector <2 x i1> %m, <2 x i1> poison, <8 x i32> <i32 0, i32 0, i32 1, i32 1, i32 2, i32 2, i32 3, i32 3>` would still be recognised as an interleave?

And we would be trying to extract a <4 x i1> out of a <4 x i1>

https://github.com/llvm/llvm-project/pull/150285


More information about the llvm-commits mailing list