Commit Graph

1054 Commits

Author SHA1 Message Date
Johannes Doerfert 57c5f0b1c4 [FIX] Ensure SAI objects for exit PHIs
If all exiting blocks of a SCoP are error blocks and therefor not
  represented we will not generate accesses and consequently no SAI
  objects for exit PHIs. However, they are needed in the code generation
  to generate the merge PHIs between the original and optimized region.
  With this patch we enusre that the SAI objects for exit PHIs exist
  even if all exiting blocks turn out to be eror blocks.

  This fixes the crash reported in PR27207.

llvm-svn: 265393
2016-04-05 13:44:21 +00:00
Johannes Doerfert 1519491eaf Do not allow to complex branch conditions
Even before we build the domain the branch condition can become very
  complex, especially if we have to build the complement of a lot of
  equality constraints. With this patch we bail if the branch condition
  has a lot of basic sets and parameters.

  After this patch we now successfully compile
    External/SPEC/CINT2000/186_crafty/186_crafty
  with "-polly-process-unprofitable -polly-position=before-vectorizer".

llvm-svn: 265286
2016-04-04 07:59:41 +00:00
Johannes Doerfert 642594ae87 Exploit graph properties during domain generation
As a CFG is often structured we can simplify the steps performed during
  domain generation. When we push domain information we can utilize the
  information from a block A to build the domain of a block B, if A dominates B
  and there is no loop backede on a path from A to B. When we pull domain
  information we can use information from a block A to build the domain of a
  block B if B post-dominates A. This patch implements both ideas and thereby
  simplifies domains that were not simplified by isl. For the FINAL basic block
  in test/ScopInfo/complex-successor-structure-3.ll we used to build a universe
  set with 81 basic sets. Now it actually is represented as universe set.

  While the initial idea to utilize the graph structure depended on the
  dominator and post-dominator tree we can use the available region
  information as a coarse grained replacement. To this end we push the
  region entry domain to the region exit and pull it from the region
  entry for the region exit if applicable.

  With this patch we now successfully compile
    External/SPEC/CINT2006/400_perlbench/400_perlbench
  and
    SingleSource/Benchmarks/Adobe-C++/loop_unroll.

Differential Revision: http://reviews.llvm.org/D18450

llvm-svn: 265285
2016-04-04 07:57:39 +00:00
Johannes Doerfert d5edbd61a1 [FIX] Do not create a SCoP in the presence of infinite loops
If a loop has no exiting blocks the region covering we use during
  schedule genertion might not cover that loop properly. For now we bail
  out as we would not optimize these loops anyway.

llvm-svn: 265280
2016-04-03 23:09:06 +00:00
Tobias Grosser 151ae32dba Revert "[FIX] Do not create a SCoP in the presence of infinite loops"
This reverts commit r265260, as it caused the following 'make check-polly'
failures:

    Polly :: ScopDetect/index_from_unpredictable_loop.ll
    Polly :: ScopInfo/multiple_exiting_blocks.ll
    Polly :: ScopInfo/multiple_exiting_blocks_two_loop.ll
    Polly :: ScopInfo/schedule-const-post-dominator-walk-2.ll
    Polly :: ScopInfo/schedule-const-post-dominator-walk.ll
    Polly :: ScopInfo/switch-5.ll

llvm-svn: 265272
2016-04-03 19:36:52 +00:00
Johannes Doerfert 2075b5d2a1 [FIX] Do not create two SAI objects for exit PHIs
If an exit PHI is written and also read in the SCoP we should not create two
  SAI objects but only one. As the read is only modeled to ensure OpenMP code
  generation knows about it we can simply use the EXIT_PHI MemoryKind for both
  accesses.

llvm-svn: 265261
2016-04-03 11:16:00 +00:00
Johannes Doerfert 7dcceb82e9 [FIX] Do not create a SCoP in the presence of infinite loops
If a loop has no exiting blocks the region covering we use during
  schedule genertion might not cover that loop properly. For now we bail
  out as we would not optimize these loops anyway.

llvm-svn: 265260
2016-04-03 11:12:39 +00:00
Johannes Doerfert 6ba927148d [FIX] Adjust the insert point for non-affine region PHIs
If a non-affine region PHI is generated we should not move the insert
  point prior to the synthezised value in the same block as we might
  split that block at the insert point later on. Only if the incoming
  value should be placed in a different block we should change the
  insertion point.

llvm-svn: 265132
2016-04-01 11:25:47 +00:00
Tobias Grosser 6deba4ea03 Revert 264782 and 264789
These caused LNT failures due to new assertions when running with
-polly-position=before-vectorizer -polly-process-unprofitable for:

FAIL: clamscan.compile_time
FAIL: cjpeg.compile_time
FAIL: consumer-jpeg.compile_time
FAIL: shapes.compile_time
FAIL: clamscan.execution_time
FAIL: cjpeg.execution_time
FAIL: consumer-jpeg.execution_time
FAIL: shapes.execution_time

The failures have been introduced by r264782, but r264789 had to be reverted
as it depended on the earlier patch.

llvm-svn: 264885
2016-03-30 18:18:31 +00:00
Johannes Doerfert a144fb148b Exploit graph properties during domain generation
As a CFG is often structured we can simplify the steps performed
  during domain generation. When we push domain information we can
  utilize the information from a block A to build the domain of a
  block B, if A dominates B. When we pull domain information we can
  use information from a block A to build the domain of a block B
  if B post-dominates A. This patch implements both ideas and thereby
  simplifies domains that were not simplified by isl. For the FINAL
  basic block in
    test/ScopInfo/complex-successor-structure-3.ll .
  we used to build a universe set with 81 basic sets. Now it actually is
  represented as universe set.

  While the initial idea to utilize the graph structure depended on the
  dominator and post-dominator tree we can use the available region
  information as a coarse grained replacement. To this end we push the
  region entry domain to the region exit and pull it from the region
  entry for the region exit.

Differential Revision: http://reviews.llvm.org/D18450

llvm-svn: 264789
2016-03-29 21:31:05 +00:00
Michael Kruse 88a2256a34 Revert "[ScopInfo] Fix domains after loops."
This reverts commit r264118. The approach is still under discussion.

llvm-svn: 264705
2016-03-29 07:50:52 +00:00
Hongbin Zheng 52ae58259d Add fine-grain dependences analysis to release notes.
Differential Revision: http://reviews.llvm.org/D17905

llvm-svn: 264575
2016-03-28 12:41:49 +00:00
Johannes Doerfert 6462d8c1d9 Generalize the domain complexity restrictions
This patch applies the restrictions on the number of domain conjuncts
  also to the domain parts of piecewise affine expressions we generate.
  To this end the wording is change slightly. It was needed to support
  complex additions featuring zext-instructions but it also fixes PR27045.

  lnt profitable runs reports only little changes that might be noise:
  Compile Time:
    Polybench/[...]/2mm                     +4.34%
    SingleSource/[...]/stepanov_container   -2.43%
  Execution Time:
    External/[...]/186_crafty               -2.32%
    External/[...]/188_ammp                 -1.89%
    External/[...]/473_astar                -1.87%

llvm-svn: 264514
2016-03-26 16:17:00 +00:00
Tobias Grosser 37034db826 Update to isl-0.16.1-145-g243bf7c
Just an import to keep track with the latest version of isl. We are not looking
for specific features.

llvm-svn: 264452
2016-03-25 19:38:18 +00:00
Johannes Doerfert 733ea34f38 [FIX] Handle accesses to "null" in MemIntrinsics
This fixes PR27035. While we now exclude MemIntrinsics from the
  polyhedral model if they would access "null" we could exploit this
  even more, e.g., remove all parameter combinations that would lead to
  the execution of this statement from the context.

llvm-svn: 264284
2016-03-24 13:50:04 +00:00
Johannes Doerfert 549768c01a [FIX] Verify the alias group before returning it
Similar to r262612 we need to check not only the pointer SCEV and the
type of an alias group but also the actual access instruction. The
reason is again the same: The pointer SCEV is not flow sensitive but the
access function is. In r262612 we avoided consolidating alias groups
even though the pointer SCEV and the type were the same but the access
function was not. Here it is simpler as we can simply check all members
of an alias group against the given access instruction.

llvm-svn: 264274
2016-03-24 13:22:16 +00:00
Tobias Grosser 25e8ebe29d Drop explicit -polly-delinearize parameter
Delinearization is now enabled by default and does not need to explicitly need
to be enabled in our tests.

llvm-svn: 264154
2016-03-23 13:21:02 +00:00
Tobias Grosser bfb6a9683b Codegen:Do not invalidate dominator tree when bailing out during code generation
When codegenerating invariant loads in some rare cases we cannot generate code
and bail out. This change ensures that we maintain a valid dominator tree
in these situations. This fixes llvm.org/PR26736

Contributed-by: Matthias Reisinger <d412vv1n@gmail.com>
llvm-svn: 264142
2016-03-23 06:57:51 +00:00
Tobias Grosser 898a636210 Add option to disallow modref function calls in scops.
This might be useful to evaluate the benefit of us handling modref funciton
calls. Also, a new bug that was triggered by modref function calls was
recently reported http://llvm.org/PR27035. To ensure the same issue does not
cause troubles for other people, we temporarily disable this until the bug
is resolved.

llvm-svn: 264140
2016-03-23 06:40:15 +00:00
Michael Kruse 49a59ca093 [ScopInfo] Fix domains after loops.
ISL can conclude additional conditions on parameters from restrictions
on loop variables. Such conditions persist when leaving the loop and the
loop variable is projected out. This results in a narrower domain for
exiting the loop than entering it and is logically impossible for
non-infinite loops.

We fix this by not adding a lower bound i>=0 when constructing BB
domains, but defer it to when also the upper bound it computed, which
was done redundantly even before this patch.

This reduces the number of LNT fails with -polly-process-unprofitable
-polly-position=before-vectorizer from 8 to 6.

llvm-svn: 264118
2016-03-22 23:27:42 +00:00
Tobias Grosser 5a8c052baf Invalidate scop on encountering a complex control flow
We bail out if current scop has a complex control flow as this could lead to
building of large domain conditions. This is to reduce compile time.  This
addresses r26382.

Contributed-by: Chris Jenneisch <chrisj@codeaurora.org>

Differential Revision: http://reviews.llvm.org/D18362

llvm-svn: 264105
2016-03-22 22:05:32 +00:00
Tobias Grosser 0904c69110 ScopInfo: Do not generate dependences for i1 values used in affine branches
Affine branches are fully modeled and regenerated from the polyhedral domain and
consequently do not require any input conditions to be propagated.

llvm-svn: 263678
2016-03-16 23:33:54 +00:00
Michael Kruse afd2db5351 [SCEVValidator] Fix loop exit values considered affine.
Index calculations can use the last value that come out of a loop.
Ideally, ScalarEvolution can compute that exit value directly without
depending on the loop induction variable, but not in all cases.

This changes isAffine to not consider such loop exit values as affine to
avoid that SCEVExpander adds uses of the original loop induction
variable.

This fix is analogous to r262404 that applies to general uses of loop
exit values instead of index expressions and loop bouds as in this
patch.

This reduces the number of LNT test-suite fails with
-polly-position=before-vectorizer -polly-unprofitable
from 10 to 8.

llvm-svn: 262665
2016-03-03 22:10:52 +00:00
Tobias Grosser 2880f10aa4 tests: Fix some spelling mistakes
llvm-svn: 262649
2016-03-03 19:51:03 +00:00
Michael Kruse faedfcbf6d [BlockGenerator] Fix PHI merges for MK_Arrays.
Value merging is only necessary for scalars when they are used outside
of the scop. While an array's base pointer can be used after the scop,
it gets an extra ScopArrayInfo of type MK_Value. We used to generate
phi's for both of them, where one was assuming the reault of the other
phi would be the original value, because it has already been replaced by
the previous phi. This resulted in IR that the current IR verifier
allows, but is probably illegal.

This reduces the number of LNT test-suite fails with
-polly-position=before-vectorizer -polly-process-unprofitable
from 16 to 10.

Also see llvm.org/PR26718.

llvm-svn: 262629
2016-03-03 17:20:43 +00:00
Johannes Doerfert df88023d2b [FIX] Consolidation of loads with same pointer but different access relation
This should fix PR19422.

  Thanks to Jeremy Huddleston Sequoia for reporting this.
  Thanks to Roman Gareev for his investigation and the reduced test case.

llvm-svn: 262612
2016-03-03 12:26:58 +00:00
Michael Kruse c7e0d9c216 Fix non-synthesizable loop exit values.
Polly recognizes affine loops that ScalarEvolution does not, in
particular those with loop conditions that depend on hoisted invariant
loads. Check for SCEVAddRec dependencies on such loops and do not
consider their exit values as synthesizable because SCEVExpander would
generate them as expressions that depend on the original induction
variables. These are not available in generated code.

llvm-svn: 262404
2016-03-01 21:44:06 +00:00
Johannes Doerfert 066dbf3f8e Track assumptions and restrictions separatly
In order to speed up compile time and to avoid random timeouts we now
  separately track assumptions and restrictions. In this context
  assumptions describe parameter valuations we need and restrictions
  describe parameter valuations we do not allow. During AST generation
  we create a runtime check for both, whereas the one for the
  restrictions is negated before a conjunction is build.

  Except the In-Bounds assumptions we currently only track restrictions.

Differential Revision: http://reviews.llvm.org/D17247

llvm-svn: 262328
2016-03-01 13:06:28 +00:00
Johannes Doerfert abadd71da1 [FIX] Prevent compile time problems due to complex invariant loads
This cures the symptoms we see in h264 of SPEC2006 but not the cause.

llvm-svn: 262327
2016-03-01 13:05:14 +00:00
Michael Kruse c0a19b079d Reapply "Add update_test.py script."
Originally committed in r261899 and reverted in r262202 due to failing
in out-of-LLVM tree builds.

Replace the use of LLVM_TOOLS_BINARY_DIR by LLVM_TOOLS_DIR which exists
in both, in-tree and out-of-tree builds.

Original commit message:
The script updates a lit test case that uses FileCheck using the actual
output of the 'RUN:'-lines program. Useful when updating test cases due
to expected output changes and diff'ing expected and actual output.

llvm-svn: 262227
2016-02-29 14:58:13 +00:00
Tobias Grosser a4835c5673 Revert "Add update_test.py script."
This reverts commit r261899. Even though I am not yet 100% certain, this is
commit is the only one that has some relation to the recent cmake failures
in Polly.

llvm-svn: 262202
2016-02-29 07:12:10 +00:00
Hongbin Zheng b1908ea5b9 Update the fine-grain dependences analysis test case.
llvm-svn: 262101
2016-02-27 01:50:01 +00:00
Hongbin Zheng 9691d71674 Introduce fine-grain dependence analysis by tagging access functions and schedules tree with either the id of memory access or memory references.
Differential Revision: http://reviews.llvm.org/D17381

llvm-svn: 262039
2016-02-26 17:05:24 +00:00
Michael Kruse 9cfc49d5b5 Add update_test.py script.
The script updates a lit test case that uses FileCheck using the actual
output of the 'RUN:'-lines program. Useful when updating test cases due
expected output changes and diff'ing expected and actual output.

llvm-svn: 261899
2016-02-25 17:12:12 +00:00
Johannes Doerfert a792098047 Support calls with known ModRef function behaviour
Check the ModRefBehaviour of functions in order to decide whether or
  not a call instruction might be acceptable.

Differential Revision: http://reviews.llvm.org/D5227

llvm-svn: 261866
2016-02-25 14:08:48 +00:00
Michael Kruse f33c125dd2 Fix DomTree preservation for generated subregions.
The generated dedicated subregion exit block was assumed to have the same
dominance relation as the original exit block. This is incorrect if the exit
block receives other edges than only from the subregion, which results in that
e.g. the subregion's entry block does not dominate the exit block.

llvm-svn: 261865
2016-02-25 14:08:48 +00:00
Johannes Doerfert 9dd42ee7c1 Try to build alias checks even when non-affine accesses are allowed
From now on we bail only if a non-trivial alias group contains a non-affine
  access, not when we discover aliasing and non-affine accesses are allowed.

llvm-svn: 261863
2016-02-25 14:06:11 +00:00
Michael Kruse f8266fad8d Tidy test case. NFC.
The test style guide defines that opt should get its input from stdin.
(instead by file argument to avoid that the file name appears in its
output)

CHECK-FORCED is not recognized by FileCheck; remove it.

llvm-svn: 261786
2016-02-24 22:08:02 +00:00
Roman Gareev 11001e1534 Annotation of SIMD loops
Use 'mark' nodes annotate a SIMD loop during ScheduleTransformation and skip
parallelism checks.

The buildbot shows the following compile/execution time changes:

  Compile time:
    Improvements    Δ     Previous  Current  σ
    …/gesummv      -6.06% 0.2640    0.2480   0.0055
    …/gemver       -4.46% 0.4480    0.4280   0.0044
    …/covariance   -4.31% 0.8360    0.8000   0.0065
    …/adi          -3.23% 0.9920    0.9600   0.0065
    …/doitgen      -2.53% 0.9480    0.9240   0.0090
    …/3mm          -2.33% 1.0320    1.0080   0.0087

  Execution time:
    Regressions     Δ     Previous  Current  σ
    …/viterbi       1.70% 5.1840    5.2720   0.0074
    …/smallpt       1.06% 12.4920   12.6240  0.0040

Reviewed-by: Tobias Grosser <tobias@grosser.es>

Differential Revision: http://reviews.llvm.org/D14491

llvm-svn: 261620
2016-02-23 09:00:13 +00:00
Johannes Doerfert 85c06c80d1 Add test case for [FIX] commit r261474
llvm-svn: 261501
2016-02-21 21:53:39 +00:00
Johannes Doerfert cea6193b79 Support memory intrinsics
This patch adds support for memcpy, memset and memmove intrinsics. They are
  represented as one (memset) or two (memcpy, memmove) memory accesses in the
  polyhedral model. These accesses have an access range that describes the
  summarized effect of the intrinsic, i.e.,
    memset(&A[i], '$', N);
  is represented as a write access from A[i] to A[i+N].

Differential Revision: http://reviews.llvm.org/D5226

llvm-svn: 261489
2016-02-21 19:13:19 +00:00
Johannes Doerfert 91bb5bc862 Use regular expressions instead of temporary names for IR test [NFC]
llvm-svn: 261488
2016-02-21 18:59:35 +00:00
Johannes Doerfert 4d9bb8d594 Allow all combinations of types and subscripts for memory accesses
To support non-aligned accesses we introduce a virtual element size
  for arrays that divides each access function used for this array. The
  adjustment of the access function based on the element size of the
  array was therefore moved after this virtual element size was
  determined, thus after all accesses have been created.

Differential Revision: http://reviews.llvm.org/D17246

llvm-svn: 261226
2016-02-18 16:50:12 +00:00
Johannes Doerfert 13637678b1 [FIX] LICM test case
llvm-svn: 260955
2016-02-16 12:10:42 +00:00
Johannes Doerfert 4cf1580f0c [FIX] Check the next base pointer for possible invariant loads
A load can only be invariant if its base pointer is invariant too. To
  this end, we check if the base pointer is defined inside the region or
  outside. In the former case we recursively check if we can (and
  therefore will) hoist the base pointer too. Only if that happends we
  can hoist the load.

llvm-svn: 260886
2016-02-15 12:42:05 +00:00
Johannes Doerfert f69162486b Revert "[FIX] Hoist accesses if AA stated they are invariant"
This reverts commit 98efa006c96ac981c00d2e386ec1102bce9f549a.

  The fix was broken since we do not use AA in the ScopDetection anymore to
  check for invariant accesses.

llvm-svn: 260884
2016-02-15 12:21:11 +00:00
Johannes Doerfert 2353e39e1f [FIX] Hoist accesses if AA stated they are invariant
Before this patch it could happen that we did not hoist a load that
  was a base pointer of another load even though AA already declared the
  first one as invariant (during ScopDetection). If this case arises we
  will now skipt the "can be overwriten" check because in this case the
  over-approximating nature causes us to generate broken code.

llvm-svn: 260862
2016-02-14 23:37:14 +00:00
Johannes Doerfert 965edde695 Separate more constant factors of parameters
So far we separated constant factors from multiplications, however,
  only when they are at the outermost level of a parameter SCEV. Now,
  we also separate constant factors from the parameter SCEV if the
  outermost expression is a SCEVAddRecExpr. With the changes to the
  SCEVAffinator we can now improve the extractConstantFactor(...)
  function at will without worrying about any other code part. Thus,
  if needed we can implement a more comprehensive
  extractConstantFactor(...) function that will traverse the SCEV
  instead of looking only at the outermost level.

  Four test cases were affected. One did not change much and the other
  three were simplified.

llvm-svn: 260859
2016-02-14 22:30:56 +00:00
Johannes Doerfert 96e5471139 Separate invariant equivalence classes by type
We now distinguish invariant loads to the same memory location if they
  have different types. This will cause us to pre-load an invariant
  location once for each type that is used to access it. However, we can
  thereby avoid invalid casting, especially if an array is accessed
  though different typed/sized invariant loads.

  This basically reverts the changes in r260023 but keeps the test
  cases.

llvm-svn: 260045
2016-02-07 17:30:13 +00:00
Johannes Doerfert e708790c59 [FIX] Two "off-by-one" error in constant range usage
llvm-svn: 260031
2016-02-07 13:59:03 +00:00
Tobias Grosser 8ebdc2dd53 Make memory accesses with different element types optional
We also disable this feature by default, as there are still some issues in
combination with invariant load hoisting that slipped through my initial
testing.

llvm-svn: 260025
2016-02-07 08:48:57 +00:00
Tobias Grosser 46bafbd0fe Do not yet consider loads with non-canonical element size for load hoisting.
Invariant load hoisting of memory accesses with non-canonical element
types lacks support for equivalence classes that contain elements of
different width/size. This support should be added, but to get our buildbots
back to green, we disable load hoisting for memory accesses with non-canonical
element size for now.

llvm-svn: 260023
2016-02-07 08:11:36 +00:00
Tobias Grosser 107cd5f5f6 IslNodeBuilder: Invariant load hoisting of elements with differing sizes
Always use access-instruction pointer type to load the invariant values.
Otherwise mismatches between ScopArrayInfo element type and memory access
element type will result in invalid casts. These type mismatches are after
r259784 a lot more common and also arise with types of different size, which
have not been handled before.

Interestingly, this change actually simplifies the code, as we now have only
one code path that is always taken, rather then a standard code path for the
common case and a "fixup" code path that replaces the standard code path in
case of mismatching types.

llvm-svn: 260009
2016-02-06 21:23:39 +00:00
Michael Kruse 2e02d560aa Follow uses to create value MemoryAccesses
The previously implemented approach is to follow value definitions and
create write accesses ("push defs") while searching for uses. This
requires the same relatively validity- and requirement conditions to be
replicated at multiple locations (PHI instructions, other instructions,
uses by PHIs).

We replace this by iterating over the uses in a SCoP ("pull in
requirements"), and add writes only when at least one read has been
added. It turns out to be simpler code because each use is only iterated
over once and writes are added for the first access that reads it. We
need another iteration to identify escaping values (uses not in the
SCoP), which also makes the difference between such accesses more
obvious. As a side-effect, the order of scalar MemoryAccess can change.

Differential Revision: http://reviews.llvm.org/D15706

llvm-svn: 259987
2016-02-06 09:19:40 +00:00
Tobias Grosser d840fc7277 Support accesses with differently sized types to the same array
This allows code such as:

void multiple_types(char *Short, char *Float, char *Double) {
  for (long i = 0; i < 100; i++) {
    Short[i] = *(short *)&Short[2 * i];
    Float[i] = *(float *)&Float[4 * i];
    Double[i] = *(double *)&Double[8 * i];
  }
}

To model such code we use as canonical element type of the modeled array the
smallest element type of all original array accesses, if type allocation sizes
are multiples of each other. Otherwise, we use a newly created iN type, where N
is the gcd of the allocation size of the types used in the accesses to this
array. Accesses with types larger as the canonical element type are modeled as
multiple accesses with the smaller type.

For example the second load access is modeled as:

  { Stmt_bb2[i0] -> MemRef_Float[o0] : 4i0 <= o0 <= 3 + 4i0 }

To support code-generating these memory accesses, we introduce a new method
getAccessAddressFunction that assigns each statement instance a single memory
location, the address we load from/store to. Currently we obtain this address by
taking the lexmin of the access function. We may consider keeping track of the
memory location more explicitly in the future.

We currently do _not_ handle multi-dimensional arrays and also keep the
restriction of not supporting accesses where the offset expression is not a
multiple of the access element type size. This patch adds tests that ensure
we correctly invalidate a scop in case these accesses are found. Both types of
accesses can be handled using the very same model, but are left to be added in
the future.

We also move the initialization of the scop-context into the constructor to
ensure it is already available when invalidating the scop.

Finally, we add this as a new item to the 2.9 release notes

Reviewers: jdoerfert, Meinersbur

Differential Revision: http://reviews.llvm.org/D16878

llvm-svn: 259784
2016-02-04 13:18:42 +00:00
Wei Mi eb14ac5396 Polly tests update contributed by Tobias Grosser for SCEV patch in r259736.
llvm-svn: 259737
2016-02-04 01:34:28 +00:00
Tobias Grosser ba043143a9 test: make test case more robust against removal of unrelated instructions
llvm-svn: 259693
2016-02-03 21:10:11 +00:00
Tobias Grosser e2c31210b2 Revert "Support loads with differently sized types from a single array"
This reverts commit (@259587). It needs some further discussions.

llvm-svn: 259629
2016-02-03 05:53:27 +00:00
Tobias Grosser 5d3fc1ea43 Support loads with differently sized types from a single array
We support now code such as:

void multiple_types(char *Short, char *Float, char *Double) {
  for (long i = 0; i < 100; i++) {
    Short[i] = *(short *)&Short[2 * i];
    Float[i] = *(float *)&Float[4 * i];
    Double[i] = *(double *)&Double[8 * i];
  }
}

To support such code we use as element type of the modeled array the smallest
element type of all original array accesses. Accesses with larger types are
modeled as multiple accesses with the smaller type.

For example the second load access is modeled as:

  { Stmt_bb2[i0] -> MemRef_Float[o0] : 4i0 <= o0 <= 3 + 4i0 }

To support jscop-rewritable memory accesses we need each statement instance to
only be assigned a single memory location, which will be the address at which
we load the value. Currently we obtain this address by taking the lexmin of
the access function. We may consider keeping track of the memory location more
explicitly in the future.

llvm-svn: 259587
2016-02-02 22:05:29 +00:00
Tobias Grosser c2fd8b411d ScopInfo: Correct schedule construction
For schedule generation we assumed that the reverse post order traversal used by
the domain generation is sufficient, however it is not. Once a loop is
discovered, we have to completely traverse it, before we can generate the
schedule for any block/region that is only reachable through a loop exiting
block.

To this end, we add a "loop stack" that will keep track of loops we
discovered during the traversal but have not yet traversed completely.
We will never visit a basic block (or region) outside the most recent
(thus smallest) loop in the loop stack but instead queue such blocks
(or regions) in a waiting list. If the waiting list is not empty and
(might) contain blocks from the most recent loop in the loop stack the
next block/region to visit is drawn from there, otherwise from the
reverse post order iterator.

We exploit the new property of loops being always completed before additional
loops are processed, by removing the LoopSchedules map and instead keep all
information in LoopStack. This clarifies that we indeed always only keep a
stack of in-process loops, but will never keep incomplete schedules for an
arbitrary set of loops. As a result, we can simplify some of the existing code.

This patch also adds some more documentation about how our schedule construction
works.

This fixes http://llvm.org/PR25879

This patch is an modified version of Johannes Doerfert's initial fix.

Differential Revision: http://reviews.llvm.org/D15679

llvm-svn: 259354
2016-02-01 11:54:13 +00:00
Michael Kruse 26311f00e8 Remove autotools build system
The autotools build system is based on and requires LLVM's autotools
build system to work, which has been depricated and finally removed in
r258861. Consequently we also remove the autotools build system from
Polly.

Differential Revision: http://reviews.llvm.org/D16655

llvm-svn: 259041
2016-01-28 12:00:33 +00:00
Michael Kruse fd46308de4 ScopInfo: Never add read accesses for synthesizable values
Before adding a MK_Value READ MemoryAccess, check whether the read is
necessary or synthesizable. Synthesizable values are later generated by
the SCEVExpander and therefore do not need to be transferred
explicitly. This can happen because the check for synthesizability has
presumbly been forgotten in the case where a phi's incoming value has
been defined in a different statement.

Differential Revision: http://reviews.llvm.org/D15687

llvm-svn: 258998
2016-01-27 22:51:56 +00:00
Michael Kruse ee6a4fc680 Unique phi write accesses
Ensure that there is at most one phi write access per PHINode and
ScopStmt. In particular, this would be possible for non-affine
subregions with multiple exiting blocks. We replace multiple MAY_WRITE
accesses by one MUST_WRITE access. The written value is constructed
using a PHINode of all exiting blocks. The interpretation of the PHI
WRITE's "accessed value" changed from the incoming value to the PHI like
for PHI READs since there is no unique incoming value.

Because region simplification shuffles around PHI nodes -- particularly
with exit node PHIs -- the PHINodes at analysis time does not always
exist anymore in the code generation pass. We instead remember the
incoming block/value pair in the MemoryAccess.

Differential Revision: http://reviews.llvm.org/D15681

llvm-svn: 258809
2016-01-26 13:33:27 +00:00
Michael Kruse 436db620e7 Unique value write accesses
Ensure there is at most one write access per definition of an
llvm::Value. Keep track of already created value write access by using
a (dense) map.

Replace addValueWriteAccess by ensureValueStore which can be uses more
liberally without worrying to add redundant accesses. It will be used,
e.g. in a logical correspondant for value reads -- ensureValueReload --
to ensure that the expected definition has been written when loading it.

Differential Revision: http://reviews.llvm.org/D15483

llvm-svn: 258807
2016-01-26 13:33:10 +00:00
Johannes Doerfert 6f50c29ab2 [FIX] Domain generation error due to loops in non-affine regions
llvm-svn: 258803
2016-01-26 11:03:25 +00:00
Johannes Doerfert 432658d7b8 [FIX] Build correct domain for non-affine region SCoPs
llvm-svn: 258802
2016-01-26 11:01:41 +00:00
Tobias Grosser f2cdd144e5 BlockGenerators: Replace getNewScalarValue with getNewValue
Both functions implement the same functionality, with the difference that
getNewScalarValue assumes that globals and out-of-scop scalars can be directly
reused without loading them from their corresponding stack slot. This is correct
for sequential code generation, but causes issues with outlining code e.g. for
OpenMP code generation. getNewValue handles such cases correctly.

Hence, we can replace getNewScalarValue with getNewValue. This is not only more
future proof, but also eliminates a bunch of code.

The only functionality that was available in getNewScalarValue that is lost
is the on-demand creation of scalar values. However, this is not necessary any
more as scalars are always loaded at the beginning of each basic block and will
consequently always be available when scalar stores are generated. As this was
not the case in older versions of Polly, it seems the on-demand loading is just
some older code that has not yet been removed.

Finally, generateScalarLoads also generated loads for values that are loop
invariant, available in GlobalMap and which are preferred over the ones loaded
in generateScalarLoads. Hence, we can just skip the code generation of such
scalar values, avoiding the generation of dead code.

Differential Revision: http://reviews.llvm.org/D16522

llvm-svn: 258799
2016-01-26 10:01:35 +00:00
Tobias Grosser 232905089e test: Name instructions in a test case [NFC]
llvm-svn: 258662
2016-01-24 17:51:37 +00:00
Tobias Grosser 1c3a6d7808 ScopDetection: Do not detect regions with irreducible control as scops
Polly currently does not support irreducible control and it is probably not
worth supporting. This patch adds code that checks for irreducible control
and refuses regions containing irreducible control.

Polly traditionally had rather restrictive checks on the control flow structure
which would have refused irregular control, but within the last couple of months
most of the control flow restrictions have been removed. As part of this
generalization we accidentally allowed irregular control flow.

Contributed-by: Karthik Senthil and Ajith Pandel
llvm-svn: 258497
2016-01-22 09:44:37 +00:00
Tobias Grosser b3a9538e95 Remove irreducible control flow from test case
The test case we look at does not necessarily require irreducible control flow,
but a normal loop is sufficient to create a non-affine region containing more
than one basic block that dominates the exit node. We replace this irreducible
control flow with a normal loop for the following reasons:

  1) This is easier to understand
  2) We will subsequently commit a patch that ensures Polly does not process
     irreducible control flow.

Within non-affine regions, we could possibly handle irreducible control flow.

llvm-svn: 258496
2016-01-22 09:33:33 +00:00
Johannes Doerfert 370cf00c9f Make sure we preserve alignment information after hoisting invariant load
In Polly, after hoisting loop invariant loads outside loop, the alignment
information for hoisted loads are missing, this patch restore them.

Contributed-by: Lawrence Hu <lawrence@codeaurora.org>

Differential Revision: http://reviews.llvm.org/D16160

llvm-svn: 258105
2016-01-19 00:17:21 +00:00
Michael Kruse 959a8dc39f Update to ISL 0.16.1
llvm-svn: 257898
2016-01-15 15:54:45 +00:00
Michael Kruse 5a9a65e43f Prepare unit tests for update to ISL 0.16
ISL 0.16 will change how sets are printed which breaks 117 unit tests
that text-compare printed sets. This patch re-formats most of these unit
tests using a script and small manual editing on top of that. When
actually updating ISL, most work is done by just re-running the script
to adapt to the changed output.

Some tests that compare IR and tests with single CHECK-lines that can be
easily updated manually are not included here.

The re-format script will also be committed afterwards. The per-test
formatter invocation command lines options will not be added in the near
future because it is ad hoc and would overwrite the manual edits.
Ideally it also shouldn't be required anymore because ISL's set printing
has become more stable in 0.16.

Differential Revision: http://reviews.llvm.org/D16095

llvm-svn: 257851
2016-01-15 00:48:42 +00:00
Roman Gareev 10595a1739 Call assumeNoOutOfBound only in updateDimensionality
Call assumeNoOutOfBound only in updateDimensionality to process situations
when new dimensions are added and new bounds checks are required.

Contributed-by: Tobias Grosser, Gareev Roman
llvm-svn: 257170
2016-01-08 14:01:59 +00:00
Tobias Grosser c1a269bf0e Add option to assume single-loop scops with sufficient compute are profitable
If a loop has a sufficiently large amount of compute instruction in its loop
body, it is unlikely that our rewrite of the loop iterators introduces large
performance changes. As Polly can also apply beneficical optimizations (such
as parallelization) to such loop nests, we mark them as profitable.

This option is currently "disabled" by default, but can be used to run
experiments. If enabled by setting it e.g. to 40 instructions, we currently
see some compile-time increases on LNT without any significant run-time
changes.

llvm-svn: 256199
2015-12-21 21:00:43 +00:00
Johannes Doerfert 30e2307f61 [FIX] Schedule generation for block exiting multiple loops.
This fixes bug PR25604.

llvm-svn: 256125
2015-12-20 17:12:22 +00:00
Tobias Grosser 75dc40c3be ScopInfo: Bail out in case of complex branch structures
Scops that contain many complex branches are likely to result in complex domain
conditions that consist of a large (> 100) number of conjucts.  Transforming
such domains is expensive and unlikely to result in efficient code.  To avoid
long compile times we detect this case and skip such scops. In the future we may
improve this by either using non-affine subregions to hide such complex
condition structures or by exploiting in certain cases properties (e.g.,
dominance) that allow us to construct the domains of a scop in a way that
results in a smaller number improving conjuncts.

Example of a code that results in complex iteration spaces:

      loop.header
     /    |    \ \
   A0    A2    A4 \
     \  /  \  /    \
      A1    A3      \
     /  \  /  \     |
   B0    B2    B4   |
     \  /  \  /     |
      B1    B3      ^
     /  \  /  \     |
   C0    C2    C4   |
     \  /  \  /    /
      C1    C3    /
       \   /     /
    loop backedge

llvm-svn: 256123
2015-12-20 13:31:48 +00:00
Roman Gareev 22803d4488 Fix of a comment.
llvm-svn: 255923
2015-12-17 20:47:10 +00:00
Roman Gareev 8aa437503c Fix delinearization of fortran arrays
The patch fixes Bug 25759 produced by inappropriate handling of unsigned
maximum SCEV expressions by SCEVRemoveMax. Without a fix, we get an infinite
loop and a segmentation fault, if we try to process, for example,
'((-1 + (-1 * %b1)) umax {(-1 + (-1 * %yStart)),+,-1}<%.preheader>)'.
It also fixes a potential issue related to signed maximum SCEV expressions.

Tested-by: Roman Gareev <gareevroman@gmail.com>
Fixed-by: Tobias Grosser <tobias@grosser.es>

Differential Revision: http://reviews.llvm.org/D15563

llvm-svn: 255922
2015-12-17 20:37:17 +00:00
Tobias Grosser a69d4f0d83 VectorBlockGenerator: Generate scalar loads for vector statements
When generating scalar loads/stores separately the vector code has not been
updated. This commit adds code to generate scalar loads for vector code as well
as code to assert in case scalar stores are encountered within a vector loop.

llvm-svn: 255714
2015-12-15 23:49:58 +00:00
Tobias Grosser 0921477248 ScopInfo: Look up first (and only) array access
When rewriting the access functions of load/store statements, we are only
interested in the actual array memory location. The current code just took
the very first memory access, which could be a scalar or an array access. As
a result, we failed to update access functions even though this was requested
via .jscop.

llvm-svn: 255713
2015-12-15 23:49:53 +00:00
Tobias Grosser f4f6870ff2 Revert "Always treat scalar writes as MUST_WRITEs"
This reverts commit r255471.

Johannes raised in the post-commit review of r255471 the concern that PHI
writes in non-affine regions with two exiting blocks are not really MUST_WRITE,
but we just know that at least one out of the set of all possible PHI writes
will be executed. Modeling all PHI nodes as MUST_WRITEs is probably save, but
adding the needed documentation for such a special case is probably not worth
the effort. Michael will be proposing a new patch that ensures only a single
PHI_WRITE is created for non-affine regions, which - besides other benefits -
should also allow us to use a single well-defined MUST_WRITE for such PHI
writes.

(This is not a full revert, but the condition and documentation have been
slightly extended)

llvm-svn: 255503
2015-12-14 15:05:37 +00:00
Michael Kruse e0d135c536 Add unit test for r255473
Check that memory accesses in non-affine regions that are always executed are
MUST_WRITE.

llvm-svn: 255500
2015-12-14 14:53:30 +00:00
Michael Kruse b06e3029d1 Always treat scalar writes as MUST_WRITEs
LLVM's IR guarantees that a value definition occurs before any use, and
also the value of a PHI must be one of the incoming values, "written"
in one of the incoming blocks. Hence, such writes are never conditional
in the context of a non-affine subregion.

llvm-svn: 255471
2015-12-13 22:10:32 +00:00
Tobias Grosser 2d3d4ec860 executeScopConditionally: Introduce special exiting block
When introducing separate control flow for the original and optimized code we
introduce now a special 'ExitingBlock':

      \   /
    EnteringBB
        |
    SplitBlock---------\
   _____|_____         |
  /  EntryBB  \    StartBlock
  |  (region) |        |
  \_ExitingBB_/   ExitingBlock
        |              |
    MergeBlock---------/
        |
      ExitBB
      /    \

This 'ExitingBlock' contains code such as the final_reloads for scalars, which
previously were just added to whichever statement/loop_exit/branch-merge block
had been generated last. Having an explicit basic block makes it easier to
find these constructs when looking at the CFG.

llvm-svn: 255107
2015-12-09 11:38:22 +00:00
Tobias Grosser 87a44d29a2 test: Fix misspelled test line
llvm-svn: 255106
2015-12-09 11:38:08 +00:00
Tobias Grosser a5d9e65e17 Update isl to isl-0.15-142-gf101714
This update brings in improvements to isl's 'isolate' option that reduce the
number of code versions generated. This results in both code-size and compile
time reduction for outer loop vectorization.

Thanks to Roman Garev and Sven Verdoolaege for working on this improvement.

llvm-svn: 254706
2015-12-04 08:46:14 +00:00
Tobias Grosser 2f8e43d677 ScopInfo: Add support for delinearizing fortran arrays
gfortran (and fortran in general?) does not compute the address of an array
element directly from the array sizes (e.g., %s0, %s1), but takes first the
maximum of the sizes and 0 (e.g., max(0, %s0)) before multiplying the resulting
value with the per-dimension array subscript expressions. To successfully
delinearize index expressions as we see them in fortran, we first filter 'smax'
expressions out of the SCEV expression, use them to guess array size parameters
and only then continue with the existing delinearization.

llvm-svn: 253995
2015-11-24 17:06:38 +00:00
Tobias Grosser 9737c7b431 ScopInfo: Remove domains of error blocks (and blocks they dominate) early on
Trying to build up access functions for any of these blocks is likely to fail,
as error blocks may contain invalid/non-representable instructions, and blocks
dominated by error blocks may reference such instructions, which wil also cause
failures. As all of these blocks are anyhow assumed to not be executed, we can
just remove them early on.

This fixes http://llvm.org/PR25596

llvm-svn: 253818
2015-11-22 11:06:51 +00:00
Tobias Grosser 020fa09a3c Remove -polly-code-generator=isl from many test cases
This is the default since a long time. Setting it again does not add value
in any of these test cases.

llvm-svn: 253800
2015-11-21 23:05:48 +00:00
Johannes Doerfert a2a74f09fc Do not enforce lcssa
At some point we enforced lcssa for the loop surrounding the entry block.
  This is not only questionable as it does not check any other loop but also
  not needed any more.

llvm-svn: 253789
2015-11-21 17:00:02 +00:00
Johannes Doerfert dec27df588 [FIX] Get the correct loop that surrounds a region
llvm-svn: 253788
2015-11-21 16:56:13 +00:00
Tobias Grosser b39c96aa19 ScopInfo: Ensure unique names for parameter names coming from load instructions
In case the original parameter instruction does not have a name, but it comes
from a load instruction where the base pointer has a name we used the name of
the load instruction to give some more intuition of where the parameter came
from. To ensure this works also through GEPs which may have complex offsets,
we originally just dropped the offsets and _only_ used the base pointer name.
As this can result in multiple parameters to get the same name, we now prefix
the parameter ID to ensure parameter names are unique. This will make it easier
to understand debug output.

This change does not affect correctness, as parameter IDs (even of the same
name) can always be distinguished through the SCEV pointer stored inside them.

llvm-svn: 253330
2015-11-17 11:54:51 +00:00
Johannes Doerfert a4b77c079b [FIX] Bail if access function is not divisible by element size.
llvm-svn: 252942
2015-11-12 20:15:32 +00:00
Johannes Doerfert 55b3d8b831 Consistenly use getTypeAllocSize for size estimation.
Only when we check for wrapping we want to use the store size, for all
  other cases we use the alloc size now.

Suggested by: Tobias Grosser <tobias@grosser.es>

llvm-svn: 252941
2015-11-12 20:15:08 +00:00
Tobias Grosser bc29e0b27c RegionGenerator: Only introduce subregion.ivs for loops fully within a subregion
IVs of loops for which the loop header is in the subregion, but not the entire
loop may be incremented outside of the subregion and can consequently not be
kept private to the subregion. Instead, they need to and are modeled as virtual
loops in the iteration domains. As this is the case, generating new subregion
induction variables for such loops is not needed and indeed wrong as they would
hide the virtual induction variables modeled in the scop.

This fixes a miscompile in MultiSource/Benchmarks/Ptrdist/bc and
MultiSource/Benchmarks/nbench/. Thanks Michael and Johannes for their
investiagations and helpful observations regarding this bug.

llvm-svn: 252860
2015-11-12 07:34:09 +00:00
Johannes Doerfert 2af10e2eed Use parameter constraints provided via llvm.assume
If an llvm.assume dominates the SCoP entry block and the assumed condition
  can be expressed as an affine inequality we will now add it to the context.

Differential Revision: http://reviews.llvm.org/D14413

llvm-svn: 252851
2015-11-12 03:25:01 +00:00
Johannes Doerfert d84493e52e Emit remarks for taken assumptions
Differential Revision: http://reviews.llvm.org/D14412

llvm-svn: 252848
2015-11-12 02:33:38 +00:00
Johannes Doerfert 0cf4e0aa42 Emit remark about aliasing pointers
llvm-svn: 252847
2015-11-12 02:32:51 +00:00
Johannes Doerfert 48fe86f1ff Emit SCoP source location as remark during ScopInfo
This removes a similar feature from ScopDetection, though with
  -polly-report that feature present twice anyway.

llvm-svn: 252846
2015-11-12 02:32:32 +00:00
Johannes Doerfert fdbf201fc9 [FIX] Do not generate code for parameters referencing dead values
Check if a value that is referenced by a parameter is dead and do not
generate code for the parameter in such a case.

llvm-svn: 252813
2015-11-11 22:40:51 +00:00
Tobias Grosser e19fca4525 ScopInfo: Bailing out means assigning isl_set_empty to the AssumedContext
I got this the other way around in 252750. Thank you Johannes for noticing.

llvm-svn: 252795
2015-11-11 20:21:39 +00:00
Tobias Grosser 910cf26811 ScopInfo: Do not try to model the memory accesses in an error block
Error blocks may contain arbitrary instructions, among them some which we can
not modeled correctly. As we do not generate ScopStmts for error blocks anyhow
there is no point in trying to generate access functions for them.

This fixes llvm.org/PR25494

llvm-svn: 252794
2015-11-11 20:15:49 +00:00
Tobias Grosser 4cd07b1188 ScopInfo: Bound compute time spent in boundary context construction
For complex inputs our current approach of construction the boundary context
may in rare cases become computationally so expensive that it is better to
abort. This change adds a compute out check that bounds the compuations we
spend on boundary context construction and bails out if this limit is reached.

We can probably make our boundary construction algorithm more efficient, but
this requires some more investigation and probably also some additional changes
to isl. Until these have been added, we bound the compile time to ensure our
buildbots are green.

llvm-svn: 252758
2015-11-11 17:34:02 +00:00
Tobias Grosser 20a4c0c205 ScopInfo: Limit the number of disjuncts in assumed context
In certain rare cases (mostly -polly-process-unprofitable on large sequences
of conditions - often without any loop), we see some compile-time timeouts due
to the construction of an overly complex assumption context. This change limits
the number of disjuncts to 150 (adjustable), to prevent us from creating
assumptions contexts that are too large for even the compilation to finish.

The limit has been choosen as large as possible to make sure we do not
unnecessarily drop test coverage. If such cases also appear in
-polly-process-unprofitable=false mode we may need to think about this again,
as the current limitations may still allow assumptions that are way to complex
to be checked profitably at run-time.

There is also certainly room for improvement regarding how (and how efficient)
we construct an assumed context, but this requires some more thinking.

This completes llvm.org/PR25458

llvm-svn: 252750
2015-11-11 16:22:36 +00:00
Tobias Grosser e3d1f1c0b0 ScopDetection: Tighten the check for always executed 'error blocks'
Basic blocks that are always executed can not be error blocks as their execution
can not possibly be an unlikely event. In this commit we tighten the check
if an error block to basic blcoks that do not dominate the exit condition, but
that dominate all exiting blocks of the scop.

llvm-svn: 252726
2015-11-11 13:25:13 +00:00
Tobias Grosser b12b006c4b ScopDetection: Do not allow blocks to reference operands in error blocks
r252713 introduced a couple of regressions due to later basic blocks refering
to instructions defined in error blocks which have not yet been modeled.

This commit is currently just encoding limitations of our modeling and code
generation backends to ensure correctness. In theory, we should be able to
generate and optimize such regions, as everything that is dominated by an error
region is assumed to not be executed anyhow. We currently just lack the code
to make this happen in practice.

llvm-svn: 252725
2015-11-11 12:44:18 +00:00
Tobias Grosser 56e3fefbdc test: Shorten test case to reduce 'make polly-check' time
Thinking more about the last commit I came to realize that for testing the
new functionality it is sufficient to verify that the iteration domains
we construct for a simple test case do not contain any of the complexity that
caused compile time issues for larger inputs.

llvm-svn: 252714
2015-11-11 09:19:15 +00:00
Tobias Grosser b76cd3cc56 ScopInfo: Pass domain constraints through error blocks
Previously, we just skipped error blocks during scop construction. With
this change we make sure we can construct domains for error blocks such that
these domains can be forwarded to subsequent basic blocks.

This change ensures that basic blocks that post-dominate and are dominated by
a basic block that branches to an error condition have the very same iteration
domain as the branching basic block. Before, this change we would construct
a domain that excludes all error conditions. Such domains could become _very_
complex and were undesirable to build.

Another solution would have been to drop these constraints using a
dominance/post-dominance check instead of modeling the error blocks. Such
a solution could also work in case of unreachable statements or infinite
loops in the scop. However, as we currently (to my believe incorrectly) model
unreachable basic blocks in the post-dominance tree, such a solution is not
yet feasible and requires first a change to LLVM's post-dominance tree
construction.

This commit addresses the most sever compile time issue reported in:
http://llvm.org/PR25458

llvm-svn: 252713
2015-11-11 08:42:20 +00:00
Johannes Doerfert dcfedf3505 [FIX] Cast pre-loaded values correctly or reload them with adjusted type.
Especially for structs, the SAI object of a base pointer does not
describe all the types that the user might expect when he loads from
that base pointer. While we will still cast integers and pointers we
will now reload the value with the correct type if floating point and
non-floating point values are involved. However, there are now TODOs
where we use bitcasts instead of a proper conversion or reloading.

This fixes bug 25479.

llvm-svn: 252706
2015-11-11 06:20:25 +00:00
Johannes Doerfert fc4bfc465a [FIX] Create empty invariant equivalence classes
We now create all invariant equivalence classes for required invariant loads
  instead of creating them on-demand. This way we can check if a parameter
  references an invariant load that is actually not executed and was therefor
  not materialized. If that happens the parameter is not materialized either.

This fixes bug 25469.

llvm-svn: 252701
2015-11-11 04:30:07 +00:00
Tobias Grosser 8b05278b4e tests: Add test that has a single pointer both as scalar read and array base
In case we also model scalar reads it can happen that a pointer appears in both
a scalar read access as well as the base pointer of an array access. As this
is a little surprising, we add a specific test case to document this behaviour.
To my understanding it should be OK to have a read from an array A[] and
read/write accesses to A[...]. isl is treating these arrays as unrelated as
their dimensionality differs. This seems to be correct as A[] remains constant
throughout the execution of the scop and is not affected by the reads/writes to
A[...]. If this causes confusion, it might make sense to make this behaviour
more obvious by using different names (e.g., A_scalar[], A[...]).

llvm-svn: 252615
2015-11-10 16:23:30 +00:00
Tobias Grosser 98e566e213 Simplify test case
Commit r252422 introduced an unnecessary complicated test case. Reduce it to
the part that actually triggered the original issue.

llvm-svn: 252611
2015-11-10 15:42:44 +00:00
Tobias Grosser 4ea2e07a60 ScopInfo: Make printing of ScopArrayInfo more similar to declarations in C
Memory references are now printed as follows:

           Old                          New
Scalars:   i64 MemRef_val[*]            i64 MemRef_val;
Arrays:    i64 MemRef_A[*][%m][%o][8]   i64 MemRef_A[*][%m][%o];

We do not print any more information about the element size in the type. Such
information has already been available in a comment after the scalar/array
declaration. It was redundant and did not match well with what people were used
from C.

llvm-svn: 252602
2015-11-10 14:02:54 +00:00
Michael Kruse c993739e0d Fix non-affine generated entering node not being recognized as dominating
Scalar reloads in the generated entering block were not recognized as
dominating the subregions locks when there were multiple entering
nodes. This resulted in values defined in there not being copied.

As a fix, we unconditionally add the BBMap of the generated entering
node to the generated entry. This fixes part of llvm.org/PR25439.

This reverts 252449 and reapplies r252445. Its test was failing
indeterministically due to r252375 which was reverted in r252522.

llvm-svn: 252540
2015-11-09 23:33:40 +00:00
Michael Kruse d6fb6f1b0c Fix dominance when subregion exit is outside scop
The dominance of the generated non-affine subregion block was based on
the scop's merge block, therefore resulted in an invalid DominanceTree.
It resulted in some values as assumed to be unusable in the actual
generated exit block.

We detect the case that the exit block has been moved and decide
dominance using the BB at the original exit. If we create another exit
node, that exit nodes is dominated by the one generated from where the
original exit resides. This fixes llvm.org/PR25438 and part of
llvm.org/PR25439.

llvm-svn: 252526
2015-11-09 23:07:38 +00:00
Michael Kruse ebffcbeefa Revert r252375 "Fix non-affine region dominance of implicitely stored values"
It introduced indeterminism as it was iterating over an address-indexed
hashtable. The corresponding bug PR25438 will be fixed in a successive
commit.

llvm-svn: 252522
2015-11-09 22:37:29 +00:00
Johannes Doerfert 7a6e292d86 [FIX] Use same alloca for invariant loads and the scalar users
llvm-svn: 252451
2015-11-09 06:28:45 +00:00
Johannes Doerfert 544b23a1ef Revert "Fix non-affine generated entering node not being recognized as dominating"
This reverts commit 9775824b265e574fc541e975d64d3e270243b59d due to a
failing unit test.

Please check and correct the unit test and commit again.

llvm-svn: 252449
2015-11-09 06:04:05 +00:00
Michael Kruse fd9c89e84b Fix non-affine generated entering node not being recognized as dominating
Scalar reloads in the generated entering block were not recognized as
dominating the subregions locks when there were multiple entering
nodes. This resulted in values defined in there not being copied.

As a fix, we unconditionally add the BBMap of the generated entering
node to the generated entry. This fixes part of llvm.org/PR25439.

llvm-svn: 252445
2015-11-09 05:00:30 +00:00
Johannes Doerfert 188542fda9 [FIX] Initialize incoming scalar memory locations for PHIs
llvm-svn: 252437
2015-11-09 00:21:21 +00:00
Johannes Doerfert f85ad0411f [FIX] Carefully simplify assumptions in the presence of error blocks
If a SCoP contains error blocks we cannot use the domain constraints
  to simplify the assumptions as the domain is already influenced by the
  assumptions we took. Before this patch we did that and some assumptions
  became self-fulfilling as they were implied by the domain constraints.

llvm-svn: 252424
2015-11-08 20:16:39 +00:00
Johannes Doerfert a768624f14 [FIX] Introduce different SAI objects for scalar and memory accesses
Even if a scalar and memory access have the same base pointer, we cannot use
  one SAI object as the type but also the number of dimensions are wrong. For
  the attached test case this caused a crash in the invariant load hoisting,
  though it could cause various other problems too.

This fixes bug 25428 and a execution time bug in MallocBench/cfrac.

Reported-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
llvm-svn: 252422
2015-11-08 19:12:05 +00:00
Johannes Doerfert 3797707695 [FIX] Use unreachable to indicate dead code and repair dominance
When we bail out early we make the partially build new code path
  practically dead, though it was not unreachable. To remove dominance
  problems we now make it not only dead but also prevent the control
  flow to join with the original code path, thus allow to use original
  values after the SCoP without any PHI nodes.

This fixes bug 25447.

llvm-svn: 252420
2015-11-08 17:57:41 +00:00
Johannes Doerfert c4898504ea [FIX] Bail out if there is a dependence cycle between invariant loads
While the program cannot cause a dependence cycle between invariant
  loads, additional constraints (e.g., to ensure finite loops) can
  introduce them. It is hard to detect them in the SCoP description,
  thus we will only check for them at code generation time. If such a
  recursion is detected we will bail out the code generation and place a
  "false" runtime check to guarantee the original code is used.

  This fixes bug 25443.

llvm-svn: 252412
2015-11-07 19:46:04 +00:00
Johannes Doerfert 44483c5599 [FIX] Remove all invariant load occurences from own execution context
llvm-svn: 252411
2015-11-07 19:45:27 +00:00
Michael Kruse 0651480b97 Fix non-affine region dominance of implicitely stored values
After loop versioning, a dominance check of a non-affine subregion's
exit node causes the dominance check to always fail on any block in the
subregion if it shares the same exit block with the scop. The
subregion's exit block has become polly_merge_new_and_old, which also
receives the control flow of the generated code. This would cause that
any value for implicit stores is assumed to be not from the scop.

We check dominance with the generated exit node instead.

This fixes llvm.org/PR25438

llvm-svn: 252375
2015-11-07 00:36:50 +00:00
Tobias Grosser 712229ec59 Add missing '%loadPolly' to test case
llvm-svn: 252302
2015-11-06 14:03:35 +00:00
Michael Kruse ddb6528ba6 Fix reuse of non-dominating synthesized value in subregion exit
We were adding all generated values in non-affine subregions to be used
for the subregions generated exit block. The thought was that only
values that are dominating the original exit block can be used there.
But it is possible for synthesizable values to be expanded in any
block. If the same values is also used for implicit writes, it would
try to reuse already synthesized values even if not dominating the exit
block.

The fix is to only add values to the list of values usable in the exit
block only if it is dominating the exit block. This fixes
llvm.org/PR25412.

llvm-svn: 252301
2015-11-06 13:51:24 +00:00
Tobias Grosser 6578f001bf Adjust debug metadata to LLVM changes in 252219
llvm-svn: 252273
2015-11-06 06:27:39 +00:00
Tobias Grosser f1bfd75221 ScopInfo: Allocate globally unique memory access identifiers
Before this commit memory reference identifiers have only been unique per
basic block, but not per (non-affine) ScopStmt. This commit now uses the
MemoryAccess base pointer to uniquely identify each Memory access.

llvm-svn: 252200
2015-11-05 20:15:37 +00:00
Michael Kruse 27149cf32d Use per-BB value maps for non-exit BBs
For generating scalar writes of non-affine subregions, all except phi
writes are generated in the exit block. The phi writes are generated in
the incoming block for which we errornously used the same BBMap. This
can conflict if a value for one block is synthesized, and then reused
for another block which is not dominated by the first block. This is
fixed by using block-specific BBMaps for phi writes.

llvm-svn: 252172
2015-11-05 16:17:17 +00:00
Michael Kruse f714d470d7 Fix escaping value to subregion entry node phi
An incoming value from a block the is not inside the scop is an
external use, even if the phi is inside the scop. A previous fix in
r251208 did not apply if the phi is inside a non-affine subregion. We
move the check for this phi case before the non-affine subregion check.

llvm-svn: 252157
2015-11-05 13:18:43 +00:00
Johannes Doerfert 22892687f7 [FIX] Simplify and correct preloading of base pointer origin
To simplify and correct the preloading of a base pointer origin, e.g.,
  the base pointer for the current indirect invariant load, we now just
  check if there is an invariant access class that involves the base
  pointer of the current class.

llvm-svn: 251962
2015-11-03 19:15:33 +00:00
Johannes Doerfert eca9e890b9 Remove read-only statements from the SCoP
We do not need to model read-only statements in the SCoP as they will
  not cause any side effects that are visible to the outside anyway.
  Removing them should safe us time and might even simplify the ASTs we
  generate.

Differential Revision: http://reviews.llvm.org/D14272

llvm-svn: 251948
2015-11-03 16:54:49 +00:00
Johannes Doerfert 475d8e3f42 [FIX] Ensure base pointer origin was preloaded already
If a base pointer of a preloaded value has a base pointer origin, thus it is
  an indirect invariant load, we have to make sure the base pointer origin is
  preloaded first.

llvm-svn: 251946
2015-11-03 16:49:02 +00:00
Johannes Doerfert d6fc0701ee [FIX] Carefully rewrite parameters wrt. invariant equivalence classes
ScalarEvolution doesn't allow the operands of an AddRec to be variant in the
  loop of the AddRec. When we rewrite parameter SCEVs it might seem like the
  new SCEV violates this property and ScalarEvolution will trigger an
  assertion. To avoid this we move the start part out of an AddRec when we
  rewrite it, thus avoid the operands to be possibly variant completely.

llvm-svn: 251945
2015-11-03 16:47:58 +00:00
Johannes Doerfert 3181c2ef72 [FIX] Correctly update SAI base pointer
If a base pointer load is preloaded, we have change the base pointer of
  the derived SAI. However, as the derived SAI relationship is is
  coarse grained, we need to check if we actually preloaded the base
  pointer or a different element of the base pointer SAI array.

llvm-svn: 251881
2015-11-03 01:42:59 +00:00
Johannes Doerfert dca2837b76 [FIX] Do not crash in the presence of infinite loops.
llvm-svn: 251870
2015-11-03 00:28:07 +00:00
Johannes Doerfert 907456fe04 [FIX] Use appropriately sized types for big constants
llvm-svn: 251869
2015-11-03 00:26:22 +00:00
Tobias Grosser 8286b83f97 ScopInfo: Bail out in case of mismatching array dimension sizes
In some cases different memory accesses access the very same array using a
different multi-dimensional array layout where the same dimensions have
different sizes. Instead of asserting when encountering this issue, we
gracefully bail out for this scop.

This fixes llvm.org/PR25252

llvm-svn: 251791
2015-11-02 11:29:32 +00:00
Tobias Grosser 4dc909cbed tests: Add test cases for LLVM commit r251267
This fixes llvm.org/PR25242

llvm-svn: 251268
2015-10-25 22:56:42 +00:00
Tobias Grosser bf45e74254 ScopDetect: Bail out for non-simple memory accesses
Volatile or atomic memory accesses are currently not supported. Neither did
we think about any special handling needed nor do we support the unknown
instructions the alias set tracker turns them into sometimes. Before this
patch, us not supporting unkown instructions in an alias set caused the
following assertion failures:

Assertion `AG.size() > 1 && "Alias groups should contain at least two accesses"'
failed

llvm-svn: 251234
2015-10-25 13:48:40 +00:00
Tobias Grosser 4d935cd9aa tests: Add test case forgotten in 251191
llvm-svn: 251228
2015-10-25 10:55:40 +00:00
Tobias Grosser 907090c37c ScopDetection: Update DetectionContextMap accordingly
When verifying if a scop is still valid we rerun all analysis, but did not
update DetectionContextMap. This change ensures that information, e.g. about
non-affine regions, is correctly updated

llvm-svn: 251227
2015-10-25 10:55:35 +00:00
Tobias Grosser 51174cca30 ScopDetection: Do not crash if we find zero array size candidates for delinearization
llvm-svn: 251226
2015-10-25 08:40:44 +00:00
Tobias Grosser 5528dcdf25 ScopDetection: Always refuse multi-dimensional memory accesses with 'undef' in
the size expression.

We previously only checked if the size expression is 'undef', but allowed size
expressions of the form 'undef * undef' by accident. After this change we now
require size expressions to be affine which implies no 'undef' appears anywhere
in the expression.

llvm-svn: 251225
2015-10-25 08:40:38 +00:00
Tobias Grosser baffa091dd ScopInfo: PHI-node uses in the EntryNode with an incoming BB that is not part
of the Region are external.

During code generation we split off the parts of the PHI nodes in the entry
block, which have incoming blocks that are not part of the region. As these
split-off PHI nodes then are external uses, we consequently also need to model
these uses in ScopInfo.

llvm-svn: 251208
2015-10-24 20:55:27 +00:00
Tobias Grosser ffd6b3bb29 Add a missing '-S'
llvm-svn: 251199
2015-10-24 19:02:01 +00:00
Tobias Grosser a3f6edaee1 BlockGenerator: Do not assert when finding model PHI nodes defined outside the scop
Such PHI nodes can not only appear in the ExitBlock of the Scop, but indeed
any scalar PHI node above the scop and used in the scop is modeled as scalar
read access.

llvm-svn: 251198
2015-10-24 19:01:09 +00:00
Johannes Doerfert 654c3284f4 [FIX] Do not hoist nested variant base pointers
This fixes bug 25249.

llvm-svn: 250958
2015-10-21 22:14:57 +00:00
Tobias Grosser ca7f5bb767 Full/partial tile separation for vectorization
We isolate full tiles from partial tiles to be able to, for example, vectorize
loops with parametric lower and/or upper bounds.

If we use -polly-vectorizer=stripmine, we can see execution-time improvements:
correlation from 1m7361s to 0m5720s (-67.05 %), covariance from 1m5561s to
0m5680s (-63.50 %), ary3 from 2m3201s to 1m2361s (-46.72 %), CrystalMk from
8m5565s to 7m4285s (-13.18 %).

The current full/partial tile separation increases compile-time more than
necessary. As a result, we see in compile time regressions, for example, for 3mm
from 0m6320s to 0m9881s (56.34%). Some of this compile time increase is expected
as we generate more IR and consequently more time is spent in the LLVM backends.
However, a first investiagation has shown that a larger portion of compile time
is unnecessarily spent inside Polly's parallelism detection and could be
eliminated by propagating existing knowledge about vector loop parallelism.
Before enabling -polly-vectorizer=stripmine by default, it is necessary to
address this compile-time issue.

Contributed-by: Roman Gareev <gareevroman@gmail.com>

Reviewers: jdoerfert, grosser

Subscribers: grosser, #polly

Differential Revision: http://reviews.llvm.org/D13779

llvm-svn: 250809
2015-10-20 09:12:21 +00:00
Michael Kruse 48ea8efd59 Correct typo in CHECK line
Thanks Tobias for the hint.

llvm-svn: 250695
2015-10-19 10:51:20 +00:00
Michael Kruse dc12222287 Synthesize phi arguments in incoming block
New values were always synthesized in the block of the instruction
that needed them. This is incorrect for PHI node whose' value must be
defined in the respective incoming block. This patch temporarily moves
the builder's insert point to the incoming block while synthesizing phi
node arguments. 

This fixes PR25241 (http://llvm.org/bugs/show_bug.cgi?id=25241)

llvm-svn: 250693
2015-10-19 09:19:25 +00:00
Johannes Doerfert 9c28bfa72c [FIX] Only constant integer branch conditions are always affine
There are several different kinds of constants that could occur in a
  branch condition, however we can only handle the most interesting one
  namely constant integers. To this end we have to treat others as
  non-affine.

  This fixes bug 25244.

llvm-svn: 250669
2015-10-18 22:56:42 +00:00
Johannes Doerfert 30c2265f98 [FIX] Normalize loops outside the SCoP during schedule generation
We build the schedule based on a traversal of the region and accumulate
  information for each loop in it. The total schedule is associated with the
  loop surrounding the SCoP, though it can happen that there are blocks in the
  SCoP which are part of loops that are only partially in the SCoP. Instead of
  associating information with them (they are not part of the SCoP and
  consequently are not modeled) we have to associate the schedule information
  with the surrounding loop if any.

  This fixes bug 25240.

llvm-svn: 250668
2015-10-18 21:17:11 +00:00
Johannes Doerfert b864c2c3c9 [FIX] Do not try to hoist "empty" accesses
Accesses that have a relative offset (in bytes) that is not divisible
  by the type size (in bytes) will be represented as empty in the SCoP
  description. This is on its own not good but it also crashed the
  invariant load hoisting. This patch will fix the latter problem while
  the former should be addressed too.

  This fixes bug 25236.

llvm-svn: 250664
2015-10-18 19:50:18 +00:00
Johannes Doerfert bc7cff4c18 [FIX] Do not hoist invariant pointers with non-loaded base ptr in SCoP
If the base pointer of a load is invariant and defined in the SCoP but
  not loaded we cannot hoist the load as we would not hoist the base
  pointer definition.

  This fixes bug 25237.

llvm-svn: 250663
2015-10-18 19:49:25 +00:00
Johannes Doerfert af3e301a67 [FIX] Restructure invariant load equivalence classes
Sorting is replaced by a demand driven code generation that will pre-load a
  value when it is needed or, if it was not needed before, at some point
  determined by the order of invariant accesses in the program. Only in very
  little cases this demand driven pre-loading will kick in, though it will
  prevent us from generating faulty code. An example where it is needed is
  shown in:
    test/ScopInfo/invariant_loads_complicated_dependences.ll

  Invariant loads that appear in parameters but are not on the top-level (e.g.,
  the parameter is not a SCEVUnknown) will now be treated correctly.

Differential Revision: http://reviews.llvm.org/D13831

llvm-svn: 250655
2015-10-18 12:39:19 +00:00
Johannes Doerfert d8b6ad255f [FIX] Cast preloaded values
Preloaded values have to match the type of their counterpart in the
  original code and not the type of the base array.

llvm-svn: 250654
2015-10-18 12:36:42 +00:00
Johannes Doerfert 01978cfa0c Remove independent blocks pass
Polly can now be used as a analysis only tool as long as the code
  generation is disabled. However, we do not have an alternative to the
  independent blocks pass in place yet, though in the relevant cases
  this does not seem to impact the performance much. Nevertheless, a
  virtual alternative that allows the same transformations without
  changing the input region will follow shortly.

llvm-svn: 250652
2015-10-18 12:28:00 +00:00
Tobias Grosser b8d27aab7d Revert to original BlockGenerator::getOrCreateAlloca(MemoryAccess &Access)
Expressing this in terms of BlockGenerator::getOrCreateAlloca(const
ScopArrayInfo *Array) does not work as the MemoryAccess BasePtr is in case of
invariant load hoisting different to the ScopArrayInfo BasePtr. Until this is
investigated and fixed, we move back to code that just uses the baseptr of
MemoryAccess.

llvm-svn: 250637
2015-10-18 00:51:13 +00:00
Michael Kruse 225f0d1ee2 Load/Store scalar accesses before/after the statement itself
Instead of generating implicit loads within basic blocks, put them 
before the instructions of the statment itself, including non-affine 
subregions. The region's entry node is dominating all blocks in the 
region and therefore the loaded value will be available there.

Implicit writes in block-stmts were already stored back at the end of 
the block. Now, also generate the stores of non-affine subregions when 
leaving the statement, i.e. in the exiting block.

This change is required for array-mapped implicits ("De-LICM") to 
ensure that there are no dependencies of demoted scalars within 
statments. Statement load all required values, operator on copied in 
registers, and then write back the changed value to the demoted memory. 
Lifetimes analysis within statements becomes unecessary.

Differential Revision: http://reviews.llvm.org/D13487

llvm-svn: 250625
2015-10-17 21:36:00 +00:00
Michael Kruse 01cb379fed Avoid unnecessay .s2a write access when used only in PHIs
Accesses for exit node phis will be handled separately by 
buildPHIAccesses if there is more than one exiting edge, 
buildScalarDependences does not need to create additional SCALAR 
accesses.

This is a corrected version of r250517, which was reverted in r250607.

Differential Revision: http://reviews.llvm.org/D13848

llvm-svn: 250622
2015-10-17 21:07:08 +00:00
Tobias Grosser 3839b422e6 Revert "Avoid unnecessay .s2a write access when used only in PHIs"
This reverts commit r250606 due to some bugs it introduced. After these bugs
have been resolved, we will add it back to tree.

llvm-svn: 250607
2015-10-17 08:54:05 +00:00
Michael Kruse e71893d580 Add testcase for r250517
llvm-svn: 250518
2015-10-16 15:17:26 +00:00
Michael Kruse aeceab770e Avoid unnecessay .s2a write access when used only in PHIs
PHI accesses will be handled separately by buildPHIAccesses,
buildScalarDependences does not need to create additional accesses.

llvm-svn: 250517
2015-10-16 15:14:40 +00:00
Tobias Grosser b860289dbd Add ScopInfo test case for r250411
llvm-svn: 250439
2015-10-15 18:26:06 +00:00
Tobias Grosser 473a5c3253 test: Correctly check for branch statements
In r250408 'CHECK-NEXT: br' lines were removed as they also matched a
'%polly.subregion.iv.inc' instruction and did consequently not check what they
were supposed to check. However, without these lines we can not test that the
.s2a instructions that are not any more generated since r250411 really are not
emitted. Hence, we add back the CHECK-NEXT lines to ensure there are really no
instructions generated between the store that we check for and the branch at the
end of the basic block. To ensure we do not match too early, we now check for
'br i1' or 'br label'.

llvm-svn: 250435
2015-10-15 18:04:20 +00:00
Michael Kruse 668af71b82 Do not add accesses for intra-ScopStmt scalar def-use chains
When pulling a llvm::Value to be written as a PHI write, the former
code did only check whether it is within the same basic block, but it
could also be the same non-affine subregion. In that case some 
unecessary pair of MemoryAccesses would have been created.

Two unit test were explicitely checking for the unecessary writes,
including the comments that the writes are unecessary. 

llvm-svn: 250411
2015-10-15 14:45:48 +00:00
Michael Kruse 90428328ee Remove "CHECK: br" from some unit tests
They happen to match
%polly.subregion.iv.inc = add i32 %polly.subregion.iv, 1
         ^^                                ^^
that is, are misleading in what they actually check.

llvm-svn: 250408
2015-10-15 14:40:40 +00:00
Michael Kruse b987be12bf Add testcase for SCEV explansion in non-affine subregions
When sharing the same map from old to new value, CodeGeneration would
reuse the same new value for each basic block. However, the SCEV
expander might emit code in a basic block that does not dominate a use
of the SCEV in another basic block. This test checks whether both such
blocks have their own expanded new values. 

llvm-svn: 250389
2015-10-15 10:40:14 +00:00
Tobias Grosser 6b948d5efb [tests] More testing for PHI-nodes in non-affine regions
We harden one test case by ensuring no additional stores may possibly be
introduced between the stores we check for and the basic block terminator
statements.

We also add a test case for the situation where a value that is passed from
a non-affine region to a PHI node does not dominate the exit of the non-affine
region. This case has come up in patch reviews, so we make sure it is properly
handled today and in the future.

llvm-svn: 250217
2015-10-13 20:03:09 +00:00
Tobias Grosser e2c8275346 ScopInfo: Allow simple 'AddRec * Parameter' products in delinearization
We also allow such products for cases where 'Parameter' is loaded within the
scop, but where we can dynamically verify that the value of 'Parameter' remains
unchanged during the execution of the scop.

This change relies on Polly's new RequiredILS tracking infrastructure recently
contributed by Johannes.

llvm-svn: 250019
2015-10-12 08:02:30 +00:00
Johannes Doerfert 9b1f9c8b61 Allow eager evaluated binary && and || conditions
The domain generation can handle lazy && and || by default but eager
  evaluated expressions were dismissed as non-affine. With this patch we
  will allow arbitrary combinations of and/or bit-operations in the
  conditions of branches.

Differential Revision: http://reviews.llvm.org/D13624

llvm-svn: 249971
2015-10-11 13:21:03 +00:00
Johannes Doerfert 697fdf891c Consolidate invariant loads
If a (assumed) invariant location is loaded multiple times we
  generated a parameter for each location. However, this caused compile
  time problems for several benchmarks (e.g., 445_gobmk in SPEC2006 and
  BT in the NAS benchmarks). Additionally, the code we generate is
  suboptimal as we preload the same location multiple times and perform
  the same checks on all the parameters that refere to the same value.

  With this patch we consolidate the invariant loads in three steps:
    1) During SCoP initialization required invariant loads are put in
       equivalence classes based on their pointer operand. One
       representing load is used to generate a parameter for the whole
       class, thus we never generate multiple parameters for the same
       location.
    2) During the SCoP simplification we remove invariant memory
       accesses that are in the same equivalence class. While doing so
       we build the union of all execution domains as it is only
       important that the location is at least accessed once.
    3) During code generation we only preload one element of each
       equivalence class with the unified execution domain. All others
       are mapped to that preloaded value.

Differential Revision: http://reviews.llvm.org/D13338

llvm-svn: 249853
2015-10-09 17:12:26 +00:00
Johannes Doerfert c7ab83dfb7 Remove unused flag polly-allow-non-scev-backedge-taken-count
Drop an unused flag polly-allow-non-scev-backedge-taken-count and also
  its occurrences from the tests.

Contributed-by: Chris Jenneisch <chrisj@codeaurora.org>

Differential Revision: http://reviews.llvm.org/D13400

llvm-svn: 249675
2015-10-08 10:05:48 +00:00
Johannes Doerfert 08d90a3cee Treat conditionally executed non-pure calls as errors
This replaces the support for user defined error functions by a
  heuristic that tries to determine if a call to a non-pure function
  should be considered "an error". If so the block is assumed not to be
  executed at runtime. While treating all non-pure function calls as
  errors will allow a lot more regions to be analyzed, it will also
  cause us to dismiss a lot again due to an infeasible runtime context.
  This patch tries to limit that effect. A non-pure function call is
  considered an error if it is executed only in conditionally with
  regards to a cheap but simple heuristic.

llvm-svn: 249611
2015-10-07 20:32:43 +00:00
Johannes Doerfert 09e3697f44 Allow invariant loads in the SCoP description
This patch allows invariant loads to be used in the SCoP description,
  e.g., as loop bounds, conditions or in memory access functions.

  First we collect "required invariant loads" during SCoP detection that
  would otherwise make an expression we care about non-affine. To this
  end a new level of abstraction was introduced before
  SCEVValidator::isAffineExpr() namely ScopDetection::isAffine() and
  ScopDetection::onlyValidRequiredInvariantLoads(). Here we can decide
  if we want a load inside the region to be optimistically assumed
  invariant or not. If we do, it will be marked as required and in the
  SCoP generation we bail if it is actually not invariant. If we don't
  it will be a non-affine expression as before. At the moment we
  optimistically assume all "hoistable" (namely non-loop-carried) loads
  to be invariant. This causes us to expand some SCoPs and dismiss them
  later but it also allows us to detect a lot we would dismiss directly
  if we would ask e.g., AliasAnalysis::canBasicBlockModify(). We also
  allow potential aliases between optimistically assumed invariant loads
  and other pointers as our runtime alias checks are sound in case the
  loads are actually invariant. Together with the invariant checks this
  combination allows to handle a lot more than LICM can.

  The code generation of the invariant loads had to be extended as we
  can now have dependences between parameters and invariant (hoisted)
  loads as well as the other way around, e.g.,
    test/Isl/CodeGen/invariant_load_parameters_cyclic_dependence.ll
  First, it is important to note that we cannot have real cycles but
  only dependences from a hoisted load to a parameter and from another
  parameter to that hoisted load (and so on). To handle such cases we
  materialize llvm::Values for parameters that are referred by a hoisted
  load on demand and then materialize the remaining parameters. Second,
  there are new kinds of dependences between hoisted loads caused by the
  constraints on their execution. If a hoisted load is conditionally
  executed it might depend on the value of another hoisted load. To deal
  with such situations we sort them already in the ScopInfo such that
  they can be generated in the order they are listed in the
  Scop::InvariantAccesses list (see compareInvariantAccesses). The
  dependences between hoisted loads caused by indirect accesses are
  handled the same way as before.

llvm-svn: 249607
2015-10-07 20:17:36 +00:00
Tobias Grosser 369c1d663b test: Add example of scalar that is reused accross loop
llvm-svn: 249527
2015-10-07 09:00:29 +00:00
Tobias Grosser 575aca8d43 Introduce -polly-process-unprofitable
This single option replaces -polly-detect-unprofitable and -polly-no-early-exit
and is supposed to be the only option that disables compile-time heuristics that
aim to bail out early on scops that are believed to not benefit from Polly
optimizations.

Suggested-by:  Johannes Doerfert
llvm-svn: 249426
2015-10-06 16:10:29 +00:00
Tobias Grosser f4ee371e60 tests: Drop -polly-detect-unprofitable and -polly-no-early-exit
These flags are now always passed to all tests and need to be disabled if
not needed. Disabling these flags, rather than passing them to almost all
tests, significantly simplfies our RUN: lines.

llvm-svn: 249422
2015-10-06 15:36:44 +00:00
Tobias Grosser 4fdcf7b813 test: By default disable Polly's compile-time profitability heuristics
llvm-svn: 249420
2015-10-06 15:30:26 +00:00
Tobias Grosser 935f62cf0d tests: Explicitly state if profitability tests should be used
Polly's profitability heuristic saves compile time by skipping trivial scops or
scops were we know no good optimization can be applied. For almost all our tests
this heuristic makes little sense as we aim for minimal test cases when testing
functionality. Hence, in almost all cases this heuristic is better be disabled.
In preparation of disabling Polly's compile time heuristic by default in the
test suite we first explicitly enable it in the couple of test cases that really
use it (or run with/without heuristic side-by-side).

llvm-svn: 249418
2015-10-06 15:19:35 +00:00
Tobias Grosser 1ac26d06fe test: Disable profitability heuristics to unfail LICM test case
This test case was XFAILed under the assumption Polly is unable to detect the
scop. However, disabling Polly's profitability heuristics is sufficient to
detect this scop.

llvm-svn: 249414
2015-10-06 15:10:19 +00:00
Tobias Grosser d76603fbe7 test: sdiv in loop bounds is supported since a while
By disabling our scop-profitability heuristics this becomes also visible in some
older test cases.

llvm-svn: 249411
2015-10-06 14:59:31 +00:00
Tobias Grosser b73c695aba tests: Drop outdated and unused lit variable
llvm-svn: 249401
2015-10-06 13:50:20 +00:00
Johannes Doerfert f17a78ef63 Remove non-executed statements during SCoP simplifcation
A statement with an empty domain complicates the invariant load
  hoisting and does not help any subsequent analysis or transformation.
  In fact it might introduce parameter dimensions or increase the
  schedule dimensionality. To this end, we remove statements with an
  empty domain early in the SCoP simplification.

llvm-svn: 249276
2015-10-04 15:00:05 +00:00
Johannes Doerfert 634909c2c9 [FIX] Domain generation for non-affine loops
llvm-svn: 249275
2015-10-04 14:57:41 +00:00
Johannes Doerfert f61df69423 [FIX] Count affine loops correctly
The "unprofitable" heuristic was broken and counted boxed loops
  even though we do not represent and optimize them.

llvm-svn: 249274
2015-10-04 14:56:08 +00:00
Johannes Doerfert 757a32b5b3 [FIX] Approximate non-affine loops correctly
Before isValidCFG() could hide the fact that a loop is non-affine by
  over-approximation. This is problematic if a subregion of the loop contains
  an exit/latch block and is over-approximated. Now we do not over-approximate
  in the isValidCFG function if we check loop control.  If such control is
  non-affine the whole loop is over-approximated, not only a subregion.

llvm-svn: 249273
2015-10-04 14:54:27 +00:00
Johannes Doerfert 3e7d171866 [FIX] Repair broken commit
The last invariant load fix was based on a later patch not
  polly/master, thus needs to be adjusted.

llvm-svn: 249145
2015-10-02 15:35:03 +00:00
Johannes Doerfert 8930f4846c [FIX] Do not hoist from inside a non-affine subregion
We have to skip accesses in non-affine subregions during hoisting as
  they might not be executed under the same condition as the entry of
  the non-affine subregion.

llvm-svn: 249139
2015-10-02 14:51:00 +00:00
Michael Kruse cac948ef46 Earlier creation of ScopStmt objects
This moves the construction of ScopStmt to the beginning of the 
ScopInfo pass. The late creation was a result of the earlier separation 
of ScopInfo and TempScopInfo. This will avoid introducing more 
ScopStmt-like maps in future commits. The AccFuncMap will also be 
removed in some future commit. DomainMap might also be included into 
ScopStmt.

The order in which ScopStmt are created changes and initially creates 
empty statements that are removed in a simplification.

Differential Revision: http://reviews.llvm.org/D13341

llvm-svn: 249132
2015-10-02 13:53:07 +00:00
Johannes Doerfert 911951f4f8 Hand down referenced & globally mapped values to the subfunction
If a value is globally mapped (IslNodeBuilder::ValueMap) and
  referenced in the code that will be put into a subfunction, we hand
  down the new value to the subfunction.

  This patch also removes code that handed down all invariant loads to
  the subfunction. Instead, only needed invariant loads are given to the
  subfunction. There are two possible reasons for an invariant load to
  be handed down:
    1) The invariant load is used in a block that is placed in the
       subfunction but which is not the parent of the load. In this
       case, the scalar access that will read the loaded value, will
       cause its base pointer (the preloaded value) to be handed down to
       the subfunction.
    2) The invariant load is defined and used in a block that is placed
       in the subfunction. With this patch we will hand down the
       preloaded value to the subfunction as the invariant load is
       globally mapped to that value.

llvm-svn: 249126
2015-10-02 13:11:27 +00:00
Johannes Doerfert f56738041e Make the SCoP generation resistent wrt. error blocks
When error blocks are not terminated by an unreachable they have successors
  that might only be reachable via error blocks. Additionally, branches in
  error blocks are not checked during SCoP detection, thus we might not be able
  to handle them. With this patch we do not try to model error block exit
  conditions. Anything that is only reachable via error blocks is ignored too,
  as it will not be executed in the optimized version of the SCoP anyway.

llvm-svn: 249099
2015-10-01 23:48:18 +00:00
Johannes Doerfert f80f3b0449 Allow user defined error functions
The user can provide function names with
    -polly-error-functions=name1,name2,name3
  that will be treated as error functions. Any call to them is assumed
  not to be executed.

  This feature is mainly for developers to play around with the new
  "error block" feature.

llvm-svn: 249098
2015-10-01 23:45:51 +00:00
Johannes Doerfert 850d346302 [FIX] Parallel codegen for invariant loads
Hand down all preloaded values to the parallel subfunction.

llvm-svn: 249010
2015-10-01 13:40:36 +00:00
Tobias Grosser aff56c8a78 Reapply "BlockGenerator: Generate synthesisable instructions only on-demand"
Instructions which we can synthesis from a SCEV expression are not
generated directly, but only when they are used as an operand of
another instruction. This avoids generating unnecessary instructions
and works more reliably than first inserting them and then deleting
them later on.

This commit was reverted in r248860 due to a remaining miscompile, where
we forgot to synthesis the operand values that were referenced from scalar
writes. test/Isl/CodeGen/scalar-store-from-same-bb.ll tests that we do this
now correctly.

llvm-svn: 248900
2015-09-30 13:36:54 +00:00
Johannes Doerfert ef19ead20e [FIX] Use escape logic for invariant loads
Before we unconditinoally forced all users outside the SCoP to use
  the preloaded value. However, if the SCoP is not executed due to the
  runtime checks, we need to use the original value because it might not
  be invariant in the first place.

llvm-svn: 248881
2015-09-30 09:43:20 +00:00
Johannes Doerfert c1db67e218 Identify and hoist definitively invariant loads
As a first step in the direction of assumed invariant loads (loads
  that are not written in some context) we now detect and hoist
  definitively invariant loads. These invariant loads will be preloaded
  in the code generation and used in the optimized version of the SCoP.
  If the load is only conditionally executed the preloaded version will
  also only be executed under the same condition, hence we will never
  access memory that wouldn't have been accessed otherwise. This is also
  the most distinguishing feature to licm.

  As hoisting can make statements empty we will simplify the SCoP and
  remove empty statements that would otherwise cause artifacts in the
  code generation.

Differential Revision: http://reviews.llvm.org/D13194

llvm-svn: 248861
2015-09-29 23:47:21 +00:00
Johannes Doerfert f6343d74ef Revert "BlockGenerator: Generate synthesisable instructions only on-demand"
This reverts commit 07830c18d789ee72812d5b5b9b4f8ce72ebd4207.

  The commit broke at least one test in lnt,
    MultiSource/Benchmarks/Ptrdist/bc/number.c
  was miss compiled and the test produced a wrong result.

  One Polly test case that was added later was adjusted too.

llvm-svn: 248860
2015-09-29 23:43:40 +00:00
Tobias Grosser 98b3ee50ff Codegen: Support memory accesses with different types
Every once in a while we see code that accesses memory with different types,
e.g. to perform operations on a piece of memory using type 'float', but to copy
data to this memory using type 'int'. Modeled in C, such codes look like:

    void foo(float A[], float B[]) {
      for (long i = 0; i < 100; i++)
        *(int *)(&A[i]) = *(int *)(&B[i]);
      for (long i = 0; i < 100; i++)
        A[i] += 10;
    }

We already used the correct types during normal operations, but fall back to our
detected type as soon as we import changed memory access functions. For these
memory accesses we may generate invalid IR due to a mismatch between the element
type of the array we detect and the actual type used in the memory access.  To
address this issue, we always cast the newly created address of a memory access
back to the type of the memory access where the address will be used.

llvm-svn: 248781
2015-09-29 06:44:38 +00:00
Tobias Grosser 95e59aaa54 OpenMP: Name addresses in subfunction structure
While debugging, this makes it easier to understand due to which memory
reference these stores have been introduced.

llvm-svn: 248717
2015-09-28 16:46:38 +00:00
Tobias Grosser 28b9a14b07 BlockGenerator: Generate synthesisable instructions only on-demand
Instructions which we can synthesis from a SCEV expression are not generated
directly, but only when they are used as an operand of another instruction. This
avoids generating unnecessary instruction and works more reliably than first
inserting them and then deleting them later on.

Suggested-by: Johannes Doerfert <doerfert@cs.uni-saarland.de>

Differential Revision: http://reviews.llvm.org/D13208

llvm-svn: 248712
2015-09-28 13:47:50 +00:00
Johannes Doerfert 9a132f36c3 Allow switch instructions in SCoPs
This patch allows switch instructions with affine conditions in the
  SCoP. Also switch instructions in non-affine subregions are allowed.
  Both did not require much changes to the code, though there was some
  refactoring needed to integrate them without code duplication.

  In the llvm-test suite the number of profitable SCoPs increased from
  135 to 139 but more importantly we can handle more benchmarks and user
  inputs without preprocessing.

Differential Revision: http://reviews.llvm.org/D13200

llvm-svn: 248701
2015-09-28 09:33:22 +00:00
Tobias Grosser f223cdf17e [tests] Add memory writes to make this scop not trivially empty
llvm-svn: 248697
2015-09-28 07:37:06 +00:00
Johannes Doerfert f32f5f2305 Remove obsolete check
This check was needed at some point but seems not useful anymore. Only
  one adjustment in the domain generation was needed to cope with the
  cases this check prevented from happening before.

llvm-svn: 248695
2015-09-28 01:30:37 +00:00
Tobias Grosser 0722a1e5d5 BlockGenerator: Be less agressive with deleting dead instructions
We now only delete trivially dead instructions in the BB we copy (copyBB), but
not in any other BB.  Only for copyBB we know that there will _never_ be any
future uses of instructions that have no use after copyBB has been generated.
Other instructions in the AST that have been generated by IslNodeBuilder may
look dead at the moment, but may possibly still be referenced by GlobalMaps. If
we delete them now, later uses would break surprisingly.

We do not have a test case that breaks due to us deleting too many instructions.
This issue was found by inspection.

llvm-svn: 248688
2015-09-27 19:50:16 +00:00
Tobias Grosser 0ff79e586d BlockGenerator: Simplify code generated for region statements
After having generated a new user statement a couple of inefficient or
trivially dead instructions may remain. This commit runs instruction
simplification over the newly generated blocks to ensure unneeded
instructions are removed right away.

This commit does adds simplification for non-affine subregions which was not
yet part of 248681.

llvm-svn: 248683
2015-09-27 11:35:00 +00:00
Tobias Grosser 412f9774f8 [CodeGen test] Replace undef values with some defined constants
Otherwise, part of the computation will be just simplified away when we add
instruction simplification support to the RegionGenerator.

llvm-svn: 248682
2015-09-27 11:34:53 +00:00
Tobias Grosser 1b9d25a42d BlockGenerator: Simplify code generated for scop statements
After having generated a new user statement a couple of inefficient or trivially
dead instructions may remain. This commit runs instruction simplification over
the newly generated blocks to ensure unneeded instructions are removed right
away.

This commit does not yet add simplification for non-affine subregions.

llvm-svn: 248681
2015-09-27 11:17:22 +00:00
Johannes Doerfert fb19dd694c Create parallel code in a separate block
This commit basically reverts r246427 but still solves the issue
  tackled by that commit. Instead of emitting initialization code in the
  beginning of the start block we now generate parallel code in its own
  block and thereby guarantee separation. This is necessary as we cannot
  generate code for hoisted loads prior to the start block but it still
  needs to be placed prior to everything else.

llvm-svn: 248674
2015-09-26 20:57:59 +00:00
Tobias Grosser 06c495c2b0 Add test case from llvm.org/PR17187
The new domain construction algorithm now correctly models this test case (and
derives an empty run-time condition). Add this test case to ensure we do not
regress.

llvm-svn: 248669
2015-09-26 14:27:54 +00:00
Johannes Doerfert 12155a9ef4 Add test case from open bug
The bug (15771) was fixed already with the new domain generation
  but the test case was not added till now.

llvm-svn: 248668
2015-09-26 14:03:29 +00:00
Johannes Doerfert c6987c18de [FIX] Use the surrounding loop for non-affine SCoP regions
When the whole SCoP is a non-affine region we need to use the
  surrounding loop in the construction of the schedule as that is
  the one that will be looked up after the schedule generation.

  This fixes bug 24947

llvm-svn: 248667
2015-09-26 13:41:43 +00:00
Tobias Grosser bbda083c75 Add test case for delinearization through bitcasts
This was forgotten in r247928

llvm-svn: 248663
2015-09-26 08:55:59 +00:00
Tobias Grosser 99c70dd8d1 Ensure memory accesses to the same array have identical dimensionality
When recovering multi-dimensional memory accesses, it may happen that different
accesses to the same base array are recovered with different dimensionality.
This patch ensures that the dimensionalities are unified by adding zero valued
dimensions to acesses with lower dimensionality. When starting to model
fixed-size arrays as multi-dimensional in 247906, this has not been taken
care of.

llvm-svn: 248662
2015-09-26 08:55:54 +00:00
Tobias Grosser 8016f3a4f5 Add missing PHI to test case
llvm-svn: 248563
2015-09-25 05:41:30 +00:00
Tobias Grosser da95a4a7c7 Handle read-only scalars used in PHI-nodes correctly
This change addresses three issues:

  - Read only scalars that enter a PHI node through an edge that comes from
    outside the scop are not modeled any more, as such PHI nodes will always
    be initialized to this initial value right before the SCoP is entered.
  - For PHI nodes that depend on a scalar value that is defined outside the
    scop, but where the scalar values is passed through an edge that itself
    comes from a BB that is part of the region, we introduce in this basic
    block a read of the out-of-scop value to ensure it's value is available
    to write it into the PHI alloc location.
  - Read only uses of scalars by PHI nodes are ignored in the general read only
    handling code, as they are taken care of by the general PHI node modeling
    code.

llvm-svn: 248535
2015-09-24 20:59:59 +00:00
Michael Kruse 2d0ece960f Remove Analysis Output of TempScopInfo
After the merge of TempScopInfo into ScopInfo the analysis output 
remained because of the existing unit tests. These remains are removed 
and the units tests converted to match the equivalent output of 
ScopInfo's analysis output. The unit tests are also moved into the
directory of ScopInfo tests.

Differential Revision: http://reviews.llvm.org/D13116

llvm-svn: 248485
2015-09-24 11:41:21 +00:00
Tobias Grosser b1c39429d9 Do not model delinearized and linearized access relation for a single access
A missing return statement that previously did not have a visibly negative
effect caused after some data-structure changes in r248024 multi-dimensional
accesses to be modeled both multi-dimensional as well as linearized. This
commit adds the missing return to avoid the incorrect double modeling as
well as the compile time increases it caused.

llvm-svn: 248171
2015-09-21 16:19:25 +00:00
Johannes Doerfert 6a72a2af13 Use <nsw> AddRecs in the affinator to avoid bounded assumptions
If we encounter a <nsw> tagged AddRec for a loop we know the trip count of
  that loop has to be bounded or the semantics is undefined anyway. Hence, we
  only need to add unbounded assumptions if no such AddRec is known.

llvm-svn: 248128
2015-09-20 16:59:23 +00:00
Johannes Doerfert 707a406078 Add bounded loop assumption
So far we ignored the unbounded parts of the iteration domain, however
  we need to assume they do not occure at all to remain sound if they do.

llvm-svn: 248126
2015-09-20 16:38:19 +00:00
Johannes Doerfert f2cc86edae Simplify domain generation
We now add loop carried information during the second traversal of the
  region instead of in a intermediate step in-between. This makes the
  generation simpler, removes code and should even be faster.

llvm-svn: 248125
2015-09-20 16:15:32 +00:00
Johannes Doerfert 0c1123a831 [FIX] Repair test case that was unprofitable
llvm-svn: 248124
2015-09-20 16:14:41 +00:00
Johannes Doerfert 06c57b594c Allow loops with multiple back edges
In order to allow multiple back edges we:
    - compute the conditions under which each back edge is taken
    - build the union over all these conditions, thus the condition that
      any back edge is taken
    - apply the same logic to the union we applied to a single back edge

llvm-svn: 248120
2015-09-20 15:00:20 +00:00
Johannes Doerfert 7175bdfbe4 Add loop trip count based heuristic for SCoP detection
As we currently do not perform any optimizations that targets (or is
  even aware) small trip counts we will skip them when we count the
  loops in a region.

llvm-svn: 248119
2015-09-20 14:56:54 +00:00
Michael Kruse e2bccbbfb2 Merge IRAccess into MemoryAccess
All MemoryAccess objects will be owned by ScopInfo::AccFuncMap which 
previously stored the IRAccess objects. Instead of creating new 
MemoryAccess objects, the already created ones are reused, but their 
order might be different now. Some fields of IRAccess and MemoryAccess 
had the same meaning and are merged.

This is the last step of fusioning TempScopInfo.{h|cpp} and 
ScopInfo.{h.cpp}. Some refactoring might still make sense.

Differential Revision: http://reviews.llvm.org/D12843

llvm-svn: 248024
2015-09-18 19:59:43 +00:00
Tobias Grosser 5fd8c0961e Model fixed-size multi-dimensional arrays if possible multi-dimensional
If the GEP instructions give us enough insights, model scalar accesses as
multi-dimensional (and generate the relevant run-time checks to ensure
correctness). This will allow us to simplify the dependence computation in
a subsequent commit.

llvm-svn: 247906
2015-09-17 17:28:15 +00:00
Johannes Doerfert 883f8c1d2f Use modulo semantic to generate non-integer-overflow assumptions
This will allow to generate non-wrap assumptions for integer expressions
  that are part of the SCoP. We compare the common isl representation of
  the expression with one computed with modulo semantic. For all parameter
  combinations they are not equal we can have integer overflows.

  The nsw flags are respected when the modulo representation is computed,
  nuw and nw flags are ignored for now.

  In order to not increase compile time to much, the non-wrap assumptions
  are collected in a separate boundary context instead of the assumed
  context. This helps compile time as the boundary context can become
  complex and it is therefor not advised to use it in other operations
  except runtime check generation. However, the assumed context is e.g.,
  used to tighten dependences. While the boundary context might help to
  tighten the assumed context it is doubtful that it will help in practice
  (it does not effect lnt much) as the boundary (or no-wrap assumptions)
  only restrict the very end of the possible value range of parameters.

  PET uses a different approach to compute the no-wrap context, though lnt runs
  have shown that this version performs slightly better for us.

llvm-svn: 247732
2015-09-15 22:52:53 +00:00
Michael Kruse da8d6203f4 Fix after renamed CMake cache entry
LLVM_EXTERNAL_CLANG_BUILD was changed to LLVM_TOOL_CLANG_BUILD in
r242059.

llvm-svn: 247675
2015-09-15 10:51:15 +00:00
Michael Kruse fa62b1763c Run polly-check-format with unit tests
Add polly-check-format as dependency of check-polly if clang-format is 
available in the same build.

Differential Revision: http://reviews.llvm.org/D12850

llvm-svn: 247600
2015-09-14 19:11:48 +00:00
Tobias Grosser aaadc5302c [test] Load Polly before using the polly flags
llvm-svn: 247551
2015-09-14 11:49:05 +00:00
Johannes Doerfert 334f9e87c6 [FIX] XFAIL test that depends on pending LLVM commit
llvm-svn: 247550
2015-09-14 11:45:34 +00:00
Johannes Doerfert e114dc024e [FIX] Handle error blocks in non-affine regions correctly
llvm-svn: 247545
2015-09-14 11:15:58 +00:00
Johannes Doerfert 40fa56f59f [FIX] Allow the whole SCoP to be a non-affine subregion
llvm-svn: 247544
2015-09-14 11:15:07 +00:00
Johannes Doerfert 36255eecd8 Revert r247278 "Disable support for modulo expressions"
This reverts commit 00c5b6ca8832439193036aadaaaee92a43236219.

  We can handle modulo expressions in the domain again.

llvm-svn: 247542
2015-09-14 11:14:23 +00:00
Johannes Doerfert ca1e38fa43 Propagate exit conditions as described in the PET paper
At some point we build loop trip counts using this method. It was replaced by
  a simpler trick that works only for affine (e.g., not modulo) constraints and
  relies on the removal of unbounded parts. In order to allow modulo constrains
  again we go back to the former, more accurate method.

llvm-svn: 247540
2015-09-14 11:12:52 +00:00
Michael Kruse 07d5df4db8 Fix out-of-range access in test case
The function use_after_scop would iterate from 0 to 1024 and accessing element A[1024] where A has only valid indexes from 0 to 1023. Polly detects the situation of unconditionally undefined behavior and bail out in ScopInfo as non-feasible for optimization.

Other tests add impossible context assumptions as well, hance might show the same problem.

llvm-svn: 247412
2015-09-11 13:45:05 +00:00
David Blaikie 0afc1e4ecc Update polly for explicit type parameter to global alias change
llvm-svn: 247382
2015-09-11 03:42:32 +00:00
Tobias Grosser 34b11fc197 XFAIL tests that require an additional LLVM patch to work
llvm-svn: 247338
2015-09-10 21:32:29 +00:00
Johannes Doerfert 90db75ed24 Runtime error check elimination
Hoist runtime checks in the loop nest if they guard an "error" like event.
  Such events are recognized as blocks with an unreachable terminator or a call
  to the ubsan function that deals with out of bound accesses. Other "error"
  events can be added easily.

  We will ignore these blocks when we detect/model/optmize and code generate SCoPs
  but we will make sure that they would not have been executed using the assumption
  framework.

llvm-svn: 247310
2015-09-10 17:51:27 +00:00
Johannes Doerfert f4fa9879fb [FIX] Do not assume only one loop can be left at a time
llvm-svn: 247291
2015-09-10 15:53:59 +00:00
Johannes Doerfert b68cffb5df Allow general loops with one latch
As we do not rely on ScalarEvolution any more we do not need to get
  the backedge taken count. Additionally, our domain generation handles
  everything that is affine and has one latch and our ScopDetection will
  over-approximate everything else.

  This change will therefor allow loops with:
    - one latch
    - exiting conditions that are affine

  Additionally, it will not check for structured control flow anymore.
  Hence, loops and conditionals are not necessarily single entry single
  exit regions any more.

Differential Version: http://reviews.llvm.org/D12758

llvm-svn: 247289
2015-09-10 15:27:46 +00:00
Michael Kruse d868b5d509 Merge TempScopInfo into ScopInfo
The TempScopInfo (-polly-analyze-ir) pass is removed and its work taken
over by ScopInfo (-polly-scops). Several tests depend on
-polly-analyze-ir and use -polly-scops instead which for the moment
prints the output of both passes. This again is not expected by some
other tests, especially those with negative searches, which have been
adapted.

Differential Version: http://reviews.llvm.org/D12694

llvm-svn: 247288
2015-09-10 15:25:24 +00:00
Michael Kruse 9cc1b9d31e Clean-up unit tests
Remove redundant flags and duplicate invocations of the same test.

llvm-svn: 247285
2015-09-10 14:42:09 +00:00
Johannes Doerfert 5b9ff8b667 Replace ScalarEvolution based domain generation
This patch replaces the last legacy part of the domain generation, namely the
ScalarEvolution part that was used to obtain loop bounds. We now iterate over
the loops in the region and propagate the back edge condition to the header
blocks. Afterwards we propagate the new information once through the whole
region. In this process we simply ignore unbounded parts of the domain and
thereby assume the absence of infinite loops.

  + This patch already identified a couple of broken unit tests we had for
    years.
  + We allow more loops already and the step to multiple exit and multiple back
    edges is minimal.
  + It allows to model the overflow checks properly as we actually visit
    every block in the SCoP and know where which condition is evaluated.
  - It is currently not compatible with modulo constraints in the
    domain.

Differential Revision: http://reviews.llvm.org/D12499

llvm-svn: 247279
2015-09-10 13:00:06 +00:00
Johannes Doerfert 171f07ed71 Disable support for modulo expressions
The support for modulo expressions is not comlete and makes the new
  domain generation harder. As the currently broken domain generation
  needs to be replaced, we will first swap in the new, fixed domain
  generation and make it compatible with the modulo expressions later.

llvm-svn: 247278
2015-09-10 12:56:46 +00:00
Chandler Carruth 66ef16b289 [PM] Update Polly for the new AA infrastructure landed in r247167.
llvm-svn: 247198
2015-09-09 22:13:56 +00:00
Johannes Doerfert 7ca8dc2d2d Disable support for pointer expressions
The support for pointer expressions is broken as it can only handle
  some patterns in the IslExprBuilder. We should to treat pointers in
  expressions the same as integers at some point and revert this patch.

llvm-svn: 247147
2015-09-09 14:19:04 +00:00
Johannes Doerfert 717b866798 Allow PHI nodes in the region exit block
While we do not need to model PHI nodes in the region exit (as it is not part
  of the SCoP), we need to prepare for the case that the exit block is split in
  code generation to create a single exiting block. If this will happen, hence
  if the region did not have a single exiting block before, we will model the
  operands of the PHI nodes as escaping scalars in the SCoP.

Differential Revision: http://reviews.llvm.org/D12051

llvm-svn: 247078
2015-09-08 21:44:27 +00:00
Tobias Grosser 02e6589bda Move more compile-time bailouts into -polly-detect-unprofitable
Instead of having two separate options
-polly-detect-scops-in-functions-without-loops and
-polly-detect-scops-in-regions-without-loops we now just use
-polly-detect-unprofitable to force the detection of scops ignoring any compile
time saving bailout heuristics.

llvm-svn: 247057
2015-09-08 19:46:41 +00:00
Tobias Grosser b8f3690e15 Add first run-time bounds elimination test case
llvm-svn: 247020
2015-09-08 16:02:19 +00:00
Tobias Grosser a89dc57b41 Do not use '.' in subfunction names
Certain backends, e.g. NVPTX, do not support '.' in function names. Hence,
we ensure all '.' are replaced by '_' when generating function names for
subfunctions. For the current OpenMP code generation, this is not strictly
necessary, but future uses cases (e.g. GPU offloading) need this issue to be
fixed.

llvm-svn: 246980
2015-09-08 06:22:17 +00:00
Tobias Grosser 12e650d682 Drop alias metadata in checks of RuntimeDebugBuilder test
Our alias metadata is currently not emitted in a deterministic order. As it
is not needed in this test, we just drop it for now (but keep in mind to fix
this).

llvm-svn: 246942
2015-09-06 08:59:50 +00:00
Tobias Grosser 86bc93a9b2 Add option -polly-codegen-add-debug-printing
When this option is enabled, Polly will emit printf calls for each scalar
load/and store which dump the scalar value loaded/stored at run time.

This patch also refactors the RuntimeDebugBuilder to use variadic templates
when generating CPU printfs. As result, it now becomes easier to print
strings that consist of a set of arguments. Also, as a single printf
call is emitted, it is more likely for such strings to be emitted atomically
if executed multi-threaded.

llvm-svn: 246941
2015-09-06 08:47:57 +00:00
Tobias Grosser 113a4a4cbb Add forgotten .jscop file
llvm-svn: 246925
2015-09-05 10:58:13 +00:00
Tobias Grosser 72b80672d9 OpenMP: Name the values passed to the subfunciton according to the original llvm::Values
llvm-svn: 246924
2015-09-05 10:41:19 +00:00
Tobias Grosser 0d8874c0f6 OpenMP codegen: support generation of multi-dimensional access functions
When computing the index expressions for new, multi-dimensional memory accesses
these new index expressions may reference original llvm::Values that are not
transfered into the OpenMP subfunction. Using GlobalMap we now replace
references to such values with the rewritten values that have e.g. been passed
to the OpenMP subfunction.

llvm-svn: 246923
2015-09-05 10:32:56 +00:00
Tobias Grosser 6f73008506 Allow the import of multi-dimensional access functions
Originally, we disallowed the import of multi-dimensional access functions due
to our code generation not supporting the generation of new address expressions
for multi-dimensional memory accesses. When building our run-time alias check
infrastructure we added code generation support for multi-dimensional address
calculations.  Hence, we can now savely allow the import of new
multi-dimensional access functions.

llvm-svn: 246917
2015-09-05 07:46:47 +00:00
Tobias Grosser 1dcfb7a1e6 ScopInfo: Add test case for two loops following right after each other
This case probably does not happen for LLVM generated code that is in loop
simplify form, but Polly does support such kind of loops. This commit ensures we
have test coverage as well.

llvm-svn: 246543
2015-09-01 11:33:13 +00:00
Tobias Grosser 40820ca286 Fix another typo in the subloop counting
... as well as the corresponding test cases.

Thank's Johannes for finding this bug.

llvm-svn: 246483
2015-08-31 21:04:51 +00:00
Johannes Doerfert 5f912d3797 Do Not Model Unbounded Loops
Code generation currently does not expect unbounded loops. When
  using ISL to compute the loop trip count, if we find that the
  iteration domain remains unbounded, we invalidate the Scop by
  creating an infeasible context.

Contributed-by: Matthew Simpson <mssimpso@codeaurora.org>

This fixes PR24634.

Differential Revision: http://reviews.llvm.org/D12493

llvm-svn: 246477
2015-08-31 19:58:24 +00:00
Tobias Grosser d213d52d0e Always use the branch instructions to model the PHI-node writes
Before this commit we did this only for Arguments or Constants, but indeed
an instruction may define a value a lot higher up in the dominance tree, but
the actual write generally needs to happen right before branching to the
PHI node. Otherwise, the writes of different branches into PHI nodes may get
intermixed if they lay higher up in the dominance tree.

llvm-svn: 246441
2015-08-31 13:45:54 +00:00
Tobias Grosser 050e0cbc0e ScopDetection: Correctly count the loops in a region
There is no reason the loops in a region need to touch either entry or exit
block. Hence, we need to look through all loops that may touch the region as
well as their children to understand if our region has at least two loops.

llvm-svn: 246433
2015-08-31 12:08:11 +00:00
Tobias Grosser 44b34b0e8a Also build scalar dependences for store instructions
While ignoring read-only scalar dependences it was not necessary to consider
store instructins, but as store instructions can be the target of a scalar
read-only dependency we need to consider them for the construction of scalar
read-only dependences.

llvm-svn: 246429
2015-08-31 11:15:00 +00:00
Tobias Grosser 9f3d55cf3d Generate scalar initialization loads at the beginning of the start BB
Our OpenMP code generation generated part of its launching code directly into
the start basic block and without this change the scalar initialization was
run _after_ the OpenMP threads have been launched. This resulted in
uninitialized scalar values to be used.

llvm-svn: 246427
2015-08-31 11:06:19 +00:00
Tobias Grosser f93451802a OpenMP-codegen: Correctly pass function arguments to subfunctions
Before we only checked if certain instructions can be expanded by us. Now we
check any value, including function arguments.

llvm-svn: 246425
2015-08-31 09:05:43 +00:00
Tobias Grosser d86bf4271c Do not model scalar references to constant values
llvm-svn: 246418
2015-08-31 06:37:25 +00:00
Johannes Doerfert 96425c2574 Traverse the SCoP to compute non-loop-carried domain conditions
In order to compute domain conditions for conditionals we will now
  traverse the region in the ScopInfo once and build the domains for
  each block in the region. The SCoP statements can then use these
  constraints when they build their domain.

  The reason behind this change is twofold:
    1) This removes a big chunk of preprocessing logic from the
       TempScopInfo, namely the Conditionals we used to build there.
       Additionally to moving this logic it is also simplified. Instead
       of walking the dominance tree up for each basic block in the
       region (as we did before), we now traverse the region only
       once in order to collect the domain conditions.
    2) This is the first step towards the isl based domain creation.
       The second step will traverse the region similar to this step,
       however it will propagate back edge conditions. Once both are in
       place this conditional handling will allow multiple exit loops
       additional logic.

Reviewers: grosser

Differential Revision: http://reviews.llvm.org/D12428

llvm-svn: 246398
2015-08-30 21:13:53 +00:00
Tobias Grosser c0091a77f9 Store scalar dependences from outside the scop into alloca locations
We already modeled read-only dependences to scalar values defined outside the
scop as memory reads and also generated read accesses from the corresponding
alloca instructions that have been used to pass these scalar values around
during code generation. However, besides for PHI nodes that have already been
handled, we failed to store the orignal read-only scalar values into these
alloc. This commit extends the initialization of scalar values to all read-only
scalar values used within the scop.

llvm-svn: 246394
2015-08-30 19:19:34 +00:00
Tobias Grosser e83a396b1d Ignore debug intrinsics and do not model their potential scalar metadata reads
Our code generation currently does not support scalar references to metadata
values. Hence, it would crash if we try to model scalar dependences to metadata
values. Fortunately, for one of the common uses, debug information, we can
for now just ignore the relevant intrinsics and consequently the issue of how
to model scalar dependences to metadata.

llvm-svn: 246388
2015-08-30 16:57:20 +00:00
Tobias Grosser 51b65d9370 Drop alias tags from vector test case
They are not really part of what is tested here.

llvm-svn: 246382
2015-08-30 14:06:30 +00:00
Duncan P. N. Exon Smith adbcf12029 DI: Fix testcases after LLVM r246327
I ran the script from r246327 and it touched all the right files;
committing now to hopefully right the bots, but if my check-polly
doesn't come back clean I'll keep looking.

http://lab.llvm.org:8011/builders/polly-amd64-linux/builds/33648

llvm-svn: 246341
2015-08-28 22:01:49 +00:00
Tobias Grosser ed21a1fc7e Do not detect Scops with only one loop.
If a region does not have more than one loop, we do not identify it as
a Scop in ScopDetection. The main optimizations Polly is currently performing
(tiling, preparation for outer-loop vectorization and loop fusion) are unlikely
to have a positive impact on individual loops. In some cases, Polly's run-time
alias checks or conditional hoisting may still have a positive impact, but those
are mostly enabling transformations which LLVM already performs for individual
loops. As we do not focus on individual loops, we leave them untouched to not
introduce compile time regressions and execution time noise. This results in
good compile time reduction (oourafft: -73.99%, smg2000: -56.25%).

Contributed-by: Pratik Bhatu <cs12b1010@iith.ac.in>

Reviewers: grosser

Differential Revision: http://reviews.llvm.org/D12268

llvm-svn: 246161
2015-08-27 16:55:18 +00:00
Johannes Doerfert d020b77295 Use ISL to Determine Loop Trip Count
Use ISL to compute the loop trip count when scalar evolution is unable to do
  so.

Contributed-by: Matthew Simpson <mssimpso@codeaurora.org>

Differential Revision: http://reviews.llvm.org/D9444

llvm-svn: 246142
2015-08-27 06:53:52 +00:00
Tobias Grosser 01c8f5f354 [Vectorizer] Detect strides in multi-dimensional arrays
The original code was only correct for one-dimensional arrays, but derived
incorrect strides for multi-dimensional arrays.

llvm-svn: 245888
2015-08-24 22:20:46 +00:00
Tobias Grosser 39f9f30e8b Only derive number of loop iterations for loops we can actually vectorize
llvm-svn: 245870
2015-08-24 20:11:34 +00:00
Tobias Grosser 1ac884d73a Use marker nodes to annotate the different levels of tiling
Currently, marker nodes are ignored during AST generation, but visible in the
-debug-only=polly-ast output.

llvm-svn: 245809
2015-08-23 09:11:00 +00:00
Roman Gareev c49724f008 Manually check a loop form
Add manual check of a loop form and return non-negative number of iterations
in case of trivially vectorizable loop.

llvm-svn: 245680
2015-08-21 09:08:14 +00:00
Tobias Grosser fc490a99f5 Do really not unroll the vector loop in combination with register tiling
The previous commit lacked a test case for register tiling + pre-vectorization
and we obviously got it immediately wrong.

llvm-svn: 245599
2015-08-20 19:08:16 +00:00
Tobias Grosser d83b8a83ec Add option to control reduction detection
llvm-svn: 245598
2015-08-20 19:08:11 +00:00
Johannes Doerfert 5d5b30649a Check feasibility for the runtime check context wrt. the domain.
If nothing is executed we can bail out early. Otherwise we can use the
  constraints that ensure at least one statement is executed for
  simplification.

llvm-svn: 245585
2015-08-20 18:06:30 +00:00
Johannes Doerfert 4eed5bea54 Link ScopArrayInfo objects
We will record if a SAI is the base of another SAI or derived from it.
  This will allow to reason about indirect base pointers later on and
  allows a clearer picture of indirection also in the SCoP dump.

llvm-svn: 245584
2015-08-20 18:04:22 +00:00
Tobias Grosser 42e2489553 Add experimental support for trivial register tiling
Register tiling in Polly is for now just an additional level of tiling which
is fully unrolled. It is disabled by default. To make this useful for more than
experiments, we still need a cost function as well as possibly further
optimizations that teach LLVM to actually put some of the values we got into
scalar registers.

llvm-svn: 245564
2015-08-20 13:45:05 +00:00
Tobias Grosser 0483271662 Add support for two-level tiling
By default we only use one level of tiling for loops, but in general tiling
for multiple levels is trivial for us. Hence, we add a set of options that
allow people to play with a second level of tiling. If this is profitable for
some cases we can work on heuristics that allow us to identify these cases
and use two-level tiling for them.

llvm-svn: 245563
2015-08-20 13:45:02 +00:00
Johannes Doerfert 43788c5783 Check for feasible runtime check context early
Instead of generating code for an empty assumed context we bail out
  early. As the number of assumptions we generate increases this becomes
  more and more important. Additionally, this change will allow us to
  hide internal contexts that are only used in runtime checks e.g., a
  boundary context with constraints not suited for simplifications.

llvm-svn: 245540
2015-08-20 05:58:56 +00:00
Tobias Grosser b0da42fb55 Generate alias metadata even in OpenMP mode
To make alias scope metadata generation work in OpenMP mode we now provide
the ScopAnnotator with information about the base pointer rewrite that happens
when passing arrays into the OpenMP subfunction.

llvm-svn: 245451
2015-08-19 16:04:35 +00:00
Tobias Grosser 07c1c2fcc9 Make prevectorization width configurable
Polly uses 'prevectorization' to enable outer loop vectorization. When
vectorizing an outer loop, we strip-mine <number-of-prevec-dims> loop
iterations which are than interchanged to the innermost level such that LLVM's
inner loop vectorizer (or Polly's simple vectorizer) can easily vectorize this
loop. The number of loop iterations to strip-mine is now configurable with the
option -polly-prevect-width=<number-of-prevec-dims>.

This is mostly a debugging option. We should probably add a heuristic that
derives the number of prevectorization dimensions from the target data and
the data types used.

llvm-svn: 245424
2015-08-19 08:46:11 +00:00
Tobias Grosser 161c9081e5 Do not use negative option name
Instead of -polly-no-tiling, we use -polly-tiling=false to disable tiling.

llvm-svn: 245423
2015-08-19 08:22:06 +00:00
Michael Kruse d568a3e20d Update test case multidim_indirect_access.ll
This test was written to check the workings of IndependentBlocks on
arrays which doesn't do such transformations anymore. The test itself
is still useful to check that the region is rejected as SCoP.  

llvm-svn: 245353
2015-08-18 21:08:41 +00:00
Roman Gareev f2bd72e00d Use isl_set_is_subset instead of isl_set_is_equal
It helps to detect correct strides in case of parametric constraints of Stride
in MemoryAccess::isStrideX.

Reviewers: grosser
llvm-svn: 245303
2015-08-18 16:12:05 +00:00
Tobias Grosser c0f8452592 Fix test cases which fail due to changes in isl's set representation
llvm-svn: 245301
2015-08-18 15:28:02 +00:00
Roman Gareev 079968e4cf test commit revert
test commit revert

llvm-svn: 245299
2015-08-18 14:56:50 +00:00
Roman Gareev 6753df4bb6 test commit
test commit

llvm-svn: 245298
2015-08-18 14:54:27 +00:00
Michael Kruse d2b0360197 Fix Codegen adding a second exit out of region
executeScopConditionally would destroy a predecessor region if it the
scop's entry was the region's exit block by forking it to polly.start
and thus creating a secnd exit out of the region. This patch "shrinks"
the predecessor region s.t. polly.split_new_and_old is not the 
region's exit anymore. 

llvm-svn: 245294
2015-08-18 13:14:42 +00:00
Johannes Doerfert e69e1141d9 Introduce the ScopExpander as a SCEVExpander replacement
The SCEVExpander cannot deal with all SCEVs Polly allows in all kinds
  of expressions. To this end we introduce a ScopExpander that handles
  the additional expressions separatly and falls back to the
  SCEVExpander for everything else.

Reviewers: grosser, Meinersbur

Subscribers: #polly

Differential Revision: http://reviews.llvm.org/D12066

llvm-svn: 245288
2015-08-18 11:56:00 +00:00
Johannes Doerfert e1fa6da356 [FIX] Create location if a needed value was not yet demoted
This allows the code generation to continue working even if a needed
  value (that is reloaded anyway) was not yet demoted. Instead of
  failing it will now create the location for future demotion to memory
  and load from that location. The stores will use the same location and
  by construction execute before the load even if the textual order in
  the generated AST is otherwise.

Reviewers: grosser, Meinersbur

Subscribers: #polly

Differential Revision: http://reviews.llvm.org/D12072

llvm-svn: 245203
2015-08-17 09:38:46 +00:00
Tobias Grosser 3278b7cd7c Add 2nd test case for sdiv/srem instructions in a SCEV
llvm-svn: 245186
2015-08-16 19:53:21 +00:00
Johannes Doerfert eca5282dd0 [FIX] Add XFAIL to crashing test case
llvm-svn: 245180
2015-08-16 14:54:16 +00:00
Johannes Doerfert 45545ff782 Build the ScopStmt domain in-place.
This will build the statement domains in-place, hence using the
  ScopStmt::Domain member instead of some intermediate isl_set.

llvm-svn: 245179
2015-08-16 14:36:01 +00:00
Johannes Doerfert c594dc9ed0 Add a crashing test case for the scalar code generation
This test case crashes the scalar code generation as we are not
  consistent with the usage of the assumed context. To be precise, we
  use the assumed context for the dependence analysis but not to
  restrict the domains of the statements.

  A step by step explanation of the problem is given in the test case.

llvm-svn: 245176
2015-08-16 11:12:22 +00:00
Tobias Grosser 8a9c2353f9 Add -polly-context option to provide additional context information
This option allows the user to provide additional information about parameter
values as an isl_set. To specify that N has the value 1024, we can provide
the context -polly-context='[N] -> {: N = 1024}'.

llvm-svn: 245175
2015-08-16 10:19:29 +00:00
Tobias Grosser bccd1b0af0 Fix test case after recent LLVM changes
llvm-svn: 244954
2015-08-13 21:08:15 +00:00
Tobias Grosser 7e584168ab Manuallt simplify test case
llvm-svn: 244907
2015-08-13 16:33:32 +00:00
Michael Kruse 2da3872a99 Add test case for SCEV synthesizing
CodeGenerator currently tries to generate code for a parameter using
values values that are computed later.

llvm-svn: 244903
2015-08-13 15:53:53 +00:00
Tobias Grosser 0164b8ff70 Enable code generation of scalar dependences from function arguments
This change extends the BlockGenerator to not only allow Instructions as
base elements of scalar dependences, but any llvm::Value. This allows
us to code-generate scalar dependences which reference function arguments, as
they arise when moddeling read-only scalar dependences.

llvm-svn: 244874
2015-08-13 08:07:39 +00:00
Tobias Grosser d46fd5ed95 Make the dimension sizes of in ScopArrayInfo available as isl_pw_affs
This makes it easier to reason about the size of an array dimension with isl.

llvm-svn: 244757
2015-08-12 15:27:16 +00:00
Tobias Grosser a77cea49d1 Always model PHI nodes in scop (if not in same nonaffine subregion)
Before we only modeled PHI nodes if at least one incoming basic block was itself
part of the region, now we always model them except if all of their operands are
part of a single non-affine subregion which we model as a black-box.

This change only affects PHI nodes in the entry block, that have exactly one
incoming edge. Before this change, we did not model them and as a result code
generation would not know how to code generate them. With this change, code
generation can code generate them like any other PHI node.

This issue was exposed by r244606. Before this change simplifyRegion would have
moved these PHI nodes out of the SCoP, so we would never have tried to code
generate them. We could implement this behavior again, but changing the IR
after the scop has been modeled and transformed always adds a risk of us
invalidating earlier analysis results. It seems more save and overall also more
consistent to just model and handle this one-entry-edge PHI nodes like any
other PHI node in the scop.

Solution proposed by:  Michael Kruse  <llvm@meinersbur.de>

llvm-svn: 244721
2015-08-12 07:48:54 +00:00
Michael Kruse fba24b3775 Add another test case with trival PHI in entry BB
This one was extracted from the test-suite's pifft and caused a
miscompilation because a scalar was not written to its alloca address.

llvm-svn: 244720
2015-08-12 07:34:55 +00:00
Michael Kruse 4f9caf2b28 Add test case for entry node with trivial PHI
This is a break-down from the test-suite's oggenc where Polly currently
crashes. 

llvm-svn: 244692
2015-08-11 23:09:19 +00:00
Michael Kruse 22370884c4 Revise the simplification of regions
The previous code had several problems:

For newly created BasicBlocks it did not (always) call RegionInfo::setRegionFor in order to update its analysis. At the moment RegionInfo does not verify its BBMap, but will in the future. This is fixed by determining the region new BBs belong to and set it accordingly. The new executeScopConditionally() requires accurate getRegionFor information. 

Which block is created by SplitEdge depends on the incoming and outgoing edges of the blocks it connects, which makes handling its output more difficult than it needs to be. Especially for finding which block has been created an to assign a region to it for the setRegionFor problem above. This patch uses an implementation for splitEdge that always creates a block between the predecessor and successor. simplifyRegion has also been simplified by using SplitBlockPredecessors instead of SplitEdge. Isolating the entries and exits have been refectored into individual functions.

Previously simplifyRegion did more than just ensuring that there is only one entering and one exiting edge. It ensured that the entering block had no other outgoing edge which was necessary for executeScopConditionally(). Now the latter uses the alternative splitEdge implementation which can handle this situation so simplifyRegion really only needs to simplify the region.

Also, executeScopConditionally assumed that there can be no PHI nodes in blocks with one incoming edge. This is wrong and LCSSA deliberately produces such edges. However, previous passes ensured that there can be no such PHIs in exit nodes, but which will no longer hold in the future.

The new code that the property that it preserves the identity of region block (the property that the memory address of the BasicBlock containing the instructions remains the same; new blocks only contain PHI nodes and a terminator), especially the entry block. As a result, there is no need to update the reference to the BasicBlock of ScopStmt that contain its instructions because they have been moved to other basic blocks.

Reviewers: grosser

Part of Differential Revision: http://reviews.llvm.org/D11867 

llvm-svn: 244606
2015-08-11 14:39:21 +00:00
Tobias Grosser 6e3ba33b07 Update isl to isl-0.15-117-ge42acfe
Besides other changes this version of isl contains a fundamental fix to memory
corruption issues we have seen with imath-32 backed isl_ints.

This update also contains a fix that ensures that the schedule-tree based
version of isl's dependence analysis takes the domain of the schedule into
account.

llvm-svn: 244585
2015-08-11 11:31:18 +00:00
Michael Kruse 874b5c2197 Correct non-existing past participle of split in filename
llvm-svn: 244478
2015-08-10 18:37:34 +00:00
Michael Kruse 4adb0279a8 Add test case with PHI node in exit block
The PHI node with multiple incoming edges from inside the region.

Thanks Tobias for coming up with the example. 

llvm-svn: 244456
2015-08-10 16:17:59 +00:00
Tobias Grosser dcc3b435ab Optionally model read-only scalars
Even though read-only accesses to scalars outside of a scop do not need to be
modeled to derive valid transformations or to generate valid sequential code,
but information about them is useful when we considering memory footprint
analysis and/or kernel offloading.

llvm-svn: 243981
2015-08-04 13:54:20 +00:00
Duncan P. N. Exon Smith 20b50f2b2a Update testcases after LLVM r243885
llvm-svn: 243887
2015-08-03 17:28:43 +00:00
Tobias Grosser 6213913244 Use the branch instruction to define the location of a PHI-node write
We use the branch instruction as the location at which a PHI-node write takes
place, instead of the PHI-node itself. This allows us to identify the
basic-block in a region statement which is on the incoming edge of the PHI-node
and for which the write access was originally introduced. As a result we can,
during code generation, avoid generating PHI-node write accesses for basic
blocks that do not preceed the PHI node without having to look at the IR
again.

This change fixes a bug which was introduced in r243420, when we started to
explicitly model PHI-node reads and writes, but dropped some additional checks
that where still necessary during code generation to not emit PHI-node writes
for basic-blocks that are not on incoming edges of the original PHI node.
Compared to the code before r243420 the new code does not need to inspect the IR
any more and we also do not generate multiple redundant writes.

llvm-svn: 243852
2015-08-02 16:17:41 +00:00
Tobias Grosser d2d15a8c65 Dependences: Zero pad the schedule map
The schedule map we derive from a schedule tree map may map statements into
schedule spaces of different dimensionality. This change adds zero padding
to ensure just a single schedule space is used and the translation from
a union_map to an isl_multi_union_pw_aff does not fail.

llvm-svn: 243849
2015-08-02 13:30:33 +00:00
Tobias Grosser 45e7944bcf Only use instructions as insert locations for SCEVExpander
SCEVExpander, which we are using during code generation, only allows
instructions as insert locations, but breaks in case BasicBlock->end() iterators
are passed to it due to it trying to obtain the basic block in which code should
be generated by calling Instruction->getParent(), which is not defined for
->end() iterators.

This change adds an assert to Polly that ensures we only pass valid instructions
to SCEVExpander and it fixes one case, where we used IRBuilder->SetInsertBlock()
to set an ->end() insert location which was later passed to SCEVExpander.

In general, Polly is always trying to build up the CFG first, before we actually
insert instructions into the CFG sceleton. As a result, each basic block should
already have at least one branch instruction before we start adding code. Hence,
always requiring the IRBuilder insert location to be set to a real instruction
should always be possible.

Thanks Utpal Bora <cs14mtech11017@iith.ac.in> for his help with test case
reduction.

llvm-svn: 243830
2015-08-01 09:07:57 +00:00
Duncan P. N. Exon Smith c51714a0c6 Fix polly tests after LLVM IR change in r243774
llvm-svn: 243801
2015-07-31 23:58:50 +00:00
Tobias Grosser 80e237bd53 Do not detect scops that are delinearized to arrays with "undef" size
Such codes are not interesting to optimize and most likely never appear in the
normal compilation flow. However, they show up during test case reduction with
bugpoint and trigger -- without this change -- an assert in
polly::MemoryAccess::foldAccess(). It is better to detect them in
ScopDetection itself and just bail out.

Contributed-by:  Utpal Bora  <cs14mtech11017@iith.ac.in>

Reviewers: grosser

Subscribers: pollydev, llvm-commits

Differential Revision: http://reviews.llvm.org/D11425

llvm-svn: 243515
2015-07-29 13:52:05 +00:00
Tobias Grosser b241d928bd Rewrite getPrevectorMap using schedule trees operations
Schedule trees are a lot easier to work with, for both humans and machines. For
humans the more structured schedule representation is easier to reason about.
Together with the more abstract isl programming interface this can result in a
lot cleaner code (see this changeset). For machines, the structured schedule and
the fact that we now use explicit piecewise affine expressions instead of
integer maps makes it easier to generate code from this schedule tree. As a
result, we can already see a slight compile-time improvement -- for 3mm from
0m0.593s to 0m0.551s seconds (-7 %). More importantly, future optimizations such
as full-partial tile separation will most likely result in more streamlined code
to be generated.

Contributed-by: Roman Gareev <gareevroman@gmail.com>
llvm-svn: 243458
2015-07-28 18:03:36 +00:00
Tobias Grosser 922452285a Keep track of ScopArrayInfo objects that model PHI node storage
Summary:
When translating PHI nodes into memory dependences during code generation we
require two kinds of memory. 'Normal memory' as for all scalar dependences and
'PHI node memory' to store the incoming values of the PHI node. With this
patch we now mark and track these two kinds of memories, which we previously
incorrectly marked as a single memory object.

Being aware of PHI node storage makes code generation easier, as we do not need
to guess what kind of storage a scalar reference requires. This simplifies the
code nicely.

Reviewers: jdoerfert

Subscribers: pollydev, llvm-commits

Differential Revision: http://reviews.llvm.org/D11554

llvm-svn: 243420
2015-07-28 14:53:44 +00:00
Tobias Grosser 3b10c94062 Prevectorize the schedule of the band (or the point loop in case of tiling)
Contributed-by: Roman Gareev <gareevroman@gmail.com>
llvm-svn: 243214
2015-07-25 12:28:56 +00:00
Michael Kruse be16d22f04 Normalize whitespace in makefiles
Tabs for rules and space for line continuations.

llvm-svn: 243179
2015-07-24 23:30:31 +00:00
Michael Kruse 1bbe346cef Make the lit configuration Python 3 compatible
by using the same techniques as LLVM's lit configuration.

llvm-svn: 243154
2015-07-24 20:33:22 +00:00
Michael Kruse 5e9f249c3e Add LICM test cases
These test cases check whether Polly still gives the same results if
LICM runs before.  Currently, it does not and therefore these cases are
expected fails. 

llvm-svn: 243037
2015-07-23 20:05:11 +00:00
Johannes Doerfert 338b42c329 Removed redundant alias checks generated during run time.
As specified in PR23888, run-time alias check generation is expensive
  in terms of compile-time. This reduces the compile time by computing
  minimal/maximal access only once for each base pointer

Contributed-by: Pratik Bhatu <cs12b1010@iith.ac.in>
llvm-svn: 243024
2015-07-23 17:04:54 +00:00
Michael Kruse 6362f5aa0b Unify FOLDER property of Polly targets
Put all Polly targets into a single "Polly" category (i.e.
solution folder). Previously there was no recognizable scheme and most
categories contained just one or two targets or targets didn't belong
to any category.

Reviewers: grosser
llvm-svn: 242779
2015-07-21 12:40:01 +00:00
Tobias Grosser 808cd69a92 Use schedule trees to represent execution order of statements
Instead of flat schedules, we now use so-called schedule trees to represent the
execution order of the statements in a SCoP. Schedule trees make it a lot easier
to analyze, understand and modify properties of a schedule, as specific nodes
in the tree can be choosen and possibly replaced.

This patch does not yet fully move our DependenceInfo pass to schedule trees,
as some additional performance analysis is needed here. (In general schedule
trees should be faster in compile-time, as the more structured representation
is generally easier to analyze and work with). We also can not yet perform the
reduction analysis on schedule trees.

For more information regarding schedule trees, please see Section 6 of
https://lirias.kuleuven.be/handle/123456789/497238

llvm-svn: 242130
2015-07-14 09:33:13 +00:00
Tobias Grosser 16c4403a91 Make non-affine statement names isl compatible
Named isl sets can generally have any name if they remain within Polly, but only
certain strings can be parsed by isl. The new names we create ensure that we
can always copy-past isl strings from Polly to other isl tools, e.g. for
debugging.

llvm-svn: 241787
2015-07-09 07:31:45 +00:00
Tobias Grosser 1b13ddea50 Add first support to delinearize A[t%2][i][j]
This is very preliminary support, but it seems to work for the most common case.
When observing more/different test cases, we can work on generalizing this.

llvm-svn: 240955
2015-06-29 14:44:22 +00:00
Tobias Grosser af4e809ca6 Remove code for scalar and PHI to array translation
This removes old code that has been disabled since several weeks and was hidden
behind the flags -disable-polly-intra-scop-scalar-to-array=false and
-polly-model-phi-nodes=false. Earlier, Polly used to translate scalars and
PHI nodes to single element arrays, as this avoided the need for their special
handling in Polly. With Johannes' patches adding native support for such scalar
references to Polly, this code is not needed any more. After this commit both
-polly-prepare and -polly-independent are now mostly no-ops. Only a couple of
simple transformations still remain, but they are scheduled for removal too.

Thanks again to Johannes Doerfert for his nice work in making all this code
obsolete.

llvm-svn: 240766
2015-06-26 07:31:18 +00:00
Tobias Grosser 50165ffdee Add support for srem instruction
Remainder operations with constant divisor can be modeled as quasi-affine
expression. This patch adds support for detecting and modeling them. We also
add a test that ensures they are correctly code generated.

This patch was extracted from a larger patch contributed by Johannes Doerfert
in http://reviews.llvm.org/D5293

llvm-svn: 240518
2015-06-24 04:13:29 +00:00
Tobias Grosser a608569856 Replace srem by function call in nonaffine test cases
This makes the test cases nonaffine even if Polly some days gains support for
the srem instruction, an instruction which is currently not modeled but which
can clearly be modeled statically. A call to a function without definition
will always remain non-affine, as there is just insufficient static information
for it to be modeled more precisely.

llvm-svn: 240458
2015-06-23 20:55:05 +00:00
Tobias Grosser aa9f575ae1 Adjust to personality function change in 239940
llvm-svn: 239992
2015-06-18 05:02:11 +00:00
Tobias Grosser 8199c722c7 Disable output for test case that does not need output
llvm-svn: 239060
2015-06-04 17:59:51 +00:00
Tobias Grosser 22adfb4373 Mark sdivs as 'exact' instead of lowering them ourselves
LLVM's instcombine already translates power-of-two sdivs that are known to be
exact to fast ashr instructions. Hence, there is no need to add this logic
ourselves.

Pointed-out-by: Johannes Doerfert
llvm-svn: 239025
2015-06-04 07:45:09 +00:00
Tobias Grosser 5cf7860704 Ensure memory access mappings are defined for full domain
We now verify that memory access functions imported via JSON are indeed defined
for the full iteration domain. Before this change we accidentally imported
memory mappings such as i -> i / 127, which only defined a mapped for values of
i that are evenly divisible by 127, but which did not define any mapping for the
remaining values, with the result that isl just generated an access expression
that had undefined behavior for all the unmapped values.

In the incorrect test cases, we now either use floor(i/127) or we use p/127 and
provide the information that p is indeed a multiple of 127.

llvm-svn: 239024
2015-06-04 07:44:35 +00:00
Tobias Grosser 244c8297cf Lower signed-divisions without rounding to ashr instructions
llvm-svn: 238929
2015-06-03 15:14:58 +00:00
Tobias Grosser cb73f150d4 Translate power-of-two floor-division into ashr
Power-of-two floor divisions can be translated into an arithmetic shift
operation. This allows us to replace a complex lowering that requires division
operations:

  %pexp.fdiv_q.0 = sub i64 %21, 128
  %pexp.fdiv_q.1 = add i64 %pexp.fdiv_q.0, 1
  %pexp.fdiv_q.2 = icmp slt i64 %21, 0
  %pexp.fdiv_q.3 = select i1 %pexp.fdiv_q.2, i64 %pexp.fdiv_q.1, i64 %21
  %pexp.fdiv_q.4 = sdiv i64 %pexp.fdiv_q.3, 128

with a simple ashr:

  %polly.fdiv_q.shr = ashr i64 %21, 7

llvm-svn: 238905
2015-06-03 06:31:30 +00:00
Tobias Grosser cdb38e5625 Exploit non-negative numerators
isl marks known non-negative numerators in modulo (and soon also division)
operations. We now exploit this by generating unsigned operations. This is
beneficial as unsigned operations with power-of-two denominators will be
translated by isl to fast bitshift or bitwise and operations.

llvm-svn: 238577
2015-05-29 17:08:19 +00:00
Tobias Grosser c825fae020 Tighten the PHI modeling test cases
While looking through the test cases I realized we did not have a CHECK line
for a duplicate memory access which we may want to eliminate later. To ensure
we do not have (or later introduce) unnecessary memory accesses, we now tighten
the test cases to look for such a pattern (and add the CHECK: line that shows
the redundant memory access).

llvm-svn: 238227
2015-05-26 18:05:45 +00:00
Tobias Grosser 268205939f Make use of scalar/phi code generation explicit in the tests
This ensures we pass all tests independently of how we set the options
-disable-polly-intra-scop-scalar-to-array and -polly-model-phi-nodes.

(At least if we enable both or disable both. Enabling them individually makes
 little sense, as they will hopefully disappear soon anyhow).

llvm-svn: 238087
2015-05-23 03:34:35 +00:00
Johannes Doerfert ecff11dcfb Add scalar and phi code generation
To reduce compile time and to allow more and better quality SCoPs in
  the long run we introduced scalar dependences and PHI-modeling. This
  patch will now allow us to generate code if one or both of those
  options are set. While the principle of demoting scalars as well as
  PHIs to memory in order to communicate their value stays the same,
  this allows to delay the demotion till the very end (the actual code
  generation). Consequently:
    - We __almost__ do not modify the code if we do not generate code
      for an optimized SCoP in the end. Thus, the early exit as well as
      the unprofitable option will now actually preven us from
      introducing regressions in case we will probably not get better
      code.
    - Polly can be used as a "pure" analyzer tool as long as the code
      generator is set to none.
    - The original SCoP is almost not touched when the optimized version
      is placed next to it. Runtime regressions if the runtime checks
      chooses the original are not to be expected and later
      optimizations do not need to revert the demotion for that part.
    - We will generate direct accesses to the demoted values, thus there
      are no "trivial GEPs" that select the first element of a scalar we
      demoted and treated as an array.

Differential Revision: http://reviews.llvm.org/D7513

llvm-svn: 238070
2015-05-22 23:43:58 +00:00
Tobias Grosser 5db5d2da13 Use base-pointer address space when creating new access functions
llvm-svn: 237785
2015-05-20 11:02:12 +00:00
Tobias Grosser 49ad36ca16 Add printing and testing to ScopArrayInfo
Being here, we extend the interface to return the element type and not a pointer
to the element type. We also provide a function to get the size (in bytes) of
the elements stored in this array.

We currently still store the element size as an innermost dimension in
ScopArrayInfo, which is somehow inconsistent and should be addressed in future
patches.

llvm-svn: 237779
2015-05-20 08:05:31 +00:00
Sunil Srivastava 19be68f088 Changed renaming of local symbols by inserting a dot before the numeric suffix.
Modified two test cases to adjust to the above change in renaming.
These two files were causing the buildbot failure in Polly, #30204 for example.
Details in http://reviews.llvm.org/D9483
This checkin goes with r237150 and r237151

llvm-svn: 237203
2015-05-12 22:44:24 +00:00