Skip to content

Commit 8e2b2c4

Browse files
committed
[SLP]Fix PR69196: Instruction does not dominate all uses
During emission of the postponed gathers, need to insert them before user instruction to avoid use before definition crash.
1 parent b3fbb67 commit 8e2b2c4

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11214,7 +11214,7 @@ Value *BoUpSLP::vectorizeTree(
1121411214
TE->VectorizedValue = nullptr;
1121511215
auto *UserI =
1121611216
cast<Instruction>(TE->UserTreeIndices.front().UserTE->VectorizedValue);
11217-
Builder.SetInsertPoint(PrevVec);
11217+
Builder.SetInsertPoint(UserI);
1121811218
Builder.SetCurrentDebugLocation(UserI->getDebugLoc());
1121911219
Value *Vec = vectorizeTree(TE);
1122011220
PrevVec->replaceAllUsesWith(Vec);
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 3
2+
; RUN: opt -S -passes=slp-vectorizer -slp-threshold=-9999 -mtriple=x86_64-unknown-linux-gnu < %s | FileCheck %s
3+
4+
define void @foo() {
5+
; CHECK-LABEL: define void @foo() {
6+
; CHECK-NEXT: bb:
7+
; CHECK-NEXT: [[TMP0:%.*]] = insertelement <2 x i32> <i32 poison, i32 0>, i32 0, i32 0
8+
; CHECK-NEXT: br label [[BB1:%.*]]
9+
; CHECK: bb1:
10+
; CHECK-NEXT: [[TMP1:%.*]] = phi <2 x i32> [ zeroinitializer, [[BB:%.*]] ], [ [[TMP6:%.*]], [[BB4:%.*]] ]
11+
; CHECK-NEXT: [[TMP2:%.*]] = shl <2 x i32> [[TMP1]], [[TMP0]]
12+
; CHECK-NEXT: [[TMP3:%.*]] = or <2 x i32> [[TMP1]], [[TMP0]]
13+
; CHECK-NEXT: [[TMP4:%.*]] = shufflevector <2 x i32> [[TMP2]], <2 x i32> [[TMP3]], <2 x i32> <i32 0, i32 3>
14+
; CHECK-NEXT: [[TMP5:%.*]] = shufflevector <2 x i32> [[TMP4]], <2 x i32> [[TMP1]], <2 x i32> <i32 0, i32 3>
15+
; CHECK-NEXT: [[TMP6]] = or <2 x i32> [[TMP5]], zeroinitializer
16+
; CHECK-NEXT: [[TMP7:%.*]] = extractelement <2 x i32> [[TMP6]], i32 0
17+
; CHECK-NEXT: [[CALL:%.*]] = call i64 null(i32 [[TMP7]])
18+
; CHECK-NEXT: br label [[BB4]]
19+
; CHECK: bb4:
20+
; CHECK-NEXT: br i1 false, label [[BB5:%.*]], label [[BB1]]
21+
; CHECK: bb5:
22+
; CHECK-NEXT: [[TMP8:%.*]] = phi <2 x i32> [ [[TMP4]], [[BB4]] ]
23+
; CHECK-NEXT: ret void
24+
;
25+
bb:
26+
br label %bb1
27+
28+
bb1:
29+
%phi = phi i32 [ 0, %bb ], [ %or, %bb4 ]
30+
%phi2 = phi i32 [ 0, %bb ], [ %or3, %bb4 ]
31+
%and = and i32 0, 0
32+
%shl = shl i32 %phi, %and
33+
%or = or i32 %shl, 0
34+
%call = call i64 null(i32 %or)
35+
%or3 = or i32 %phi2, 0
36+
br label %bb4
37+
38+
bb4:
39+
br i1 false, label %bb5, label %bb1
40+
41+
bb5:
42+
%phi6 = phi i32 [ %shl, %bb4 ]
43+
%phi7 = phi i32 [ %or3, %bb4 ]
44+
ret void
45+
}

0 commit comments

Comments
 (0)