<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 --- - Induction variable simplification does not simplify truncates"
   href="https://llvm.org/bugs/show_bug.cgi?id=24670">24670</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Induction variable simplification does not simplify truncates
          </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>All
          </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>Scalar Optimizations
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>sanjoy@playingwithpointers.com
          </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>Currently LLVM does not optimize `%c0` to `i1 true` in the following example:

declare void @use()

define void @f(i32 %len) {
 entry:
  %e = icmp slt i32 0, %len
  br i1 %e, label %loop, label %leave

 loop:
  %idx = phi i64 [ 0, %entry ], [ %idx.inc, %be ]
  %idx.inc = add i64 %idx, 1
  %idx.tr = trunc i64 %idx to i32
  call void @use()
  %c0 = icmp slt i32 %idx.tr, %len
  br i1 %c0, label %be, label %leave

 be:
  %idx.inc.tr = trunc i64 %idx.inc to i32
  call void @use()
  %c1 = icmp slt i32 %idx.inc.tr, %len
  br i1 %c1, label %loop, label %leave

 leave:
  ret void
}


The interesting bit is that SCEV already has all the smarts required to
optimize this check away; and calling `simplifyLoopIVs` optimizes the check as
expected.  -indvars does not get this case because it does not look through
truncates of induction variables, and thus does not try to eliminate `%c0`.</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>