[llvm-branch-commits] [llvm] [PatternMatch] match splats from an all-zeroes shufflevector (PR #226190)
Graham Hunter via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Fri Sep 25 03:49:09 PDT 2026
================
@@ -218,14 +218,29 @@ template <typename SubPattern_t> struct Splat_match {
auto *Splat = C->getSplatValue();
return Splat ? SubPattern.match(Splat) : false;
}
- // TODO: Extend to other cases (e.g. shufflevectors).
- return false;
+
+ auto *Shuffle = dyn_cast<ShuffleVectorInst>(V);
+ if (!Shuffle || !Shuffle->isZeroEltSplat())
+ return false;
+
+ // Look for an insertelement.
+ auto *Insert = dyn_cast<InsertElementInst>(Shuffle->getOperand(0));
+ if (!Insert)
+ return false;
+
+ Value *SplatElt = Insert->getOperand(1);
+ ConstantInt *Idx = dyn_cast<ConstantInt>(Insert->getOperand(2));
+ if (!Idx || Idx->getZExtValue() != 0)
+ return false;
+
+ return SubPattern.match(SplatElt);
+ // TODO: Handle other splat patterns.
----------------
huntergr-arm wrote:
It's possible that we could splat an arbitrary element from an existing vector, e.g. from a vector load.
I don't think that's worth worrying about right now, and it's possible that the canonical form for that would be an extractelement -> insertelement at 0 -> zeroeltsplat anyway.
https://github.com/llvm/llvm-project/pull/226190
More information about the llvm-branch-commits
mailing list