<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 --- - deduce icmp result from llvm.assume"
   href="https://llvm.org/bugs/show_bug.cgi?id=31596">31596</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>deduce icmp result from llvm.assume
          </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>Transformation Utilities
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>spatel+llvm@rotateright.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>Filing this based on a question from Daniel Berlin:
<a href="http://lists.llvm.org/pipermail/llvm-commits/Week-of-Mon-20170109/418024.html">http://lists.llvm.org/pipermail/llvm-commits/Week-of-Mon-20170109/418024.html</a>

declare void @llvm.assume(i1)

define i1 @deduce_icmp_from_assume(i8 %a, i8 %b) {
  %eqcond = icmp eq i8 %a, %b
  call void @llvm.assume(i1 %eqcond)
  %ltcond = icmp slt i8 %a, %b
  ret i1 %ltcond
}

------------------------------------------------------------------------------

Some pass (don't know which one yet because the line between analysis and the
compile-time cost of that analysis is not clear) should be able to simplify
this to return 'false', but nothing in the -O2 pipeline as of r291443 handles
this.

FWIW, we already call computeKnownBits in InstCombiner::visitReturnInst() for
the stated purpose of checking assumptions:
  // There might be assume intrinsics dominating this return that completely
  // determine the value. If so, constant fold it.

...so this particular case could be handled by adding to the pattern-matching
logic in computeKnownBitsFromAssume() ( see <a href="https://reviews.llvm.org/D28485">https://reviews.llvm.org/D28485</a> ),
but of course that's not the most general solution. 

More typically, we'd expect the 2nd icmp result to be used in a branch or
select, so calling value tracking (should computeKnownBitsFromAssume be raised
into the value tracking API?) when visiting those insts in InstCombine might be
a better way. I have a patch proposal for the select variant here:
<a href="https://reviews.llvm.org/D28337">https://reviews.llvm.org/D28337</a>

There may be no good solution because the design of the llvm.assume intrinsic
itself just isn't ideal ( <a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - refactor metadata propagation for consistency and completeness"
   href="show_bug.cgi?id=31518#c10">bug 31518, comment 10</a> ). Alternative suggestions are
that we should convert it to a form more like llvm.expect:
<a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - missed simplification from llvm.assume"
   href="show_bug.cgi?id=31512#c4">bug 31512, comment 4</a>

That could lead to a lower-to-metadata pass such as "-lower-expect", so we
wouldn't have the problem of optimization intrinsics interfering with
optimization as noted by Eli here:
<a href="https://reviews.llvm.org/D27114">https://reviews.llvm.org/D27114</a></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>