<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 - Missed opportunity to optimize pointer range checks"
   href="https://bugs.llvm.org/show_bug.cgi?id=47053">47053</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Missed opportunity to optimize pointer range checks
          </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>enhancement
          </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>david.bolvansky@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>bool f1 (char *a, char *b)
{
  return (a + 16 <= b) || (b + 16 <= a);
}



Clang:

f1(char*, char*):                              # @f1(char*, char*)
        lea     rax, [rdi + 16]
        cmp     rax, rsi
        setbe   cl
        add     rsi, 16
        cmp     rsi, rdi
        setbe   al
        or      al, cl
        ret

GCC:

f1(char*, char*):
        add     rdi, 15
        sub     rdi, rsi
        cmp     rdi, 30
        seta    al
        ret

GCC transforms 

A + size <= B || B + size <= A

to

(size_t) (A + (size - 1) - B) > (size - 1) * 2


Could be useful to optimize better RT checks from vectorizer.

Godbolt: <a href="https://godbolt.org/z/9jsKa4">https://godbolt.org/z/9jsKa4</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>