<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - delinearization fails: casting issue?"
   href="https://bugs.llvm.org/show_bug.cgi?id=33104">33104</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>delinearization fails: casting issue?
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>Polly
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Other
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>polly-dev@googlegroups.com
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>cychan@lbl.gov
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>The delinearization analysis fails on the sample codes (Listings 4 and 5)
presented in the Grosser IMPACT2015 paper due to possible casting issues.

The following code (Listing 4) was tested with "clang test.c  -O3 -mllvm -polly
 -c -mllvm -debug-only=polly-scops -mllvm -polly-process-unprofitable":

#include <stddef.h>
struct TwoDArray {
size_t size0; size_t size1; float *Base;
};
#define ACCESS_2D(A, x, y) \
*(A->Base + (x) * A->size1 + (y))
#define SIZE0_2D(A) A->size0
#define SIZE1_2D(A) A->size1
void gemm(struct TwoDArray *A, struct TwoDArray *B,
          struct TwoDArray *C) {
  for (int i = 0; i < SIZE0_2D(C); i++)
    for (int j = 0; j < SIZE1_2D(C); j++)
      for (int k = 0; k < SIZE1_2D(A); ++k)
        ACCESS_2D(C, i, j) += ACCESS_2D(A, i, k) * ACCESS_2D(B, k, j);
}

There was no output produced.  I tried running "opt -debug -basicaa
-delinearize -polly-process-unprofitable -polly-scops -analyze temp.s.ll" on
the canonicalized IR, but i was unable to decipher the output.

The following code (Listing 5) was tested with "clang test.c  -O3 -mllvm -polly
 -c -mllvm -debug-only=polly-scops -mllvm -polly-process-unprofitable":

void set_subarray(unsigned n1, unsigned n2,
    unsigned o0, unsigned o1, unsigned o2,
    unsigned s0, unsigned s1, unsigned s2,
    float A[]) {
  for (unsigned i = 0; i < s0; i++)
    for (unsigned j = 0; j < s1; j++)
      for (unsigned k = 0; k < s2; k++)
        A[(n2 * (n1 * o0 + o1) + o2) + n1 * n2 * i + n2 * j + k] = 1;
}

Which produces the following output:

    Function: set_subarray
    Region: %for.cond4.preheader---%for.inc15
    Max Loop Depth:  1
    Invariant Accesses: {
    }
    Context:
    [s2, p_1, p_2, p_3, o2] -> {  : -2147483648 <= s2 <= 2147483647 and
-2147483648 <= p_1 <= 2147483647 and -2147483648 <= p_2 <= 2147483647 and
-2147483648 <= p_3 <= 2147483647 and -2147483648 <= o2 <= 2147483647 }
    Assumed Context:
    [s2, p_1, p_2, p_3, o2] -> {  :  }
    Invalid Context:
    [s2, p_1, p_2, p_3, o2] -> {  : s2 > 0 and (o2 <= -2147483649 - p_2 - p_3
or o2 <= -2147483649 - p_3 or o2 >= 2147483649 - s2 - p_1 - p_2 - p_3 or o2 >=
2147483648 - p_3 or o2 >= 2147483648 - p_2 - p_3 or o2 < -p_1 - p_2 - p_3) }
    p0: %s2
    p1: {0,+,%n2}<%for.cond4.preheader>
    p2: {0,+,(%n1 * %n2)}<%for.cond1.preheader>
    p3: (((%n1 * %o0) + %o1) * %n2)
    p4: %o2
    Arrays {
        i32 MemRef_j_08; // Element size 4
        float MemRef_A[*]; // Element size 4
    }
    Arrays (Bounds as pw_affs) {
        i32 MemRef_j_08; // Element size 4
        float MemRef_A[*]; // Element size 4
    }
    Alias Groups (0):
        n/a
    Statements {
        Stmt_for_cond4_preheader
            Domain :=
                [s2, p_1, p_2, p_3, o2] -> { Stmt_for_cond4_preheader[] };
            Schedule :=
                [s2, p_1, p_2, p_3, o2] -> { Stmt_for_cond4_preheader[] -> [0,
0] };
            MustWriteAccess :=  [Reduction Type: NONE] [Scalar: 1]
                [s2, p_1, p_2, p_3, o2] -> { Stmt_for_cond4_preheader[] ->
MemRef_j_08[] };
        Stmt_for_body6
            Domain :=
                [s2, p_1, p_2, p_3, o2] -> { Stmt_for_body6[i0] : 0 <= i0 < s2
};
            Schedule :=
                [s2, p_1, p_2, p_3, o2] -> { Stmt_for_body6[i0] -> [1, i0] };
            MustWriteAccess :=  [Reduction Type: NONE] [Scalar: 0]
                [s2, p_1, p_2, p_3, o2] -> { Stmt_for_body6[i0] -> MemRef_A[p_1
+ p_2 + p_3 + o2 + i0] };
    }

Changing unsigned to long appears to correct the issue:

    Function: set_subarray
    Region: %entry.split---%for.cond.cleanup
    Max Loop Depth:  3
    Invariant Accesses: {
    }
    Context:
    [s0, s1, s2, n1, n2, o0, o1, o2] -> {  : -9223372036854775808 <= s0 <=
9223372036854775807 and -9223372036854775808 <= s1 <= 9223372036854775807 and
-9223372036854775808 <= s2 <= 9223372036854775807 and -9223372036854775808 <=
n1 <= 9223372036854775807 and -9223372036854775808 <= n2 <= 9223372036854775807
and -9223372036854775808 <= o0 <= 9223372036854775807 and -9223372036854775808
<= o1 <= 9223372036854775807 and -9223372036854775808 <= o2 <=
9223372036854775807 }
    Assumed Context:
    [s0, s1, s2, n1, n2, o0, o1, o2] -> {  : -n1 <= o1 <= 1 - s1 + n1 and ((o1
<span class="quote">> -n1 and -n2 <= o2 <= -s2) or (o1 <= -s1 + n1 and 0 <= o2 <= -s2 + n2) or (-n1</span >
< o1 <= -s1 + n1 and o2 >= -n2 and -s2 < o2 <= -s2 + n2 and o2 < 0)) }
    Invalid Context:
    [s0, s1, s2, n1, n2, o0, o1, o2] -> {  : (s1 > 0 and s2 > 0 and o0 >=
9223372036854775809 - s0) or (s0 > 0 and s2 > 0 and o1 >= 9223372036854775809 -
s1) or (s0 > 0 and s1 > 0 and o2 >= 9223372036854775809 - s2) }
    p0: %s0
    p1: %s1
    p2: %s2
    p3: %n1
    p4: %n2
    p5: %o0
    p6: %o1
    p7: %o2
    Arrays {
        float MemRef_A[*][%n1][%n2]; // Element size 4
    }
    Arrays (Bounds as pw_affs) {
        float MemRef_A[*][ [n1] -> { [] -> [(n1)] } ][ [n2] -> { [] -> [(n2)] }
]; // Element size 4
    }
    Alias Groups (0):
        n/a
    Statements {
        Stmt_for_body8
            Domain :=
                [s0, s1, s2, n1, n2, o0, o1, o2] -> { Stmt_for_body8[i0, i1,
i2] : 0 <= i0 < s0 and 0 <= i1 < s1 and 0 <= i2 < s2 };
            Schedule :=
                [s0, s1, s2, n1, n2, o0, o1, o2] -> { Stmt_for_body8[i0, i1,
i2] -> [i0, i1, i2] };
            MustWriteAccess :=  [Reduction Type: NONE] [Scalar: 0]
                [s0, s1, s2, n1, n2, o0, o1, o2] -> { Stmt_for_body8[i0, i1,
i2] -> MemRef_A[-1 + o0 + i0, -1 + n1 + o1 + i1, n2 + o2 + i2] : i1 <= -o1 and
i2 < -o2; Stmt_for_body8[i0, i1, i2] -> MemRef_A[o0 + i0, -1 + o1 + i1, n2 + o2
+ i2] : i1 > -o1 and i2 < -o2; Stmt_for_body8[i0, i1, i2] -> MemRef_A[-1 + o0 +
i0, n1 + o1 + i1, o2 + i2] : i1 < -o1 and i2 >= -o2; Stmt_for_body8[i0, i1, i2]
-> MemRef_A[o0 + i0, o1 + i1, o2 + i2] : i1 >= -o1 and i2 >= -o2 };
    }</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>