[PATCH] Handling store to invariant address in LAA
Ashutosh Nema
ashutosh.nema at amd.com
Fri Mar 27 00:08:42 PDT 2015
Hi anemet, hfinkel, reames,
This change is for handling of “store to invariant address” in ‘LoopAccessAnalysis’(LAA).
While analyzing loop, LAA sets ‘CanVecMem’ to false when store to invariant address appears.
928 void LoopAccessInfo::analyzeLoop(const ValueToValueMap &Strides) {
1029 if (isUniform(Ptr)) {
1030 emitAnalysis(
1031 LoopAccessReport(ST)
1032 << "write to a loop invariant address could not be vectorized");
1033 DEBUG(dbgs() << "LAA: We don't allow storing to uniform addresses\n");
1034 CanVecMem = false;
1035 return;
1036 }
This check was specific to optimizations.
We like to add a flexibility here, by letting optimizations to decide on “store to invariant address”.
Some optimizations may not be interested in “store to invariant address” and few optimization will be interested.
For the same as Adam suggested, made following change:
1) Added variable ‘StoreToLoopInvariantAddress’ in ‘LoopAccessInfo’ class.
2) Provided a getter function ‘hasStoreToLoopInvariantAddress’ for ‘StoreToLoopInvariantAddress’.
3) Updating this variable in ‘LoopAccessInfo::analyzeLoop’ for store to invariant addresses.
4) In vectorization legality ‘LoopVectorizationLegality::canVectorizeMemory’ checking this variable and returning false in case of store to invariant addresses.
Requesting to review this change.
REPOSITORY
rL LLVM
http://reviews.llvm.org/D8653
Files:
include/llvm/Analysis/LoopAccessAnalysis.h
lib/Analysis/LoopAccessAnalysis.cpp
lib/Transforms/Vectorize/LoopVectorize.cpp
Index: include/llvm/Analysis/LoopAccessAnalysis.h
===================================================================
--- include/llvm/Analysis/LoopAccessAnalysis.h
+++ include/llvm/Analysis/LoopAccessAnalysis.h
@@ -428,6 +428,13 @@
/// Only used in DEBUG build but we don't want NDEBUG-dependent ABI.
unsigned NumSymbolicStrides;
+ /// \brief Checks existence of store to invariant address inside loop.
+ /// If the loop has any store to invariant address, then it return true.
+ /// else returns false.
+ bool hasStoreToLoopInvariantAddress() const {
+ return StoreToLoopInvariantAddress;
+ }
+
private:
/// \brief Analyze the loop. Substitute symbolic strides using Strides.
void analyzeLoop(const ValueToValueMap &Strides);
@@ -465,6 +472,10 @@
/// \brief Cache the result of analyzeLoop.
bool CanVecMem;
+ /// \brief Indicator for storing to uniform addresses.
+ /// If a loop has write to a loop invariant address then it should be true.
+ bool StoreToLoopInvariantAddress;
+
/// \brief The diagnostics report generated for the analysis. E.g. why we
/// couldn't analyze the loop.
Optional<LoopAccessReport> Report;
Index: lib/Analysis/LoopAccessAnalysis.cpp
===================================================================
--- lib/Analysis/LoopAccessAnalysis.cpp
+++ lib/Analysis/LoopAccessAnalysis.cpp
@@ -1033,16 +1033,8 @@
for (I = Stores.begin(), IE = Stores.end(); I != IE; ++I) {
StoreInst *ST = cast<StoreInst>(*I);
Value* Ptr = ST->getPointerOperand();
-
- if (isUniform(Ptr)) {
- emitAnalysis(
- LoopAccessReport(ST)
- << "write to a loop invariant address could not be vectorized");
- DEBUG(dbgs() << "LAA: We don't allow storing to uniform addresses\n");
- CanVecMem = false;
- return;
- }
-
+ // Check for store to loop invariant address.
+ StoreToLoopInvariantAddress = isUniform(Ptr);
// If we did *not* see this pointer before, insert it to the read-write
// list. At this phase it is only a 'write' list.
if (Seen.insert(Ptr).second) {
Index: lib/Transforms/Vectorize/LoopVectorize.cpp
===================================================================
--- lib/Transforms/Vectorize/LoopVectorize.cpp
+++ lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -4007,6 +4007,13 @@
if (!LAI->canVectorizeMemory())
return false;
+ if (LAI->hasStoreToLoopInvariantAddress()) {
+ emitAnalysis(VectorizationReport()
+ << "write to a loop invariant address could not be vectorized");
+ DEBUG(dbgs() << "LV: We don't allow storing to uniform addresses\n");
+ return false;
+ }
+
if (LAI->getNumRuntimePointerChecks() >
VectorizerParams::RuntimeMemoryCheckThreshold) {
emitAnalysis(VectorizationReport()
EMAIL PREFERENCES
http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D8653.22778.patch
Type: text/x-patch
Size: 2783 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150327/893b6c5a/attachment.bin>
More information about the llvm-commits
mailing list