<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 - SCEV ignores nuw/nsw when computing MaxBackedgeTakenCount"
   href="https://bugs.llvm.org/show_bug.cgi?id=50028">50028</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>SCEV ignores nuw/nsw when computing MaxBackedgeTakenCount
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </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>enhancement
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>Global Analyses
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>suc-daniil@yandex.ru
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>define void @foo(i32 %n) {
entry:
  br label %loop

loop:
  %i = phi i32 [ 0, %entry ], [ %i.next, %loop ]
  %i.next = add nuw nsw i32 %i, 1
  %innercmp = icmp ult i32 %i, %n
  br i1 %innercmp, label %loop, label %exit

exit:
  ret void
}

Running opt -passes='print<scalar-evolution>' gives us the following result:

Printing analysis 'Scalar Evolution Analysis' for function 'foo':
Classifying expressions for: @foo
  %i = phi i32 [ 0, %entry ], [ %i.next, %loop ]
  -->  {0,+,1}<nuw><nsw><%loop> U: [0,-2147483648) S: [0,-2147483648)          
Exits: %n               LoopDispositions: { %loop: Computable }
  %i.next = add nuw nsw i32 %i, 1
  -->  {1,+,1}<nuw><%loop> U: [1,0) S: [1,0)            Exits: (1 + %n)        
LoopDispositions: { %loop: Computable }
Determining loop execution counts for: @foo
Loop %loop: backedge-taken count is %n
Loop %loop: max backedge-taken count is -1
Loop %loop: Predicated backedge-taken count is %n
 Predicates:

Loop %loop: Trip multiple is 1


SCEV understands that %i won't exceed 2^31, but says that the backedge can be
taken up to 2^32-1 times. Since it's an upper-bound estimate, it's correct, yet
suboptimal.</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>