<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] pairs of icmps of phis of constants are not simplified"
   href="https://llvm.org/bugs/show_bug.cgi?id=31125">31125</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[InstCombine] pairs of icmps of phis of constants are not simplified
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>3.9
          </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>arielb1@mail.tau.ac.il
          </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>Created <span class=""><a href="attachment.cgi?id=17635" name="attach_17635" title="A more complicated case that simplifycfg can't optimize">attachment 17635</a> <a href="attachment.cgi?id=17635&action=edit" title="A more complicated case that simplifycfg can't optimize">[details]</a></span>
A more complicated case that simplifycfg can't optimize

This seems to be the root cause of Rust issue
<a href="https://github.com/rust-lang/rust/issues/37930">https://github.com/rust-lang/rust/issues/37930</a>, which is causing slowness in
futures-rs.

Minified reproducer:

define i8 @start(i8* %addr) {
entry-block:
  br label %main-loop

main-loop:
  %phi = phi i8 [ 0, %entry-block ], [ 1, %core ]
  %switch_0 = icmp eq i8 %phi, 0
  store volatile i8 0, i8* %addr
  br i1 %switch_0, label %busy-wait-phi-0, label %exit

busy-wait-phi-0:
  %load = load volatile i8, i8* %addr
  %icmp = icmp eq i8 %load, 0
  br i1 %icmp, label %busy-wait-phi-0, label %core

core:
  %switch_1 = icmp eq i8 %phi, 1
  br i1 %switch_1, label %trap, label %main-loop

trap:
  ret i8 1

exit:
  ret i8 0
}

In the reproducer, `trap` can never be hit: %phi is obviously always 0 when you
enter core. SCCP should notice this (SimplifyCfg notices this simple case - but
it does not handle more complicated cases), but it seems to work only on
booleans, and relies on InstCombine to simplify integers to booleans.

If all icmps of the phi compare it against the same integer (e.g. if the `eq 1`
test is replaced with an `ne 0`), everything works well: InstCombine replaces
the integer with a boolean of the form

  %phi = phi i1 [ true, %entry-block ], [ false, %core ]

and SCCP can work its magic.

However, if, as above, one of the icmps is against an `eq 1` and another is
against an `eq 0`, this optimization, and therefore SCCP, can't take place.

This might better be done by extending SCCP to integers instead of in
InstCombine.</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>