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

    <tr>
        <th>Summary</th>
        <td>
            failing to move index addition to constant table pointer
        </td>
    </tr>

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

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

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

<pre>
    [Two LLVM IR functions](https://godbolt.org/z/3MsPx7e5e)

Here are two IR functions implementing this pseudocode:
```
def somefunction(x):
    return switch.table[x - 15]
```

When `somefunction2` is compiled the `-15` is moved to the constant table pointer, rather than doing an operation at runtime. Great.

This doesn't happen with `somefunction1`. Presumably because the compiler wants to maintain the same 8-bit wraparound behavior, so wants to do the arithmetic in 8 bits. But that behavior is irrelevant, as can be determined by either the `llvm.assume` or the size of the table. 
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJxtU1Fv2yAQ_jX2yykWxrHjPPihXdVtUitVU7U9gznHbNhYgJO0v34HybqqamQc7g6--74PLK166bL69vlk4eHh5yN8_wHDOvdB29ln9V3G2zGExWfVTcbv6TlYJa0JhXUHil5pVI_-6bzDGjO-z9hdxm4u72_oEASNQNjvYUFPi8EJ56DnA4RRe1g8rsr2VmFsdAFp2PVJocIBvJ3wHwoRO8eG_5YD_RyG1c3gTzr0YxGENEjSzrCBso5aPsO9vH-NOAPl3nfgFANx6-20aIOKmGJcsyGwS2Wyx5i2qdKTsiDmAKkvLFbPAV3Gv4ATVHe0SMygbNRME7sg5akNiABuJS8mLOCrQxGK98yeoz3KoifFuwCjWBaiSgrHj3xLigt4cujXiSi8gMRerB6v7JIIByei6CPnSRBBGqnsxYTQbqQOcHJiEc6usyKAURy1TSK8_b9VXRQLRywmDLoHgmmBdvsCbtcQpYa33dEp7RwaPBJAxBJkKlkgERSSR5OeyUb5AqivRiWfjTlOhfCkBqPf9lLw-hXBDmmenC4gx65smrphTVuxXHWV2ld7kQcdDHaD0CZdM5uOi5gqPINQSifzKf35weWrM92Hq0_0VlmQlRREdte_zeLsb-xJ2r0muuhpUrcVb_Oxw127R1nKHSUGyRuxrSRrGj6wvi_7EnMjJBofP8GM8xlPkCBoThc21x1nnJes5JxVVc0K1g5boRqGZd8MW1ZlW4Z0kKZIZtE3mbsuUZLrwVPRaE9n8lYkN_VhRkztCF-sYbSum_QflDgPGo3KU_8u8f8LrMpZFg">