Skip to content

Commit 7c963fd

Browse files
committed
[SLP]Use revectorized value for extracts from buildvector, beeing
vectorized. If the insertelement instruction is vectorized, and the extractelement instruction from such insertelement also vectorized as part of the same tree, need to extract from the corresponding for insertelement vectorized value rather than original insertelement instruction.
1 parent ee94e54 commit 7c963fd

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11139,6 +11139,8 @@ Value *BoUpSLP::vectorizeTree(TreeEntry *E, bool PostponedPHIs) {
1113911139

1114011140
case Instruction::ExtractElement: {
1114111141
Value *V = E->getSingleOperand(0);
11142+
if (const TreeEntry *TE = getTreeEntry(V))
11143+
V = TE->VectorizedValue;
1114211144
setInsertPointAfterBundle(E);
1114311145
V = FinalShuffle(V, E, VecTy, IsSigned);
1114411146
E->VectorizedValue = V;

llvm/test/Transforms/SLPVectorizer/X86/gather_extract_from_vectorbuild.ll

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,30 @@ loop:
3131
%i4 = extractelement <2 x float> %ins1, i64 0
3232
br label %loop
3333
}
34+
35+
define void @test1() {
36+
; CHECK-LABEL: define void @test1() {
37+
; CHECK-NEXT: entry:
38+
; CHECK-NEXT: br label [[LOOP:%.*]]
39+
; CHECK: loop:
40+
; CHECK-NEXT: [[TMP0:%.*]] = phi <2 x float> [ zeroinitializer, [[ENTRY:%.*]] ], [ [[TMP2:%.*]], [[LOOP]] ]
41+
; CHECK-NEXT: [[TMP1:%.*]] = fadd <2 x float> zeroinitializer, [[TMP0]]
42+
; CHECK-NEXT: [[TMP2]] = select <2 x i1> zeroinitializer, <2 x float> [[TMP1]], <2 x float> zeroinitializer
43+
; CHECK-NEXT: br label [[LOOP]]
44+
;
45+
entry:
46+
br label %loop
47+
48+
loop:
49+
%ph0 = phi float [ 0.000000e+00, %entry ], [ %i4, %loop ]
50+
%ph1 = phi float [ 0.000000e+00, %entry ], [ %i5, %loop ]
51+
%i = fadd float 0.000000e+00, %ph0
52+
%i1 = fadd float 0.000000e+00, %ph1
53+
%i2 = select i1 false, float %i, float 0.000000e+00
54+
%i3 = select i1 false, float %i1, float 0.000000e+00
55+
%ins0 = insertelement <2 x float> zeroinitializer, float %i2, i64 0
56+
%ins1 = insertelement <2 x float> %ins0, float %i3, i64 1
57+
%i4 = extractelement <2 x float> %ins1, i64 0
58+
%i5 = extractelement <2 x float> %ins1, i64 1
59+
br label %loop
60+
}

0 commit comments

Comments
 (0)