diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index a264dee00bae3..2875e71081d92 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 f6d1baf44a76e..436fba3261d60 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> , ptr @h, align 8 +; CHECK-NEXT: store <2 x i64> , ptr @h, align 8 ; CHECK-NEXT: ret void ; entry: