Skip to content

Commit b04dd5d

Browse files
committed
[SLP]FIx PR81403: compiler crah because wrongly resized vector value.
The mask for the reshuffling/resizing might be calculated incorrectly, fixed.
1 parent fb48fd1 commit b04dd5d

File tree

2 files changed

+73
-12
lines changed

2 files changed

+73
-12
lines changed

llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10648,19 +10648,13 @@ Value *BoUpSLP::vectorizeOperand(TreeEntry *E, unsigned NodeIdx,
1064810648
// ... (use %2)
1064910649
// %shuffle = shuffle <2 x> %2, poison, <2 x> {2, 0}
1065010650
// br %block
10651-
SmallVector<int> UniqueIdxs(VF, PoisonMaskElem);
10652-
SmallSet<int, 4> UsedIdxs;
10653-
int Pos = 0;
10654-
for (int Idx : VE->ReuseShuffleIndices) {
10655-
if (Idx != static_cast<int>(VF) && Idx != PoisonMaskElem &&
10656-
UsedIdxs.insert(Idx).second)
10657-
UniqueIdxs[Idx] = Pos;
10658-
++Pos;
10651+
SmallVector<int> Mask(VF, PoisonMaskElem);
10652+
for (auto [I, V] : enumerate(VL)) {
10653+
if (isa<PoisonValue>(V))
10654+
continue;
10655+
Mask[I] = VE->findLaneForValue(V);
1065910656
}
10660-
assert(VF >= UsedIdxs.size() && "Expected vectorization factor "
10661-
"less than original vector size.");
10662-
UniqueIdxs.append(VF - UsedIdxs.size(), PoisonMaskElem);
10663-
V = FinalShuffle(V, UniqueIdxs);
10657+
V = FinalShuffle(V, Mask);
1066410658
} else {
1066510659
assert(VF < cast<FixedVectorType>(V->getType())->getNumElements() &&
1066610660
"Expected vectorization factor less "
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 4
2+
; RUN: opt -S --passes=slp-vectorizer -mtriple=s390x-unknown-linux -mcpu=z16 < %s | FileCheck %s
3+
4+
define void @test() {
5+
; CHECK-LABEL: define void @test(
6+
; CHECK-SAME: ) #[[ATTR0:[0-9]+]] {
7+
; CHECK-NEXT: [[TMP1:%.*]] = call i64 @llvm.vector.reduce.xor.v8i64(<8 x i64> zeroinitializer)
8+
; CHECK-NEXT: store i64 [[TMP1]], ptr null, align 8
9+
; CHECK-NEXT: ret void
10+
;
11+
%1 = zext i8 0 to i32
12+
%2 = lshr i32 0, %1
13+
%3 = icmp ult i32 %2, 0
14+
%4 = shl i32 0, %1
15+
%5 = and i32 %4, 0
16+
%narrow = select i1 %3, i32 0, i32 %5
17+
%6 = zext i32 %narrow to i64
18+
%7 = zext i8 0 to i32
19+
%8 = lshr i32 0, %7
20+
%9 = icmp ult i32 %8, 0
21+
%10 = shl i32 0, %7
22+
%11 = and i32 %10, 0
23+
%narrow.1 = select i1 %9, i32 0, i32 %11
24+
%12 = zext i32 %narrow.1 to i64
25+
%13 = xor i64 %6, %12
26+
%14 = zext i8 0 to i32
27+
%15 = lshr i32 0, %14
28+
%16 = icmp ult i32 %15, 0
29+
%17 = shl i32 0, %14
30+
%18 = and i32 %17, 0
31+
%narrow.2 = select i1 %16, i32 0, i32 %18
32+
%19 = zext i32 %narrow.2 to i64
33+
%20 = xor i64 %13, %19
34+
%21 = icmp ult i32 %8, 0
35+
%22 = shl i32 0, %7
36+
%23 = and i32 %22, 0
37+
%narrow.3 = select i1 %21, i32 0, i32 %23
38+
%24 = zext i32 %narrow.3 to i64
39+
%25 = xor i64 %20, %24
40+
%26 = icmp ult i32 %15, 0
41+
%27 = shl i32 0, %14
42+
%28 = and i32 %27, 0
43+
%narrow.4 = select i1 %26, i32 0, i32 %28
44+
%29 = zext i32 %narrow.4 to i64
45+
%30 = xor i64 %25, %29
46+
%31 = icmp ult i32 %8, 0
47+
%32 = shl i32 0, %7
48+
%33 = and i32 %32, 0
49+
%narrow.5 = select i1 %31, i32 0, i32 %33
50+
%34 = zext i32 %narrow.5 to i64
51+
%35 = xor i64 %30, %34
52+
%36 = icmp ult i32 %15, 0
53+
%37 = shl i32 0, %14
54+
%38 = and i32 %37, 0
55+
%narrow.6 = select i1 %36, i32 0, i32 %38
56+
%39 = zext i32 %narrow.6 to i64
57+
%40 = xor i64 %35, %39
58+
%41 = icmp ult i32 %8, 0
59+
%42 = shl i32 0, %7
60+
%43 = and i32 %42, 0
61+
%narrow.7 = select i1 %41, i32 0, i32 %43
62+
%44 = zext i32 %narrow.7 to i64
63+
%45 = xor i64 %40, %44
64+
store i64 %45, ptr null, align 8
65+
ret void
66+
}
67+

0 commit comments

Comments
 (0)