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

    <tr>
        <th>Summary</th>
        <td>
            Additional missing known bits info for x * x
        </td>
    </tr>

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

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

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

<pre>
    https://github.com/llvm/llvm-project/issues/48027 outlines that `x * x` will always have bit 1 cleared. I have also discovered three additional tricks that can resolve additional unknown bits:

A: If bit 0 of the input is set, then bit 2 of the output must be cleared.
B: If bit 0 of the input is cleared, then bit 3 of the output must be cleared.
C: If the input % 4 == 2, then bits 3 and 4 of the output must be cleared.

Alternatively, `A` and `C` can be rephrased as:

A: If bit 0 of the output is set, then bit 2 of the output must be cleared.
C: If bit 2 of the output is set, then bits 3 and 4 of the output must be cleared.

This is because these are the only possible results for `(x * x) % 32`:
```
00: 00000
01: 00001
04: 00100
09: 01001
10: 10000
11: 10001
19: 11001
```

The transformations appear to be valid in alive2:
A: https://alive2.llvm.org/ce/z/wip7Ue
B: https://alive2.llvm.org/ce/z/5etB7b
C: https://alive2.llvm.org/ce/z/BNzk7L

Clang 20.1.0 doesn't optimize these patterns out currently https://godbolt.org/z/M6rj4cG3T.


</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJykVEtv4zYQ_jXUZVCDHL2cgw6OUxcB-gCK7aU3Shxb3NCkQFL2Or--oB7rZAs029YgYM3r-zgPjgxBnyxRw8pHVj5lcoy9882fP_7-vP8NOS-z1qlb08c4BJbvGB4YHk469mO76dyZ4cGYy_r3w-DdZ-oiw4MOYaTA8FBsOdbgxmi0pQCxlxFYxb8Awx18YRWHqzYGpLnKW4BeXghaHUFAZ0h6Uht4nrXSBAdKh85dyJOC2HsikErpqJ2VBqLX3cvC0EkLnoIzl3cuo32x7moTw5QNT2fH8h08HydaDu4IsSfQdhgj6ACBIsN90k1hgKuHG2NyOY8hQktfr8v47vEfARfHd6D5x6D7BfSOxbCEAlj-xPInwLd4AXKQVkHxMWzK30TyVkZ9IXNLMKziu9SYBMEqvk_fqaAtgaeh9zKQAvlBARfK_1bB_RvEb93_jvjv0v3U65BAWurkGCgFBALpaQ615gaDC0G3JqUbRhMDHJ1PlWC4XecWH6b655jUcyEqvhy-40kHPP2SJFZJJKmYJTHbHiZJzDYxxYklTohVmmyTp1g837JNSRFEL204On-WadoDyGEg6SG6VIOLNFqBtiCNvhDOV54a9_5pz-ZNes0b508MDx0xPLwyPFz1UP9B63x_d1hJ8bFu16Z-d9jjr68v9c9zdnsj7QmQb8SGg3IULMM6ghuiPuvXtYWDjGmQQ2o_dKP3ZKO5fcN4cqp1Ji5sieiXyn8uup_yT8t8ZKrJ1UP-IDNqRF3mdV7XRZX1zbauqeuwFUdEmYtCUrXdirJVclvXHEWmG-RY8hq3KBCx2tRCkeqkaElVtCVkBaez1OZrwtm0JhtRCl7kmZEtmTBtYkRLV5isDDEtZt9MG7YdT4EV3OgQwx0m6mio2d0X3VmHoO0J7usOtD26aZCXEc5Gb_7HXl_ufGnwrwAAAP__rw3zOQ">