diff options
| author | Chad Rosier <mcrosier@codeaurora.org> | 2015-11-13 19:11:07 +0000 |
|---|---|---|
| committer | Chad Rosier <mcrosier@codeaurora.org> | 2015-11-13 19:11:07 +0000 |
| commit | ed0c7d131605ae2873f4a5cb382e6a746c5b5691 (patch) | |
| tree | 64e1ece596c16336b1099bebaf7810fc8dd08663 /llvm/lib | |
| parent | 8aaae5a911827be4730c2a95fd649af2d929fa19 (diff) | |
| download | bcm5719-llvm-ed0c7d131605ae2873f4a5cb382e6a746c5b5691.tar.gz bcm5719-llvm-ed0c7d131605ae2873f4a5cb382e6a746c5b5691.zip | |
[LIR] Factor out the code to compute base ptr for negative strided loops.
This will allow for the code to be reused in the memcpy optimization.
llvm-svn: 253061
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp b/llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp index e177d4ab697..de0dc3cc0a1 100644 --- a/llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp +++ b/llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp @@ -494,6 +494,19 @@ static Constant *getMemSetPatternValue(Value *V, const DataLayout *DL) { return ConstantArray::get(AT, std::vector<Constant *>(ArraySize, C)); } +// If we have a negative stride, Start refers to the end of the memory location +// we're trying to memset. Therefore, we need to recompute the base pointer, +// which is just Start - BECount*Size. +static const SCEV *getStartForNegStride(const SCEV *Start, const SCEV *BECount, + Type *IntPtr, unsigned StoreSize, + ScalarEvolution *SE) { + const SCEV *Index = SE->getTruncateOrZeroExtend(BECount, IntPtr); + if (StoreSize != 1) + Index = SE->getMulExpr(Index, SE->getConstant(IntPtr, StoreSize), + SCEV::FlagNUW); + return SE->getMinusSCEV(Start, Index); +} + /// processLoopStridedStore - We see a strided store of some value. If we can /// transform this into a memset or memset_pattern in the loop preheader, do so. bool LoopIdiomRecognize::processLoopStridedStore( @@ -539,16 +552,8 @@ bool LoopIdiomRecognize::processLoopStridedStore( Type *IntPtr = Builder.getIntPtrTy(*DL, DestAS); const SCEV *Start = Ev->getStart(); - // If we have a negative stride, Start refers to the end of the memory - // location we're trying to memset. Therefore, we need to recompute the start - // point, which is just Start - BECount*Size. - if (NegStride) { - const SCEV *Index = SE->getTruncateOrZeroExtend(BECount, IntPtr); - if (StoreSize != 1) - Index = SE->getMulExpr(Index, SE->getConstant(IntPtr, StoreSize), - SCEV::FlagNUW); - Start = SE->getMinusSCEV(Ev->getStart(), Index); - } + if (NegStride) + Start = getStartForNegStride(Start, BECount, IntPtr, StoreSize, SE); // Okay, we have a strided store "p[i]" of a splattable value. We can turn // this into a memset in the loop preheader now if we want. However, this |

