<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </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 - Repeated conditionals are not combined with differing conditionals in between"
   href="https://bugs.llvm.org/show_bug.cgi?id=52455">52455</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Repeated conditionals are not combined with differing conditionals in between
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>13.0
          </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>enhancement
          </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>llvm-bugs@bluematt.me
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>In some auto-generated XDP code which (in part) consists of a long list of
conditional -> return XDP_DROP statements, LLVM 13 seems materially worse at
combining parts of the conditionals which are repeated than LLVM 12-, though
both miss some major cases.

The godbolt link at <a href="https://godbolt.org/z/hW3r6EKqT">https://godbolt.org/z/hW3r6EKqT</a> demonstrates this using
something that is based on my (real) auto-generated code. In clang 13, the
first part of the repeated conditional is identical and combined, but any parts
after the `ip->saddr` check (which differs across conditionals) is repeated,
almost doubling the number of instructions the BPF verifier has to process.

In clang 12 (and most previous versions), LLVM can sometimes remove the
repeated `dport` check, but only if its the only if `SADDRA_MASK` and
`SADDRB_MASK` are equal or EXTRA_CHECK is empty. In the real auto-generated
code, `SADDRA_MASK` and `SADDRB_MASK` differ across each conditional, and
`EXTRA_CHECK` is something like "ip->protocol == 6 &&", which causes clang
11/12 to repeat the port and protocol checks for each conditional (ie
<a href="https://godbolt.org/z/h8d1zesjr">https://godbolt.org/z/h8d1zesjr</a> which is the same base code as above).</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>