[llvm] [VectorCombine] Allow shuffling between vectors the same type but different element sizes (PR #121216)

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 2 05:35:22 PST 2025


================
@@ -3018,24 +3018,37 @@ bool VectorCombine::foldInsExtVectorToShuffle(Instruction &I) {
     return false;
 
   auto *VecTy = dyn_cast<FixedVectorType>(I.getType());
-  if (!VecTy || SrcVec->getType() != VecTy)
+  auto *SrcVecTy = dyn_cast<FixedVectorType>(SrcVec->getType());
+  // We can try combining vectors with different element sizes.
+  if (!VecTy || !SrcVecTy ||
+      SrcVecTy->getElementType() != VecTy->getElementType())
     return false;
 
   unsigned NumElts = VecTy->getNumElements();
-  if (ExtIdx >= NumElts || InsIdx >= NumElts)
+  unsigned NumSrcElts = SrcVecTy->getNumElements();
+  if (InsIdx >= NumElts || NumElts == 1)
----------------
RKSimon wrote:

Add ExtIdx >= NumSrcElts check

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


More information about the llvm-commits mailing list