<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/120913>120913</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            LLVM cannot constant fold memchr with constant size
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          philnik777
      </td>
    </tr>
</table>

<pre>
    ```c++
void* test1(char* first, char val) {
  return __builtin_memchr(first, val, 2);
}
```
always generates a call to `memchr`, even though it could just check the two chars. I can't really see a case where calling `memchr` is faster than just checking the two chars. For larger N it would also be interesting to use vector comparisons for this instead of calling a function.

</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJxckk9v4ywQxj8NvowaYezE5uBD2irSK_Xd414rjMeGlkDEjBN1P_0K99_uSiNbwDzP89OAIfJLRBzE_l7sHyuzskt5uDgfon_tuq4a0_Q2iIN8LyvUfSl5vCY_CXUERuJaqN46k8t69plYqAcoG3A1QSgNoisSgIy85gjPz-PqA_v4fMazdVmo_ku2KR5ACaVFU1SieyzfTwIhjybczBvBghGzYSQwYE0IwAnEQX5YHmSxwStGYJfWxYFnsGkNE7ysxGAd2ldgh8C3tMHSDv4Da6JQHUNGE8IbEOLmTgg3hxm3IB-Xv4LAE8yGGDOwM_EP_9L5T8QpZQgmL5jhR0G6bUgmUIIRwUfGjMSbMMFKCFe0nDLYdL6Y7ClFgjmVJE_gIzGaCdL8BWZgXqNln-JOyGM1Dc2kG20qHOquaXvd9m1buUHXbd9rlPow7dWEB7nXejzM-7lp-qaTc-UHJVVbK6VqXbey3ZlZtQp11-z7w6jqWbQSz8aHXQjX8y7lpfJEKw61krpuqmBGDPT5rvJQuu7GdSHRyuCJ6VvHngMOT08__y_jj6ncUyQ2kWFOYYL3QcPNs_s-If8LqzWHwTFfSDRHoU5CnRbPbh13Np2FOpWEj9_dJacXtCzUacMkoU4fpNdB_Q4AAP__i-L7ug">