<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 --- - Unsigned wrap check conditions falling to original code"
   href="https://llvm.org/bugs/show_bug.cgi?id=28922">28922</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Unsigned wrap check conditions falling to original code
          </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>Windows NT
          </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>Optimizer
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>chrisj@codeaurora.org
          </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=16927" name="attach_16927" title="test case">attachment 16927</a> <a href="attachment.cgi?id=16927&action=edit" title="test case">[details]</a></span>
test case

<span class="quote">> opt  -polly-process-unprofitable -polly-code-generator=isl -polly-ast -analyze test.ll</span >

Consider the context check below,

:: isl ast :: foo4 :: %entry.split---%for.cond.cleanup

if (1 && 0 == (m >= n + 9223372036854775809 || n >= m + 9223372036854775808 ||
m == -9223372036854775808))
for (int c0 = 0; c0 < -m + n; c0 += 1)
  Stmt_for_body(c0);

else
{  /* original code */ }


Values 9223372036854775809 (0x8000000000000001) and 9223372036854775808
(8000000000000000) are already overflown and having addition operation with
them leads to the result being wrapped.

Hence this would lead to the context condition falling to the original code. On
the other hand, say if the condition were in form where there was no operation
with the max int values it would not wrap. i.e. if the condition were like (m -
n >= 9223372036854775809) or (n - m >= 9223372036854775808). 

<span class="quote">> opt  -polly-process-unprofitable -polly-code-generator=isl  -polly-codegen -S  test.ll</span >

--snip--
polly.split_new_and_old:                          ; preds = %entry
  %0 = call { i64, i1 } @llvm.sadd.with.overflow.i64(i64 %n, i64
-9223372036854775807) <===
  %.obit = extractvalue { i64, i1 } %0, 1
  %polly.overflow.state = or i1 false, %.obit
  %.res = extractvalue { i64, i1 } %0, 0
  %1 = icmp sge i64 %m, %.res
  %2 = call { i64, i1 } @llvm.sadd.with.overflow.i64(i64 %m, i64
-9223372036854775808) <===
  %.obit1 = extractvalue { i64, i1 } %2, 1
  %polly.overflow.state2 = or i1 %polly.overflow.state, %.obit1
  %.res3 = extractvalue { i64, i1 } %2, 0
  %3 = icmp sge i64 %n, %.res3
  %4 = or i1 %1, %3
  %5 = icmp eq i64 %m, -9223372036854775808
  %6 = or i1 %4, %5
  %7 = sext i1 %6 to i64
  %8 = icmp eq i64 0, %7
  %9 = and i1 true, %8
  %polly.rtc.overflown = xor i1 %polly.overflow.state2, true
  %polly.rtc.result = and i1 %9, %polly.rtc.overflown
  br i1 %polly.rtc.result, label %polly.start, label %entry.split
--snip--</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>