[llvm] 01e02e0 - [SLP]Fix PR87011: Do not assume that initial ext/trunc nodes can be
Alexey Bataev via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 28 18:05:43 PDT 2024
Author: Alexey Bataev
Date: 2024-03-28T18:02:26-07:00
New Revision: 01e02e0b6a15562e241e9ed18b295c66ae20f410
URL: https://github.com/llvm/llvm-project/commit/01e02e0b6a15562e241e9ed18b295c66ae20f410
DIFF: https://github.com/llvm/llvm-project/commit/01e02e0b6a15562e241e9ed18b295c66ae20f410.diff
LOG: [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.
Added:
Modified:
llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
llvm/test/Transforms/SLPVectorizer/RISCV/init-ext-node-not-truncable.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index a264dee00bae38..2875e71081d928 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -14450,9 +14450,15 @@ void BoUpSLP::computeMinimumValueSizes() {
ReductionBitWidth = 0;
}
- for (unsigned Idx : RootDemotes)
- ToDemote.append(VectorizableTree[Idx]->Scalars.begin(),
- VectorizableTree[Idx]->Scalars.end());
+ for (unsigned Idx : RootDemotes) {
+ Value *V = VectorizableTree[Idx]->Scalars.front();
+ uint32_t OrigBitWidth = DL->getTypeSizeInBits(V->getType());
+ if (OrigBitWidth > MaxBitWidth) {
+ APInt Mask = APInt::getBitsSetFrom(OrigBitWidth, MaxBitWidth);
+ if (MaskedValueIsZero(V, Mask, SimplifyQuery(*DL)))
+ ToDemote.push_back(V);
+ }
+ }
RootDemotes.clear();
IsTopRoot = false;
IsProfitableToDemoteRoot = true;
diff --git a/llvm/test/Transforms/SLPVectorizer/RISCV/init-ext-node-not-truncable.ll b/llvm/test/Transforms/SLPVectorizer/RISCV/init-ext-node-not-truncable.ll
index f6d1baf44a76e2..436fba3261d602 100644
--- a/llvm/test/Transforms/SLPVectorizer/RISCV/init-ext-node-not-truncable.ll
+++ b/llvm/test/Transforms/SLPVectorizer/RISCV/init-ext-node-not-truncable.ll
@@ -1,5 +1,5 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 4
-; RUN: opt -S --passes=slp-vectorizer -mtriple=riscv64-unknown-linux-gnu -mattr="+v" < %s | FileCheck %s
+; RUN: opt -S --passes=slp-vectorizer -mtriple=riscv64-unknown-linux-gnu -mattr="+v" < %s -slp-threshold=-5 | FileCheck %s
@h = global [16 x i64] zeroinitializer
@@ -7,7 +7,7 @@ define void @test() {
; CHECK-LABEL: define void @test(
; CHECK-SAME: ) #[[ATTR0:[0-9]+]] {
; CHECK-NEXT: entry:
-; CHECK-NEXT: store <2 x i64> <i64 1, i64 0>, ptr @h, align 8
+; CHECK-NEXT: store <2 x i64> <i64 -1, i64 0>, ptr @h, align 8
; CHECK-NEXT: ret void
;
entry:
More information about the llvm-commits
mailing list