summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms
diff options
context:
space:
mode:
authorJingyue Wu <jingyue@google.com>2015-04-06 17:15:48 +0000
committerJingyue Wu <jingyue@google.com>2015-04-06 17:15:48 +0000
commit96d74006fda3b47d19ca1ad5a663d59af9fed21e (patch)
tree9b75d1a51867c5a3b251badd3822db9053a1dc58 /llvm/lib/Transforms
parent07e063e44c2348d23b2d7f249e7da3be56c20760 (diff)
downloadbcm5719-llvm-96d74006fda3b47d19ca1ad5a663d59af9fed21e.tar.gz
bcm5719-llvm-96d74006fda3b47d19ca1ad5a663d59af9fed21e.zip
[SLSR] consider &B[S << i] as &B[(1 << i) * S]
Summary: This reduces handling &B[(1 << i) * s] to handling &B[i * S]. Test Plan: slsr-gep.ll Reviewers: meheff Subscribers: sanjoy, llvm-commits Differential Revision: http://reviews.llvm.org/D8837 llvm-svn: 234180
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r--llvm/lib/Transforms/Scalar/StraightLineStrengthReduce.cpp9
1 files changed, 7 insertions, 2 deletions
diff --git a/llvm/lib/Transforms/Scalar/StraightLineStrengthReduce.cpp b/llvm/lib/Transforms/Scalar/StraightLineStrengthReduce.cpp
index d2eb0e9fcf5..681a70c517d 100644
--- a/llvm/lib/Transforms/Scalar/StraightLineStrengthReduce.cpp
+++ b/llvm/lib/Transforms/Scalar/StraightLineStrengthReduce.cpp
@@ -353,8 +353,6 @@ void StraightLineStrengthReduce::factorArrayIndex(Value *ArrayIdx,
ArrayIdx, ElementSize, GEP);
Value *LHS = nullptr;
ConstantInt *RHS = nullptr;
- // TODO: handle shl. e.g., we could treat (S << 2) as (S * 4).
- //
// One alternative is matching the SCEV of ArrayIdx instead of ArrayIdx
// itself. This would allow us to handle the shl case for free. However,
// matching SCEVs has two issues:
@@ -370,6 +368,13 @@ void StraightLineStrengthReduce::factorArrayIndex(Value *ArrayIdx,
// SLSR is currently unsafe if i * S may overflow.
// GEP = Base + sext(LHS *nsw RHS) * ElementSize
allocateCandidateAndFindBasisForGEP(Base, RHS, LHS, ElementSize, GEP);
+ } else if (match(ArrayIdx, m_NSWShl(m_Value(LHS), m_ConstantInt(RHS)))) {
+ // GEP = Base + sext(LHS <<nsw RHS) * ElementSize
+ // = Base + sext(LHS *nsw (1 << RHS)) * ElementSize
+ APInt One(RHS->getBitWidth(), 1);
+ ConstantInt *PowerOf2 =
+ ConstantInt::get(RHS->getContext(), One << RHS->getValue());
+ allocateCandidateAndFindBasisForGEP(Base, PowerOf2, LHS, ElementSize, GEP);
}
}
OpenPOWER on IntegriCloud