Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
RHS = Builder.CreateZExtOrTrunc(RHS, Splat->getType());
return BinaryOperator::CreateMul(Splat, RHS);
}
}
[[fallthrough]];
Expand Down
7 changes: 4 additions & 3 deletions llvm/test/Transforms/InstCombine/vector-reductions.ll
Original file line number Diff line number Diff line change
Expand Up @@ -469,9 +469,10 @@ define i2 @constant_multiplied_7xi2(i2 %0) {

define i32 @negative_scalable_vector(i32 %0) {
; CHECK-LABEL: @negative_scalable_vector(
; CHECK-NEXT: [[TMP2:%.*]] = insertelement <vscale x 4 x i32> poison, i32 [[TMP0:%.*]], i64 0
; CHECK-NEXT: [[TMP3:%.*]] = shufflevector <vscale x 4 x i32> [[TMP2]], <vscale x 4 x i32> poison, <vscale x 4 x i32> zeroinitializer
; CHECK-NEXT: [[TMP4:%.*]] = tail call i32 @llvm.vector.reduce.add.nxv4i32(<vscale x 4 x i32> [[TMP3]])
; CHECK-NEXT: [[TMP2:%.*]] = call i64 @llvm.vscale.i64()
; CHECK-NEXT: [[DOTTR:%.*]] = trunc i64 [[TMP2]] to i32
; CHECK-NEXT: [[TMP3:%.*]] = shl i32 [[DOTTR]], 2
; CHECK-NEXT: [[TMP4:%.*]] = mul i32 [[TMP0:%.*]], [[TMP3]]
; CHECK-NEXT: ret i32 [[TMP4]]
;
%2 = insertelement <vscale x 4 x i32> poison, i32 %0, i64 0
Expand Down