Skip to content

Commit 96806a7

Browse files
committed
[SLP]Gather copyable node, if its parent is copyable, but this node is still used outside of the block only
If the current node is a copyable node and its parent is copyable too and still current node is only used outside, better to cancel scheduling for such node, because otherwise there might be wrong def-use chain built during vectorization. Fixes llvm#166775
1 parent 4c605e9 commit 96806a7

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20996,6 +20996,15 @@ BoUpSLP::BlockScheduling::tryScheduleBundle(ArrayRef<Value *> VL, BoUpSLP *SLP,
2099620996
return false;
2099720997
}))
2099820998
return std::nullopt;
20999+
if (S.areInstructionsWithCopyableElements() && EI && EI.UserTE->hasState() &&
21000+
EI.UserTE->hasCopyableElements() &&
21001+
EI.UserTE->getMainOp()->getParent() == S.getMainOp()->getParent() &&
21002+
all_of(VL, [&](Value *V) {
21003+
if (S.isCopyableElement(V))
21004+
return true;
21005+
return isUsedOutsideBlock(V);
21006+
}))
21007+
return std::nullopt;
2099921008
bool HasCopyables = S.areInstructionsWithCopyableElements();
2100021009
if (((!HasCopyables && doesNotNeedToSchedule(VL)) ||
2100121010
all_of(VL, [&](Value *V) { return S.isNonSchedulable(V); }))) {
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6
2+
; RUN: opt -passes=slp-vectorizer -S -slp-threshold=-99999 -mtriple=x86_64-unknown-linux-gnu < %s | FileCheck %s
3+
4+
define <4 x i32> @test() {
5+
; CHECK-LABEL: define <4 x i32> @test() {
6+
; CHECK-NEXT: [[BB:.*:]]
7+
; CHECK-NEXT: [[TRUNC:%.*]] = trunc i64 0 to i32
8+
; CHECK-NEXT: br label %[[BB1:.*]]
9+
; CHECK: [[BB1]]:
10+
; CHECK-NEXT: [[OR:%.*]] = or i32 [[TRUNC]], 0
11+
; CHECK-NEXT: [[TMP0:%.*]] = insertelement <4 x i32> poison, i32 [[TRUNC]], i32 0
12+
; CHECK-NEXT: [[TMP1:%.*]] = insertelement <4 x i32> [[TMP0]], i32 0, i32 1
13+
; CHECK-NEXT: [[TMP2:%.*]] = shufflevector <4 x i32> [[TMP1]], <4 x i32> poison, <4 x i32> <i32 0, i32 1, i32 0, i32 0>
14+
; CHECK-NEXT: [[TMP3:%.*]] = or <4 x i32> [[TMP2]], zeroinitializer
15+
; CHECK-NEXT: [[ZEXT:%.*]] = zext i32 [[OR]] to i64
16+
; CHECK-NEXT: br label %[[BB3:.*]]
17+
; CHECK: [[BB3]]:
18+
; CHECK-NEXT: ret <4 x i32> [[TMP3]]
19+
;
20+
bb:
21+
%trunc = trunc i64 0 to i32
22+
br label %bb1
23+
24+
bb1:
25+
%or = or i32 %trunc, 0
26+
%zext = zext i32 %or to i64
27+
%and = and i32 0, 0
28+
%or2 = or i32 %trunc, 0
29+
br label %bb3
30+
31+
bb3:
32+
%0 = insertelement <4 x i32> zeroinitializer, i32 %trunc, i32 0
33+
%1 = insertelement <4 x i32> %0, i32 %and, i32 1
34+
%2 = insertelement <4 x i32> %1, i32 %or2, i32 2
35+
%3 = insertelement <4 x i32> %2, i32 %or, i32 3
36+
ret <4 x i32> %3
37+
}

0 commit comments

Comments
 (0)