[llvm] [InstCombine] Let shrinkSplatShuffle act on vectors of different lengths (PR #148593)

Luke Lau via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 15 22:07:23 PDT 2025


================
@@ -708,11 +708,17 @@ static Instruction *shrinkSplatShuffle(TruncInst &Trunc,
   auto *Shuf = dyn_cast<ShuffleVectorInst>(Trunc.getOperand(0));
   if (Shuf && Shuf->hasOneUse() && match(Shuf->getOperand(1), m_Undef()) &&
       all_equal(Shuf->getShuffleMask()) &&
-      Shuf->getType() == Shuf->getOperand(0)->getType()) {
+      ElementCount::isKnownGE(Shuf->getType()->getElementCount(),
+                              cast<VectorType>(Shuf->getOperand(0)->getType())
+                                  ->getElementCount())) {
     // trunc (shuf X, Undef, SplatMask) --> shuf (trunc X), Poison, SplatMask
     // trunc (shuf X, Poison, SplatMask) --> shuf (trunc X), Poison, SplatMask
-    Value *NarrowOp = Builder.CreateTrunc(Shuf->getOperand(0), Trunc.getType());
-    return new ShuffleVectorInst(NarrowOp, Shuf->getShuffleMask());
+    auto *const NewTruncTy = Shuf->getOperand(0)->getType()->getWithNewType(
+        Trunc.getType()->getScalarType());
+    Value *NarrowOp =
+        Builder.CreateTrunc(Shuf->getOperand(0), NewTruncTy, Trunc.getName());
+    return new ShuffleVectorInst(NarrowOp, Shuf->getShuffleMask(),
+                                 Shuf->getName());
----------------
lukel97 wrote:

I don't think many places in InstCombine preserve the names, should these changes be left out and posted as a separate NFC?

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


More information about the llvm-commits mailing list