<html>
    <head>
      <base href="http://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 --- - ISel DAG: HandleMergeInputChains is overly conservative"
   href="http://llvm.org/bugs/show_bug.cgi?id=19237">19237</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>ISel DAG: HandleMergeInputChains is overly conservative
          </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>Common Code Generator Code
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>qcolombet@apple.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=12277" name="attach_12277" title="Testcase that show a missed folding because of the overly conservative check">attachment 12277</a> <a href="attachment.cgi?id=12277&action=edit" title="Testcase that show a missed folding because of the overly conservative check">[details]</a></span>
Testcase that show a missed folding because of the overly conservative check

During the select phase of the isel process, SelectionDAGISel performs a check
to see if a load is foldable into another node (for node supporting that
feature of course).
In particular, it checks that folding the load into the related node will not
create a cycle in the DAG.
This check is done by HandleMergeInputChains.

HandleMergeInputChains is not actually checking that a cycle will be created if
something is folded into something else.
In particular, it is not checking for reachability but instead relies on
heuristics to give a quick answer. This answer is conservatively correct:
- No: no cycle will be created.
- Yes: a cycle *may* be created.

I believe this limitation is intended for three reasons:
1. to avoid costly reachability checks.
2. to handle only the rewriting of token factor from the not-yet-matched nodes
to the matched node.
3. everything that has been matched is ready to schedule.

The risk with this approximation is twofold:
- The lowering phase may rely on this folding to happen. As a result "cannot
select" cases may happen like what we fixed in r204631.
- Although this may not impact the performance, the generated code looks bad,
and the code size is impacted.

* STEPS TO REPRODUCE
llc -mattr=+avx2 testcase.ll -o - -O3

* RESULTS
The fallback pattern is used for the broadcast instruction:
    movb    (%rdi), %al
    vmovd    %eax, %xmm1
    vpbroadcastb    %xmm1, %xmm1
Whereas the folding pattern would have match if the cycle detection was
correct:
    vpbroadcastb    (%rdi), %xmm1</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>