Skip to content

Commit 4dede75

Browse files
committed
[SLP]Transform nodes before building externally used values
transformNodes function may create new vector nodes, so the reduced values might be vectorized later. Need to build the list of the externally used values after the transformNodes() function call to avoid compiler crash. Fixe #110787
1 parent 8805ff7 commit 4dede75

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18848,6 +18848,7 @@ class HorizontalReduction {
1884818848
++SameValuesCounter.try_emplace(OrigV).first->second;
1884918849
}
1885018850
}
18851+
V.transformNodes();
1885118852
SmallPtrSet<Value *, 4> VLScalars(VL.begin(), VL.end());
1885218853
// Gather externally used values.
1885318854
SmallPtrSet<Value *, 4> Visited;
@@ -18877,7 +18878,6 @@ class HorizontalReduction {
1887718878
for (Value *RdxVal : VL)
1887818879
if (RequiredExtract.contains(RdxVal))
1887918880
LocalExternallyUsedValues[RdxVal];
18880-
V.transformNodes();
1888118881
V.buildExternalUses(LocalExternallyUsedValues);
1888218882

1888318883
V.computeMinimumValueSizes();
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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 -slp-threshold=-10 < %s | FileCheck %s
3+
4+
define i32 @test(i1 %cond) {
5+
; CHECK-LABEL: define i32 @test(
6+
; CHECK-SAME: i1 [[COND:%.*]]) {
7+
; CHECK-NEXT: [[ENTRY:.*]]:
8+
; CHECK-NEXT: br label %[[BB:.*]]
9+
; CHECK: [[BB]]:
10+
; CHECK-NEXT: [[P1:%.*]] = phi i32 [ [[OR92:%.*]], %[[BB]] ], [ 0, %[[ENTRY]] ]
11+
; CHECK-NEXT: [[TMP0:%.*]] = phi <2 x i32> [ [[TMP8:%.*]], %[[BB]] ], [ zeroinitializer, %[[ENTRY]] ]
12+
; CHECK-NEXT: [[TMP1:%.*]] = or i32 1, 0
13+
; CHECK-NEXT: [[TMP2:%.*]] = shufflevector <2 x i32> [[TMP0]], <2 x i32> poison, <4 x i32> <i32 0, i32 1, i32 poison, i32 poison>
14+
; CHECK-NEXT: [[TMP3:%.*]] = shufflevector <4 x i32> [[TMP2]], <4 x i32> <i32 poison, i32 poison, i32 0, i32 0>, <4 x i32> <i32 poison, i32 1, i32 6, i32 7>
15+
; CHECK-NEXT: [[TMP4:%.*]] = insertelement <4 x i32> [[TMP3]], i32 [[P1]], i32 0
16+
; CHECK-NEXT: [[TMP5:%.*]] = or <4 x i32> zeroinitializer, [[TMP4]]
17+
; CHECK-NEXT: [[OR92]] = or i32 1, 0
18+
; CHECK-NEXT: [[TMP6:%.*]] = call i32 @llvm.vector.reduce.xor.v4i32(<4 x i32> [[TMP5]])
19+
; CHECK-NEXT: [[OP_RDX:%.*]] = xor i32 [[TMP6]], [[OR92]]
20+
; CHECK-NEXT: [[TMP7:%.*]] = insertelement <2 x i32> poison, i32 [[OP_RDX]], i32 0
21+
; CHECK-NEXT: [[TMP8]] = insertelement <2 x i32> [[TMP7]], i32 [[TMP1]], i32 1
22+
; CHECK-NEXT: br i1 [[COND]], label %[[EXIT:.*]], label %[[BB]]
23+
; CHECK: [[EXIT]]:
24+
; CHECK-NEXT: ret i32 [[OP_RDX]]
25+
;
26+
entry:
27+
br label %bb
28+
29+
bb:
30+
%p1 = phi i32 [ %or92, %bb ], [ 0, %entry ]
31+
%p2 = phi i32 [ %0, %bb ], [ 0, %entry ]
32+
%p3 = phi i32 [ %4, %bb ], [ 0, %entry ]
33+
%0 = or i32 1, 0
34+
%or8.i = or i32 0, 0
35+
%or9.i = or i32 0, 0
36+
%or91 = or i32 %p1, 0
37+
%or12.i = or i32 %p2, 0
38+
%or92 = or i32 1, 0
39+
%1 = xor i32 %or91, %or12.i
40+
%2 = xor i32 %1, %or9.i
41+
%3 = xor i32 %2, %or8.i
42+
%4 = xor i32 %3, %or92
43+
br i1 %cond, label %exit, label %bb
44+
45+
exit:
46+
ret i32 %4
47+
}

0 commit comments

Comments
 (0)