Skip to content

Commit c2ae16f

Browse files
committed
[VectorCombine]Fix a crash during long vector analysis.
If the analysis of the single vector requested, need to use original type to avoid crash
1 parent 9827467 commit c2ae16f

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

llvm/lib/Transforms/Vectorize/VectorCombine.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1473,11 +1473,11 @@ bool VectorCombine::foldShuffleFromReductions(Instruction &I) {
14731473
bool UsesSecondVec =
14741474
any_of(ConcatMask, [&](int M) { return M >= NumInputElts; });
14751475
InstructionCost OldCost = TTI.getShuffleCost(
1476-
UsesSecondVec ? TTI::SK_PermuteTwoSrc : TTI::SK_PermuteSingleSrc, VecType,
1477-
Shuffle->getShuffleMask());
1476+
UsesSecondVec ? TTI::SK_PermuteTwoSrc : TTI::SK_PermuteSingleSrc,
1477+
UsesSecondVec ? VecType : ShuffleInputType, Shuffle->getShuffleMask());
14781478
InstructionCost NewCost = TTI.getShuffleCost(
1479-
UsesSecondVec ? TTI::SK_PermuteTwoSrc : TTI::SK_PermuteSingleSrc, VecType,
1480-
ConcatMask);
1479+
UsesSecondVec ? TTI::SK_PermuteTwoSrc : TTI::SK_PermuteSingleSrc,
1480+
UsesSecondVec ? VecType : ShuffleInputType, ConcatMask);
14811481

14821482
LLVM_DEBUG(dbgs() << "Found a reduction feeding from a shuffle: " << *Shuffle
14831483
<< "\n");
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 3
2+
; RUN: opt -S --passes=vector-combine -mtriple=x86_64-unknown-linux < %s | FileCheck %s
3+
4+
define i16 @test_spill_mixed() {
5+
; CHECK-LABEL: define i16 @test_spill_mixed() {
6+
; CHECK-NEXT: entry:
7+
; CHECK-NEXT: [[TMP0:%.*]] = shufflevector <32 x i32> zeroinitializer, <32 x i32> zeroinitializer, <4 x i32> <i32 28, i32 29, i32 30, i32 31>
8+
; CHECK-NEXT: [[TMP1:%.*]] = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> [[TMP0]])
9+
; CHECK-NEXT: ret i16 0
10+
;
11+
entry:
12+
%0 = shufflevector <32 x i32> zeroinitializer, <32 x i32> zeroinitializer, <4 x i32> <i32 28, i32 29, i32 30, i32 31>
13+
%1 = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %0)
14+
ret i16 0
15+
}
16+
17+
declare i32 @llvm.vector.reduce.add.v4i32(<4 x i32>)

0 commit comments

Comments
 (0)