Skip to content

Commit

Permalink
[VectorCombine]Fix a crash during long vector analysis.
Browse files Browse the repository at this point in the history
If the analysis of the single vector requested, need to use original
type to avoid crash
  • Loading branch information
alexey-bataev committed Oct 9, 2023
1 parent 9827467 commit c2ae16f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
8 changes: 4 additions & 4 deletions llvm/lib/Transforms/Vectorize/VectorCombine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1473,11 +1473,11 @@ bool VectorCombine::foldShuffleFromReductions(Instruction &I) {
bool UsesSecondVec =
any_of(ConcatMask, [&](int M) { return M >= NumInputElts; });
InstructionCost OldCost = TTI.getShuffleCost(
UsesSecondVec ? TTI::SK_PermuteTwoSrc : TTI::SK_PermuteSingleSrc, VecType,
Shuffle->getShuffleMask());
UsesSecondVec ? TTI::SK_PermuteTwoSrc : TTI::SK_PermuteSingleSrc,
UsesSecondVec ? VecType : ShuffleInputType, Shuffle->getShuffleMask());
InstructionCost NewCost = TTI.getShuffleCost(
UsesSecondVec ? TTI::SK_PermuteTwoSrc : TTI::SK_PermuteSingleSrc, VecType,
ConcatMask);
UsesSecondVec ? TTI::SK_PermuteTwoSrc : TTI::SK_PermuteSingleSrc,
UsesSecondVec ? VecType : ShuffleInputType, ConcatMask);

LLVM_DEBUG(dbgs() << "Found a reduction feeding from a shuffle: " << *Shuffle
<< "\n");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 3
; RUN: opt -S --passes=vector-combine -mtriple=x86_64-unknown-linux < %s | FileCheck %s

define i16 @test_spill_mixed() {
; CHECK-LABEL: define i16 @test_spill_mixed() {
; CHECK-NEXT: entry:
; CHECK-NEXT: [[TMP0:%.*]] = shufflevector <32 x i32> zeroinitializer, <32 x i32> zeroinitializer, <4 x i32> <i32 28, i32 29, i32 30, i32 31>
; CHECK-NEXT: [[TMP1:%.*]] = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> [[TMP0]])
; CHECK-NEXT: ret i16 0
;
entry:
%0 = shufflevector <32 x i32> zeroinitializer, <32 x i32> zeroinitializer, <4 x i32> <i32 28, i32 29, i32 30, i32 31>
%1 = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %0)
ret i16 0
}

declare i32 @llvm.vector.reduce.add.v4i32(<4 x i32>)

0 comments on commit c2ae16f

Please sign in to comment.