<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </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 --- - [Polly] Unnecessarily complicated schedule"
   href="https://llvm.org/bugs/show_bug.cgi?id=25507">25507</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[Polly] Unnecessarily complicated schedule
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>Projects
          </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>Polly
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>llvm@meinersbur.de
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=15279" name="attach_15279" title="Extract from MultiSource/Benchmark/Ptrdist/bc/number.c">attachment 15279</a> <a href="attachment.cgi?id=15279&action=edit" title="Extract from MultiSource/Benchmark/Ptrdist/bc/number.c">[details]</a></span>
Extract from MultiSource/Benchmark/Ptrdist/bc/number.c

$ clang loopschedule.c -c -O3 -mllvm -polly -mllvm -debug -mllvm
-debug-only=polly-ast -mllvm -polly-process-unprofitable

emits the following schedule for the loop "while.body => while.end"

      for (int c0 = 0; c0 < min(n2, n1); c0 += 1)
        Stmt_while_body(c0);
      if (n1 <= 0) {
        Stmt_while_body(0);
      } else if (n2 <= 0)
        Stmt_while_body(0);

    Context:
    [n2, n1] -> {  : n2 >= -2147483648 and n2 <= 2147483647 and n1 >=
-2147483648 and n1 <= 2147483647 }
    Assumed Context:
    [n2, n1] -> {  :  }
    Boundary Context:
    [n2, n1] -> {  :  }
    Statements
        Stmt_while_body
            Domain :=
                [n2, n1] -> { Stmt_while_body[i0] : i0 >= 0 and i0 <= -1 + n1
and i0 <= -1 + n2; Stmt_while_body[0] : n1 <= 0 or (n2 <= 0 and n1 >= 1) };



The initial loop condition is hoisted outside of the scop, i.e

if ((n1 > 0) && (n2 > 0)) {
  // Scop
}


1) The generated schedule has two conditions (n1 <= 0) and (n2 <= 0) that are
never evaluated code, i.e. 2/3 of the generated code is effectively dead.


2) After passing the hoisted initial condition, the BasicBlock while.body must
be executed at least once before the condition is checked again. Still, CodeGen
inserts a second initial check into "polly.loop_if". It results into an
additional branch that is not optimized away by later LLVM passes and
potentially "undef" to appear after -mem2reg.


We might analyze the hoisted condition to translate into additional assumptions
(Here: n1 > 0 && n2 > 0). Unfortunately, there is no LLVM analysis to tell the
the possible range of a value.</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>