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

Philip Reames via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 24 07:33:18 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));
----------------
preames wrote:

Same basic misunderstanding here.  For e.g. NF6, the leaf mask needs to be 1/6th of the total elements in the shuffle.  That will be 1/3 of the source size.  Only for NF2 do you happen to be exactly equal to the operand size.  

p.s. Take a look at the constant handling if this is unclear, it's done the same way.

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


More information about the llvm-commits mailing list