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

    <tr>
        <th>Summary</th>
        <td>
            Missed optimization: (y != 0 && x > (unsigned)(-1) / y) (multiplication overflow check)
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

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

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

<pre>
    ```c
#include <limits.h>
#include <stdbool.h>

bool func1(unsigned long long x, unsigned long long y)
{
    return x > (ULLONG_MAX / y);
}

bool func2(unsigned long long x, unsigned long long y)
{
    return y != 0 && x > (ULLONG_MAX / y);
}

bool func3(unsigned long long x, unsigned long long y)
{
    unsigned long long res;
    return __builtin_umulll_overflow(x, y, &res);
}
```

Expected result: All three functions produce the same code.

Actual result: func1() and func3() optimize to same code, but func2() had a redundant (y != 0) check that is not optimized out.

x86-64 clang with "-Os" option (tested in Compiler Explorer, a.k.a. godbolt.org)

```x86asm
func1:
 movq    %rsi, %rax
        mulq    %rdi
        seto    %al
 retq

func2:
        testq   %rsi, %rsi
        je .LBB1_1
        movq    %rsi, %rax
        mulq    %rdi
        seto %al
        retq
.LBB1_1:
        xorl    %eax, %eax
 retq
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysVEtz4jgQ_jXypQuX3cKvgw-QhL1kdk5btTdKWAJrRraIHomzv35LfgBJuE1UlAB199dfP5m18tQLUZNsS7LHiHnXalM_DWeljTBJFR00f69JnkyfhiSPJNkQpLJvlOcCCH1QspPOxi2hT_fE1vGD1upWPt7hEY6-b1KCpe9HIhyU7k_TNRB8gDvv7wSrGafYTj8AAIxw3vQwAKFPQLD85_n5599_7X9s_gWCu8mKbhfDx7tM8DuZvAPBlNBHSIBgTjD_M270W7jd0TTCXpzf0N_vD14qJ_u977xSaq9fhTkq_UawHJ2-h4tgHuzv8l-a5jacp-EsGid48OqVI3QDG6XAtUaIMUwndW_hbDT3jQDXCrCsE9BoLuJboE3jPFM3MEsnEayA9fySs_Bfn53s5H8CnL7CBfoH7y6FD4ot48DACO57znoXanUtY1BoWtH8BtcyB9JCr90Fm4P27gPFocxX-RoaxfoTvEnXAkFc_bQEcbTSfcB3woZ8yB4edHeWShhYxi8wZPHvmMVw0vyglYu1OV0L-zHNQ5kz202PUzLorAKdfn0JpSWYGSunumWGDdeih9N5ddHi8qPMCqdnGVOzyAj3cstkSuTF6XxCfC9ffNtP-L8ExM_bbbpPP3H6Hua3tOdzZb84_sx80EbNqIINs29x8X0T_lKCiNeUV7RikajTgqZYFbSsorbOaFmUSZqmdE3Zep0cj1WBTZUXRXXMqnwdyRoTXKdpmiY0y7GKs0IUJccEeUNZxShZJ6JjUsVKvXahDSJprRd1mmZ5SSPFDkLZcY0j9uINRilBDFvd1MFodfAnS9aJktbZK4yTTon6h7Q2tPDUzCw0ZxiqD_3_ZY0tyyR0JJarNAzIss-CvPPKybOSzYgHywKZhohgFXmj6ta5sw25xx3B3Um61h_iRncEd4Hj_LU6G_1LNI7gbozMEtzNob_W-H8AAAD__yd28EU">