[llvm] [InstCombine] Transform `vector.reduce.add` and `splat` into multiplication (PR #161020)
Hongyu Chen via llvm-commits
llvm-commits at lists.llvm.org
Sun Sep 28 08:36:32 PDT 2025
================
@@ -3761,6 +3762,26 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
return replaceInstUsesWith(CI, Res);
}
}
+
+ // Handle the case where a splat is summarized. In that case we have a
+ // multpilication. For example: %2 = insertelement <4 x i32> poison, i32
+ // %0, i64 0 %3 = shufflevector <4 x i32> %2, poison, <4 x i32>
+ // zeroinitializer %4 = tail call i32 @llvm.vector.reduce.add.v4i32(%3)
+ // =>
+ // %2 = mul i32 %0, 4
+ if (Value *Splat = getSplatValue(Arg)) {
+ // It is only a multiplication if we add the same element over and over.
+ assert(Arg->getType()->isVectorTy() &&
+ "The vector.reduce.add intrinsic's argument must be a vector!");
----------------
XChy wrote:
```suggestion
```
Remove the assertion. `cast<VectorType>` will assert itself.
https://github.com/llvm/llvm-project/pull/161020
More information about the llvm-commits
mailing list