Skip to content

Commit

Permalink
[SLP]Check if the buildvector root is not a part of the graph before …
Browse files Browse the repository at this point in the history
…deletion

If the buildvector root has no uses, it might be still needed as a part
of the graph, so need to check that it is not a part of the graph before
deletion.

Fixes #116852
  • Loading branch information
alexey-bataev committed Nov 19, 2024
1 parent d8a1c6d commit 79682c4
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
5 changes: 4 additions & 1 deletion llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13614,7 +13614,10 @@ Value *BoUpSLP::gather(
} else {
Vec = CreateShuffle(Root, Vec, Mask);
if (auto *OI = dyn_cast<Instruction>(OriginalRoot);
OI && OI->hasNUses(0))
OI && OI->hasNUses(0) &&
none_of(VectorizableTree, [&](const std::unique_ptr<TreeEntry> &TE) {
return TE->VectorizedValue == OI;
}))
eraseInstruction(OI);
}
}
Expand Down
55 changes: 55 additions & 0 deletions llvm/test/Transforms/SLPVectorizer/X86/bv-root-part-of-graph.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
; RUN: opt -S --passes=slp-vectorizer -mtriple=x86_64-unknown-linux-gnu < %s | FileCheck %s

define void @test() {
; CHECK-LABEL: define void @test() {
; CHECK-NEXT: [[BB:.*]]:
; CHECK-NEXT: [[TMP0:%.*]] = shufflevector <4 x float> <float 0.000000e+00, float undef, float 0.000000e+00, float 0.000000e+00>, <4 x float> poison, <4 x i32> <i32 0, i32 0, i32 2, i32 3>
; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <4 x float> <float 0.000000e+00, float undef, float 0.000000e+00, float 0.000000e+00>, <4 x float> <float poison, float 0.000000e+00, float poison, float poison>, <4 x i32> <i32 0, i32 5, i32 2, i32 3>
; CHECK-NEXT: br label %[[BB1:.*]]
; CHECK: [[BB1]]:
; CHECK-NEXT: [[PHI:%.*]] = phi i32 [ 0, %[[BB]] ], [ [[TMP9:%.*]], %[[BB1]] ]
; CHECK-NEXT: [[FMUL:%.*]] = fmul float 0.000000e+00, 0.000000e+00
; CHECK-NEXT: [[TMP2:%.*]] = insertelement <4 x float> [[TMP1]], float [[FMUL]], i32 2
; CHECK-NEXT: [[TMP3:%.*]] = shufflevector <4 x float> [[TMP2]], <4 x float> poison, <4 x i32> <i32 0, i32 1, i32 2, i32 2>
; CHECK-NEXT: [[TMP4:%.*]] = fadd <4 x float> [[TMP0]], [[TMP3]]
; CHECK-NEXT: [[TMP5:%.*]] = fadd <4 x float> [[TMP4]], zeroinitializer
; CHECK-NEXT: [[TMP6:%.*]] = fcmp ogt <4 x float> [[TMP5]], zeroinitializer
; CHECK-NEXT: [[TMP7:%.*]] = select <4 x i1> [[TMP6]], <4 x i32> zeroinitializer, <4 x i32> zeroinitializer
; CHECK-NEXT: [[TMP8:%.*]] = select <4 x i1> zeroinitializer, <4 x i32> [[TMP7]], <4 x i32> zeroinitializer
; CHECK-NEXT: [[TMP9]] = call i32 @llvm.vector.reduce.or.v4i32(<4 x i32> [[TMP8]])
; CHECK-NEXT: br label %[[BB1]]
;
bb:
br label %bb1

bb1:
%phi = phi i32 [ 0, %bb ], [ %or21, %bb1 ]
%sitofp = sitofp i32 0 to float
%fadd = fadd float %sitofp, %sitofp
%fadd2 = fadd float %fadd, 0.000000e+00
%fcmp = fcmp ogt float %fadd2, 0.000000e+00
%select = select i1 %fcmp, i32 0, i32 0
%select3 = select i1 false, i32 %select, i32 0
%fadd4 = fadd float %sitofp, 0.000000e+00
%fadd5 = fadd float %fadd4, 0.000000e+00
%fcmp6 = fcmp ogt float %fadd5, 0.000000e+00
%select7 = select i1 %fcmp6, i32 0, i32 0
%select8 = select i1 false, i32 %select7, i32 0
%or = or i32 %select3, %select8
%sitofp9 = sitofp i32 0 to float
%fmul = fmul float 0.000000e+00, 0.000000e+00
%fadd10 = fadd float %sitofp9, %fmul
%fadd11 = fadd float %fadd10, 0.000000e+00
%fcmp12 = fcmp ogt float %fadd11, 0.000000e+00
%select13 = select i1 %fcmp12, i32 0, i32 0
%select14 = select i1 false, i32 %select13, i32 0
%or15 = or i32 %select14, %or
%fadd16 = fadd float %fmul, 0.000000e+00
%fadd17 = fadd float %fadd16, 0.000000e+00
%fcmp18 = fcmp ogt float %fadd17, 0.000000e+00
%select19 = select i1 %fcmp18, i32 0, i32 0
%select20 = select i1 false, i32 %select19, i32 0
%or21 = or i32 %or15, %select20
br label %bb1
}

0 comments on commit 79682c4

Please sign in to comment.