<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 --- - InstCombine should keep useful &#64;llvm.assume calls" href="https://urldefense.proofpoint.com/v2/url?u=https-3A__llvm.org_bugs_show-5Fbug.cgi-3Fid-3D23809&d=AwMBaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=pF93YEPyB-J_PERP4DUZOJDzFVX5ZQ57vQk33wu0vio&m=FU8we6BJozbJDJTquB-Qrd_re0k8sA9vtSfvsAIfPm8&s=WfRPvSudgSDeuXt5WcSQGSJyU7tTrNgrIPaDPhCo1OE&e=">23809</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>InstCombine should keep useful @llvm.assume calls
          </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>Linux
          </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>wujingyue@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=14461" name="attach_14461" title="the test case as mentioned in the description">attachment 14461</a> <a href="attachment.cgi?id=14461&action=edit" title="the test case as mentioned in the description">[details]</a></span>
the test case as mentioned in the description

I have some WIP that leverages @llvm.assume in some optimization passes other
than InstCombine. However, it doesn't work yet because InstCombine removes
@llvm.assume calls that are useful for later optimizations. For example, given

define i32 @foo(i32 %a, i32 %b) {
  %sum = add i32 %a, %b
  %1 = icmp sge i32 %sum, 0
  call void @llvm.assume(i1 %1)
  ret i32 %sum
}

"opt -instcombine" emits

define i32 @foo(i32 %a, i32 %b) {
  %sum = add i32 %a, %b
  ret i32 %sum
}

removing the @llvm.assume call so later optimizations won't know sum is
non-negative any more. (Note that the opt I use here is with
<a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__reviews.llvm.org_D10283&d=AwMBaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=pF93YEPyB-J_PERP4DUZOJDzFVX5ZQ57vQk33wu0vio&m=FU8we6BJozbJDJTquB-Qrd_re0k8sA9vtSfvsAIfPm8&s=ht9Aej2kWarhXfR9u8pCl78IHzElfffe8JQQY6cG0FY&e=">http://reviews.llvm.org/D10283</a> patched. This patch fixes a bug in
ValueTracking). 

The reasons that InstCombine removes this assume call are: 
1) SimplifyICmpInst proves %1 is true based on the assume call. 
2) then, InstCombine
(<a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_docs_doxygen_html_InstCombineCompares-5F8cpp-5Fsource.html-23l02649&d=AwMBaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=pF93YEPyB-J_PERP4DUZOJDzFVX5ZQ57vQk33wu0vio&m=FU8we6BJozbJDJTquB-Qrd_re0k8sA9vtSfvsAIfPm8&s=jvFy-MlBeBXZprkOcQq7pbKZj7GWx_nKLxp4ubjPYOo&e=">http://llvm.org/docs/doxygen/html/InstCombineCompares_8cpp_source.html#l02649</a>)
replaces all uses of %1 with true including the use in the assume call. 
3) Somewhere later, llvm.assume(true) is considered trivially dead and thus
removed from the IR.</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>