Restore the initial ordering of dimensions before applying the pattern matching
authorRoman Gareev <gareevroman@gmail.com>
Thu, 6 Apr 2017 17:09:54 +0000 (17:09 +0000)
committerRoman Gareev <gareevroman@gmail.com>
Thu, 6 Apr 2017 17:09:54 +0000 (17:09 +0000)
commite0d466342b250312dd7569c3630becda99a2c50c
tree13d3267fc74886acc312caa93940ef089c87a399
parentd3115972bf62ba3119b9110b2bd46b72cce015a3
Restore the initial ordering of dimensions before applying the pattern matching

Dimensions of band nodes can be implicitly permuted by the algorithm applied
during the schedule generation.

For example, in case of the following matrix-matrix multiplication,

for (i = 0; i < 1024; i++)
  for (k = 0; k < 1024; k++)
    for (j = 0; j < 1024; j++)
      C[i][j] += A[i][k] * B[k][j];

it can produce the following schedule tree

domain: "{ Stmt_for_body6[i0, i1, i2] : 0 <= i0 <= 1023 and 0 <= i1 <= 1023 and
                                        0 <= i2 <= 1023 }"
child:
  schedule: "[{ Stmt_for_body6[i0, i1, i2] -> [(i0)] },
              { Stmt_for_body6[i0, i1, i2] -> [(i1)] },
              { Stmt_for_body6[i0, i1, i2] -> [(i2)] }]"
  permutable: 1
  coincident: [ 1, 1, 0 ]

The current implementation of the pattern matching optimizations relies on the
initial ordering of dimensions. Otherwise, it can produce the miscompilation
(e.g., [1]).

This patch helps to restore the initial ordering of dimensions by recreating
the band node when the corresponding conditions are satisfied.

Refs.:

[1] - https://bugs.llvm.org/show_bug.cgi?id=32500

Reviewed-by: Michael Kruse <llvm@meinersbur.de>
Differential Revision: https://reviews.llvm.org/D31741

llvm-svn: 299662
polly/lib/Transform/ScheduleOptimizer.cpp
polly/test/ScheduleOptimizer/pattern-matching-based-opts_4.ll [new file with mode: 0644]