[llvm] r253061 - [LIR] Factor out the code to compute base ptr for negative strided loops.
Chad Rosier via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 13 11:11:08 PST 2015
Author: mcrosier
Date: Fri Nov 13 13:11:07 2015
New Revision: 253061
URL: http://llvm.org/viewvc/llvm-project?rev=253061&view=rev
Log:
[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.
Modified:
llvm/trunk/lib/Transforms/Scalar/LoopIdiomRecognize.cpp
Modified: llvm/trunk/lib/Transforms/Scalar/LoopIdiomRecognize.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/LoopIdiomRecognize.cpp?rev=253061&r1=253060&r2=253061&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/LoopIdiomRecognize.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/LoopIdiomRecognize.cpp Fri Nov 13 13:11:07 2015
@@ -494,6 +494,19 @@ static Constant *getMemSetPatternValue(V
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::processLoopStri
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
More information about the llvm-commits
mailing list