Skip to content

Commit 376dad7

Browse files
committed
[SLP]Move resulting vector before inert point, if the late generated buildvector fully matched
If the perfect diamond match was detected for the postponed buildvectors and the vector for the previous node comes after the current node, need to move the vector register before the current inserting point to prevent compiler crash. Fixes llvm#119002
1 parent 6797b0f commit 376dad7

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16215,6 +16215,11 @@ BoUpSLP::vectorizeTree(const ExtraValueToDebugLocsMap &ExternallyUsedValues,
1621516215
}
1621616216
Builder.SetCurrentDebugLocation(UserI->getDebugLoc());
1621716217
Value *Vec = vectorizeTree(TE, /*PostponedPHIs=*/false);
16218+
if (auto *VecI = dyn_cast<Instruction>(Vec);
16219+
VecI && VecI->getParent() == Builder.GetInsertBlock() &&
16220+
Builder.GetInsertPoint()->comesBefore(VecI))
16221+
VecI->moveBeforePreserving(*Builder.GetInsertBlock(),
16222+
Builder.GetInsertPoint());
1621816223
if (Vec->getType() != PrevVec->getType()) {
1621916224
assert(Vec->getType()->isIntOrIntVectorTy() &&
1622016225
PrevVec->getType()->isIntOrIntVectorTy() &&
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
2+
; RUN: opt -S --passes=slp-vectorizer -mtriple=x86_64-unknown-linux-gnu -mattr=+avx512f < %s | FileCheck %s
3+
4+
define void @test() {
5+
; CHECK-LABEL: define void @test(
6+
; CHECK-SAME: ) #[[ATTR0:[0-9]+]] {
7+
; CHECK-NEXT: [[BB:.*]]:
8+
; CHECK-NEXT: br label %[[BB1:.*]]
9+
; CHECK: [[BB1]]:
10+
; CHECK-NEXT: [[TMP0:%.*]] = phi <2 x i32> [ zeroinitializer, %[[BB]] ], [ [[TMP4:%.*]], %[[BB4:.*]] ]
11+
; CHECK-NEXT: [[TMP1:%.*]] = or <2 x i32> [[TMP0]], zeroinitializer
12+
; CHECK-NEXT: br i1 false, label %[[BB7:.*]], label %[[BB4]]
13+
; CHECK: [[BB4]]:
14+
; CHECK-NEXT: [[TMP2:%.*]] = shufflevector <2 x i32> [[TMP0]], <2 x i32> <i32 0, i32 poison>, <2 x i32> <i32 2, i32 1>
15+
; CHECK-NEXT: [[TMP3:%.*]] = add <2 x i32> zeroinitializer, [[TMP2]]
16+
; CHECK-NEXT: [[TMP4]] = add <2 x i32> zeroinitializer, [[TMP2]]
17+
; CHECK-NEXT: br i1 false, label %[[BB7]], label %[[BB1]]
18+
; CHECK: [[BB7]]:
19+
; CHECK-NEXT: [[TMP5:%.*]] = phi <2 x i32> [ [[TMP1]], %[[BB1]] ], [ [[TMP3]], %[[BB4]] ]
20+
; CHECK-NEXT: ret void
21+
;
22+
bb:
23+
br label %bb1
24+
25+
bb1:
26+
%phi = phi i32 [ 0, %bb ], [ %add6, %bb4 ]
27+
%phi2 = phi i32 [ 0, %bb ], [ %add, %bb4 ]
28+
%or = or i32 %phi2, 0
29+
%or3 = or i32 %phi, 0
30+
br i1 false, label %bb7, label %bb4
31+
32+
bb4:
33+
%add = add i32 0, 0
34+
%add5 = add i32 0, 0
35+
%add6 = add i32 %phi, 0
36+
br i1 false, label %bb7, label %bb1
37+
38+
bb7:
39+
%phi8 = phi i32 [ %or, %bb1 ], [ %add5, %bb4 ]
40+
%phi9 = phi i32 [ %or3, %bb1 ], [ %add6, %bb4 ]
41+
ret void
42+
}

0 commit comments

Comments
 (0)