diff options
author | Haicheng Wu <haicheng@codeaurora.org> | 2018-04-03 00:05:10 +0000 |
---|---|---|
committer | Haicheng Wu <haicheng@codeaurora.org> | 2018-04-03 00:05:10 +0000 |
commit | 7f0daaeb865c4be417bc5810d8d5f2963bb20c44 (patch) | |
tree | de2c3e3663b379658d417a50228e67999671e106 /llvm/lib/Transforms/Vectorize | |
parent | 7d6131a898690f4b4bd6de64ef863125f50973ec (diff) | |
download | bcm5719-llvm-7f0daaeb865c4be417bc5810d8d5f2963bb20c44.tar.gz bcm5719-llvm-7f0daaeb865c4be417bc5810d8d5f2963bb20c44.zip |
[SLP] Distinguish "demanded and shrinkable" from "demanded and not shrinkable" values when determining the minimum bitwidth
We use two approaches for determining the minimum bitwidth.
* Demanded bits
* Value tracking
If demanded bits doesn't result in a narrower type, we then try value tracking.
We need this if we want to root SLP trees with the indices of getelementptr
instructions since all the bits of the indices are demanded.
But there is a missing piece though. We need to be able to distinguish "demanded
and shrinkable" from "demanded and not shrinkable". For example, the bits of %i
in
%i = sext i32 %e1 to i64
%gep = getelementptr inbounds i64, i64* %p, i64 %i
are demanded, but we can shrink %i's type to i32 because it won't change the
result of the getelementptr. On the other hand, in
%tmp15 = sext i32 %tmp14 to i64
%tmp16 = insertvalue { i64, i64 } undef, i64 %tmp15, 0
it doesn't make sense to shrink %tmp15 and we can skip the value tracking.
Ideas are from Matthew Simpson!
Differential Revision: https://reviews.llvm.org/D44868
llvm-svn: 329035
Diffstat (limited to 'llvm/lib/Transforms/Vectorize')
-rw-r--r-- | llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp | 23 |
1 files changed, 6 insertions, 17 deletions
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index 61242030e48..735dfd4c79d 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -4430,24 +4430,9 @@ void BoUpSLP::computeMinimumValueSizes() { // additional roots that require investigating in Roots. SmallVector<Value *, 32> ToDemote; SmallVector<Value *, 4> Roots; - for (auto *Root : TreeRoot) { - // Do not include top zext/sext/trunc operations to those to be demoted, it - // produces noise cast<vect>, trunc <vect>, exctract <vect>, cast <extract> - // sequence. - if (isa<Constant>(Root)) - continue; - auto *I = dyn_cast<Instruction>(Root); - if (!I || !I->hasOneUse() || !Expr.count(I)) - return; - if (isa<ZExtInst>(I) || isa<SExtInst>(I)) - continue; - if (auto *TI = dyn_cast<TruncInst>(I)) { - Roots.push_back(TI->getOperand(0)); - continue; - } + for (auto *Root : TreeRoot) if (!collectValuesToDemote(Root, Expr, ToDemote, Roots)) return; - } // The maximum bit width required to represent all the values that can be // demoted without loss of precision. It would be safe to truncate the roots @@ -4476,7 +4461,11 @@ void BoUpSLP::computeMinimumValueSizes() { // We start by looking at each entry that can be demoted. We compute the // maximum bit width required to store the scalar by using ValueTracking to // compute the number of high-order bits we can truncate. - if (MaxBitWidth == DL->getTypeSizeInBits(TreeRoot[0]->getType())) { + if (MaxBitWidth == DL->getTypeSizeInBits(TreeRoot[0]->getType()) && + llvm::all_of(TreeRoot, [](Value *R) { + assert(R->hasOneUse() && "Root should have only one use!"); + return isa<GetElementPtrInst>(R->user_back()); + })) { MaxBitWidth = 8u; // Determine if the sign bit of all the roots is known to be zero. If not, |