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

    <tr>
        <th>Summary</th>
        <td>
            SMUL idiom
        </td>
    </tr>

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

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

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

<pre>
    We already turn umul with overflow into the idiom. LLVM should do the same.

I understand this was previously done by @AZero13, but given they now plan to step away from LLVM after everything, I have volunteered to take over this issue in particular.

bool check_multiplication_overflow(int a, int b) {
    // Cast to long long to perform the multiplication
    long long result = (long long)a * (long long)b;

    // Check if the result is within the range of int
    if (result > INT_MAX || result < INT_MIN) {
        return true; // Overflow occurred
    }
    return false; // No overflow
}

This yields the IR targeted.

This code is a modified version of what was found in systemd's source code.


</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJxcU0tv8zYQ_DX0ZfEZEuXnQQfHqQEDSQq06QO9BCtxJbEfRRrkUob-fUFJedUHiyA5szPLWQxBt5aoFNsHsX1cYeTO-fLxlbDuwqpyaiz_IkDjCdUIHL2F2EcDd80duIF8Y9wdtGUH3BFopV2_hqenP58hdC4aBWo-CdjTWmQnkZ2uEK0iHxitAu50gDsGuHkatIvBjKCcJahGEJvs9A95lxdCnqGKDK0eyCa-Eay7w82gBXYQmG6Adxyh8a6fy2PD5IEG8iN32raJ4godDgSDM9EykSeV0Iw_afIyi9EhRAJt4YaedR0N-kV45ZyBuqP651sfDeub0TWydvbtvRNCHrRlwFQsLSohjyD2DyI7AQAIeRHyAmcMnAobZ9v5jx3cyDfO91OzvrMv4M_bnkI0DKJ4BCEPH_tCHhGEPP1_sxLFw2zgq4ZkA3Qz1VsI00vo1Kx5E21L4JpkZMHqJnF_lP8Fri-vb8-nv0Hsz2J__hR2nk-uL9_9p5-nKUXsI4ni4V3Or-9RcnUdvSf1rnb_uKwWXIMmfAW-uI8YJo_TdZGdXtNLjpqMCpOZ62_A6FtiUusvN2qnKNlG6J3SjSYFA_mgnU3G7x3ylM3GRatSJMIYmHol5D5AcNHXNFEslCtVFupYHHFFZb7fyHxz3O12q65ssrw-HopqS4gSs5oqxCzfFpnCrMibbKVLmcltVuS7_CD3m91aVmpbbY4yz3d1rg57scmoR23Wxgz92vl2NcW0zIt8W8iVwYpMmKZYSkv3OcRCyjTUvkygH1Vsg9hkRgcOnzSs2VD5-_MfT_PwrqI3Zcd8C6I4zT1uNXexWteuF_KSgMvnx827f6lmIS9TuSDkZdEzlPK_AAAA__8e4GhV">