summaryrefslogtreecommitdiffstats
path: root/polly/lib
diff options
context:
space:
mode:
authorTobias Grosser <tobias@grosser.es>2017-07-20 19:55:19 +0000
committerTobias Grosser <tobias@grosser.es>2017-07-20 19:55:19 +0000
commit1eeedf48294ac99cede3430232cad55170de99f8 (patch)
treeba547ed69da84d17f0f739f50fccabc4d09564ec /polly/lib
parentf3a778d75759ebb5c388ae93522a4cfabaebbd13 (diff)
downloadbcm5719-llvm-1eeedf48294ac99cede3430232cad55170de99f8.tar.gz
bcm5719-llvm-1eeedf48294ac99cede3430232cad55170de99f8.zip
[IslNodeBuilder] Relax complexity check in invariant loads and run it early
When performing invariant load hoisting we check that invariant load expressions are not too complex. Up to this commit, we performed this check by counting the sum of dimensions in the access range as a very simple heuristic. This heuristic is a little too conservative, as it prevents hoisting for any scops with a very large number of parameters. Hence, we update the heuristic to only count existentially quantified dimensions and set dimensions. We expect this to still detect the problematic expressions in h264 because of which this check was originally introduced. For some unknown reason, this complexity check was originally committed in IslNodeBuilder. It really belongs in ScopInfo, as there is no point in optimizing a program which we could have known earlier cannot be code generated. The benefit of running the check early is that we can avoid to even hoist checks that are expensive to code generate as invariant loads. This can be seen in the changed tests, where we now indeed detect the scop, but just not invariant load hoist the complicated access. We also improve the formatting of the code, document it, and use isl++ to simplify expressions. llvm-svn: 308659
Diffstat (limited to 'polly/lib')
-rw-r--r--polly/lib/Analysis/ScopInfo.cpp38
-rw-r--r--polly/lib/CodeGen/IslNodeBuilder.cpp23
2 files changed, 38 insertions, 23 deletions
diff --git a/polly/lib/Analysis/ScopInfo.cpp b/polly/lib/Analysis/ScopInfo.cpp
index a1643f8b01a..88206f04252 100644
--- a/polly/lib/Analysis/ScopInfo.cpp
+++ b/polly/lib/Analysis/ScopInfo.cpp
@@ -94,6 +94,12 @@ static int const MaxDisjunctsInDomain = 20;
// number of disjunct when adding non-convex sets to the context.
static int const MaxDisjunctsInContext = 4;
+// The maximal number of dimensions we allow during invariant load construction.
+// More complex access ranges will result in very high compile time and are also
+// unlikely to result in good code. This value is very high and should only
+// trigger for corner cases (e.g., the "dct_luma" function in h264, SPEC2006).
+static int const MaxDimensionsInAccessRange = 9;
+
static cl::opt<int>
OptComputeOut("polly-analysis-computeout",
cl::desc("Bound the scop analysis by a maximal amount of "
@@ -4024,6 +4030,35 @@ void Scop::addInvariantLoads(ScopStmt &Stmt, InvariantAccessesTy &InvMAs) {
isl_set_free(DomainCtx);
}
+/// Check if an access range is too complex.
+///
+/// An access range is too complex, if it contains either many disjuncts or
+/// very complex expressions. As a simple heuristic, we assume if a set to
+/// be too complex if the sum of existentially quantified dimensions and
+/// set dimensions is larger than a threshold. This reliably detects both
+/// sets with many disjuncts as well as sets with many divisions as they
+/// arise in h264.
+///
+/// @param AccessRange The range to check for complexity.
+///
+/// @returns True if the access range is too complex.
+static bool isAccessRangeTooComplex(isl::set AccessRange) {
+ unsigned NumTotalDims = 0;
+
+ auto CountDimensions = [&NumTotalDims](isl::basic_set BSet) -> isl::stat {
+ NumTotalDims += BSet.dim(isl::dim::div);
+ NumTotalDims += BSet.dim(isl::dim::set);
+ return isl::stat::ok;
+ };
+
+ AccessRange.foreach_basic_set(CountDimensions);
+
+ if (NumTotalDims > MaxDimensionsInAccessRange)
+ return true;
+
+ return false;
+}
+
isl::set Scop::getNonHoistableCtx(MemoryAccess *Access, isl::union_map Writes) {
// TODO: Loads that are not loop carried, hence are in a statement with
// zero iterators, are by construction invariant, though we
@@ -4072,6 +4107,9 @@ isl::set Scop::getNonHoistableCtx(MemoryAccess *Access, isl::union_map Writes) {
SafeToLoad = AccessRelation.range();
}
+ if (isAccessRangeTooComplex(AccessRelation.range()))
+ return nullptr;
+
isl::union_map Written = Writes.intersect_range(SafeToLoad);
isl::set WrittenCtx = Written.params();
bool IsWritten = !WrittenCtx.is_empty();
diff --git a/polly/lib/CodeGen/IslNodeBuilder.cpp b/polly/lib/CodeGen/IslNodeBuilder.cpp
index db23319183a..7783818e17b 100644
--- a/polly/lib/CodeGen/IslNodeBuilder.cpp
+++ b/polly/lib/CodeGen/IslNodeBuilder.cpp
@@ -53,12 +53,6 @@ using namespace llvm;
STATISTIC(VersionedScops, "Number of SCoPs that required versioning.");
-// The maximal number of dimensions we allow during invariant load construction.
-// More complex access ranges will result in very high compile time and are also
-// unlikely to result in good code. This value is very high and should only
-// trigger for corner cases (e.g., the "dct_luma" function in h264, SPEC2006).
-static int const MaxDimensionsInAccessRange = 9;
-
static cl::opt<bool> PollyGenerateRTCPrint(
"polly-codegen-emit-rtc-print",
cl::desc("Emit code that prints the runtime check result dynamically."),
@@ -1134,26 +1128,9 @@ bool IslNodeBuilder::materializeFortranArrayOutermostDimension() {
return true;
}
-/// Add the number of dimensions in @p BS to @p U.
-static isl_stat countTotalDims(__isl_take isl_basic_set *BS, void *U) {
- unsigned *NumTotalDim = static_cast<unsigned *>(U);
- *NumTotalDim += isl_basic_set_total_dim(BS);
- isl_basic_set_free(BS);
- return isl_stat_ok;
-}
-
Value *IslNodeBuilder::preloadUnconditionally(isl_set *AccessRange,
isl_ast_build *Build,
Instruction *AccInst) {
-
- // TODO: This check could be performed in the ScopInfo already.
- unsigned NumTotalDim = 0;
- isl_set_foreach_basic_set(AccessRange, countTotalDims, &NumTotalDim);
- if (NumTotalDim > MaxDimensionsInAccessRange) {
- isl_set_free(AccessRange);
- return nullptr;
- }
-
isl_pw_multi_aff *PWAccRel = isl_pw_multi_aff_from_set(AccessRange);
isl_ast_expr *Access =
isl_ast_build_access_from_pw_multi_aff(Build, PWAccRel);
OpenPOWER on IntegriCloud