Skip to content

Commit 3db0f8c

Browse files
committed
[SLP]Update TrackedToOrig mappings after reduction vectorization
Need to update mappings in TrackedToOrig to correctly provide mapping between updated reduced value after vectorization and its original value, otherwise the compiler might miss this update and it may cause compiler crash later, when it tries to find the original instruction mapping for the updated value. Fixes #109376
1 parent 1c47fa9 commit 3db0f8c

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18668,6 +18668,14 @@ class HorizontalReduction {
1866818668
// Vectorize a tree.
1866918669
Value *VectorizedRoot =
1867018670
V.vectorizeTree(LocalExternallyUsedValues, InsertPt);
18671+
// Update TrackedToOrig mapping, since the tracked values might be
18672+
// updated.
18673+
for (Value *RdxVal : Candidates) {
18674+
Value *OrigVal = TrackedToOrig.at(RdxVal);
18675+
Value *TransformedRdxVal = TrackedVals.at(OrigVal);
18676+
if (TransformedRdxVal != RdxVal)
18677+
TrackedToOrig.try_emplace(TransformedRdxVal, OrigVal);
18678+
}
1867118679

1867218680
Builder.SetInsertPoint(InsertPt);
1867318681

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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 < %s | FileCheck %s
3+
4+
define i16 @test() {
5+
; CHECK-LABEL: define i16 @test() {
6+
; CHECK-NEXT: [[ENTRY:.*:]]
7+
; CHECK-NEXT: [[TMP0:%.*]] = call i16 @llvm.vector.reduce.or.v8i16(<8 x i16> zeroinitializer)
8+
; CHECK-NEXT: [[TMP1:%.*]] = call i16 @llvm.vector.reduce.or.v4i16(<4 x i16> zeroinitializer)
9+
; CHECK-NEXT: [[OP_RDX:%.*]] = or i16 [[TMP0]], [[TMP1]]
10+
; CHECK-NEXT: [[OP_RDX1:%.*]] = or i16 [[OP_RDX]], 0
11+
; CHECK-NEXT: ret i16 [[OP_RDX1]]
12+
;
13+
entry:
14+
%subi = add i16 0, 0
15+
%sub40.i = add i16 %subi, 0
16+
%sub41.i = add i16 %subi, 0
17+
%sub42.i = add i16 %subi, 0
18+
%sub43.i = add i16 %subi, 0
19+
%sub44.i = add i16 %subi, 0
20+
%sub45.i = add i16 %subi, 0
21+
%sub46.i = add i16 0, 0
22+
%sub47.i = add i16 0, 0
23+
%sub48.i = add i16 0, 0
24+
%sub49.i = add i16 0, 0
25+
%or40.i = or i16 %sub40.i, %sub41.i
26+
%or41.i = or i16 %or40.i, %sub42.i
27+
%or42.i = or i16 %or41.i, %sub43.i
28+
%or43.i = or i16 %or42.i, %sub44.i
29+
%or44.i = or i16 %or43.i, %sub45.i
30+
%or45.i = or i16 %or44.i, %sub46.i
31+
%or46.i = or i16 %or45.i, %sub47.i
32+
%or47.i = or i16 %or46.i, %sub48.i
33+
%or48.i = or i16 %or47.i, %sub49.i
34+
%or50.i = or i16 %or48.i, %subi
35+
%subii = add i16 0, 0
36+
%subi16.i = add i16 %subii, 0
37+
%subi17.i = add i16 %subii, 0
38+
%0 = or i16 %subi16.i, %subi17.i
39+
%1 = or i16 %0, %or50.i
40+
ret i16 %1
41+
}

0 commit comments

Comments
 (0)