[llvm] [InstCombine] Move extends across identity shuffles. (PR #146901)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 8 04:58:47 PDT 2025
================
@@ -2591,15 +2590,31 @@ static Instruction *foldCastShuffle(ShuffleVectorInst &Shuf,
return nullptr;
}
+ VectorType *CastSrcTy = cast<VectorType>(Cast0->getSrcTy());
VectorType *ShufTy = Shuf.getType();
VectorType *ShufOpTy = cast<VectorType>(Shuf.getOperand(0)->getType());
- VectorType *CastSrcTy = cast<VectorType>(Cast0->getSrcTy());
// TODO: Allow length-increasing shuffles?
if (ShufTy->getElementCount().getKnownMinValue() >
ShufOpTy->getElementCount().getKnownMinValue())
return nullptr;
+ // shuffle (cast X), Poison, identity-with-extract-mask -->
+ // cast (shuffle X, Poison, identity-with-extract-mask).
+ if (Cast0->hasOneUse() && Shuf.isIdentityWithExtract() &&
+ isa<PoisonValue>(Shuf.getOperand(1))) {
----------------
fhahn wrote:
Thanks, updated the check. I think the poison check is needed, because `isIdentityWithExtract` also allows to select all elements from the second vector operand, as @dtcxzyw 's test case showed
https://github.com/llvm/llvm-project/pull/146901
More information about the llvm-commits
mailing list