Skip to content

Commit 01e02e0

Browse files
committed
[SLP]Fix PR87011: Do not assume that initial ext/trunc nodes can be
represented by bitwidth without analysis. Need to check that initial ext/trunc nodes can be safely represented using calculated bitwidth before applying it.
1 parent 338be79 commit 01e02e0

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14450,9 +14450,15 @@ void BoUpSLP::computeMinimumValueSizes() {
1445014450
ReductionBitWidth = 0;
1445114451
}
1445214452

14453-
for (unsigned Idx : RootDemotes)
14454-
ToDemote.append(VectorizableTree[Idx]->Scalars.begin(),
14455-
VectorizableTree[Idx]->Scalars.end());
14453+
for (unsigned Idx : RootDemotes) {
14454+
Value *V = VectorizableTree[Idx]->Scalars.front();
14455+
uint32_t OrigBitWidth = DL->getTypeSizeInBits(V->getType());
14456+
if (OrigBitWidth > MaxBitWidth) {
14457+
APInt Mask = APInt::getBitsSetFrom(OrigBitWidth, MaxBitWidth);
14458+
if (MaskedValueIsZero(V, Mask, SimplifyQuery(*DL)))
14459+
ToDemote.push_back(V);
14460+
}
14461+
}
1445614462
RootDemotes.clear();
1445714463
IsTopRoot = false;
1445814464
IsProfitableToDemoteRoot = true;

llvm/test/Transforms/SLPVectorizer/RISCV/init-ext-node-not-truncable.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 4
2-
; RUN: opt -S --passes=slp-vectorizer -mtriple=riscv64-unknown-linux-gnu -mattr="+v" < %s | FileCheck %s
2+
; RUN: opt -S --passes=slp-vectorizer -mtriple=riscv64-unknown-linux-gnu -mattr="+v" < %s -slp-threshold=-5 | FileCheck %s
33

44
@h = global [16 x i64] zeroinitializer
55

66
define void @test() {
77
; CHECK-LABEL: define void @test(
88
; CHECK-SAME: ) #[[ATTR0:[0-9]+]] {
99
; CHECK-NEXT: entry:
10-
; CHECK-NEXT: store <2 x i64> <i64 1, i64 0>, ptr @h, align 8
10+
; CHECK-NEXT: store <2 x i64> <i64 -1, i64 0>, ptr @h, align 8
1111
; CHECK-NEXT: ret void
1212
;
1313
entry:

0 commit comments

Comments
 (0)