[llvm] [VectorCombine] Fold vector.interleave2 with two constant splats (PR #125144)
Min-Yih Hsu via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 30 16:45:12 PST 2025
================
@@ -3145,6 +3146,45 @@ bool VectorCombine::foldInsExtVectorToShuffle(Instruction &I) {
return true;
}
+bool VectorCombine::foldInterleaveIntrinsics(Instruction &I) {
+ // If we're interleaving 2 constant splats, for instance `<vscale x 8 x i32>
+ // <splat of 666>` and `<vscale x 8 x i32> <splat of 777>`, we can create a
+ // larger splat
+ // `<vscale x 8 x i64> <splat of ((777 << 32) | 666)>` first before casting it
+ // back into `<vscale x 16 x i32>`.
+ using namespace PatternMatch;
+ const APInt *SplatVal0, *SplatVal1;
+ if (!match(&I, m_Intrinsic<Intrinsic::vector_interleave2>(
+ m_APInt(SplatVal0), m_APInt(SplatVal1))))
+ return false;
+
+ LLVM_DEBUG(dbgs() << "VC: Folding interleave2 with two splats: " << I
+ << "\n");
+
+ auto *VTy =
+ cast<VectorType>(cast<IntrinsicInst>(I).getArgOperand(0)->getType());
+ auto *ExtVTy = VectorType::getExtendedElementVectorType(VTy);
+ unsigned Width = VTy->getElementType()->getIntegerBitWidth();
+
+ if (TTI.getInstructionCost(&I, CostKind) <
+ TTI.getCastInstrCost(Instruction::BitCast, I.getType(), ExtVTy,
----------------
mshockwave wrote:
We're really just worrying about the legalization cost here, should `ExtVTy` be an illegal type.
https://github.com/llvm/llvm-project/pull/125144
More information about the llvm-commits
mailing list