<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 --- - branch condition should be known from llvm.assume"
   href="https://llvm.org/bugs/show_bug.cgi?id=31929">31929</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>branch condition should be known 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>Scalar Optimizations
          </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 the request in:
<a href="https://reviews.llvm.org/D28204">https://reviews.llvm.org/D28204</a>

These are purposely minimized to be instcombine tests. If we decide that the
functionality doesn't belong there, then the tests may require additional
instructions to thwart other transformations (phi -> select) and/or trigger
from a different pass (LICM?).

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

declare void @llvm.assume(i1)

define i8 @assume_guarantees_notnull(i8* %x) {
entry:
  %notnull = icmp ne i8* %x, null
  tail call void @llvm.assume(i1 %notnull)
  br i1 %notnull, label %if, label %endif   <--- condition is known true
if:
  %ld = load i8, i8* %x
  br label %endif
endif:
  %sel = phi i8 [ 0, %entry ], [ %ld, %if ]
  ret i8 %sel
}

Depending on how we want to solve this, it may be relevant to use a non-pointer
value in the icmp:

define i8 @assume_guarantees_notnull(i8 %y, i8* %x) {
entry:
  %notnull = icmp ne i8 %y, 0               <--- type shouldn't matter?
  tail call void @llvm.assume(i1 %notnull)
  br i1 %notnull, label %if, label %endif
if:                               
  %ld = load i8, i8* %x, align 1
  br label %endif
endif:                   
  %sel = phi i8 [ 0, %entry ], [ %ld, %if ]
  ret i8 %sel
}

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

For reference, we handle the 'select' variant of these examples in instcombine
by calling computeKnownBits when we know there might be an assumption that
defines the condition. That was <a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - missed simplification from llvm.assume"
   href="show_bug.cgi?id=31512">bug 31512</a> / <a href="https://reviews.llvm.org/rL291915">https://reviews.llvm.org/rL291915</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>