[llvm] Extend vector.reduce.add and splat transform to scalable vectors (PR #161101)
Gábor Spaits via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 29 00:57:17 PDT 2025
================
@@ -3785,13 +3785,19 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
// vector.reduce.add.vNiM(splat(%x)) -> mul(%x, N)
if (Value *Splat = getSplatValue(Arg)) {
- ElementCount VecToReduceCount =
- cast<VectorType>(Arg->getType())->getElementCount();
+ VectorType *VecToReduceTy = cast<VectorType>(Arg->getType());
+ ElementCount VecToReduceCount = VecToReduceTy->getElementCount();
+ Value *RHS;
if (VecToReduceCount.isFixed()) {
unsigned VectorSize = VecToReduceCount.getFixedValue();
- return BinaryOperator::CreateMul(
- Splat, ConstantInt::get(Splat->getType(), VectorSize));
+ RHS = ConstantInt::get(Splat->getType(), VectorSize);
}
+
+ RHS = Builder.CreateElementCount(Type::getInt64Ty(II->getContext()),
+ VecToReduceCount);
+ if (Splat->getType() != RHS->getType())
----------------
spaits wrote:
I will remove the check. I only did it because I see the same check a few lines above:
https://github.com/llvm/llvm-project/pull/161101/files#diff-bc7e40810dd612e1bea85874e9ee09c840e5d7ba1ddf2c164965aa9f366ead67R3777
Just there they do it with `Res` vector an `II` call. Is the check redundant there too? If so, may I remove that too?
https://github.com/llvm/llvm-project/pull/161101
More information about the llvm-commits
mailing list