<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/136498>136498</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[LSR] Regression in array access with constant stride
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
abdimoallim
</td>
</tr>
</table>
<pre>
It appears LSR does not recognize that shift operations could be promoted to operate directly on 64-bit values instead of adding extra 32-bit truncation and sign-extension for ops on loop induction variables. E.g. direct 64-bit shifting compared to `lea r9d, [8*rcx]` then `movsxd r9, r9d` for `i*8` and `i<<3` respectively.
```llvm
%35 = trunc nuw nsw i64 %indvars.iv to i32
%shl = shl i32 %35, 3
%idxprom = sext i32 %shl to i64
%arrayidx = getelementptr inbounds i32, ptr %src, i64 %idxprom
```
[Godbolt test](https://godbolt.org/z/xe6d9Ks69) (timeout on Alive2).
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJxck82OrTYMx58mbKxBED4OLFjMR09V9a7mPkEgBlyFBCWGOXOfvkqYUasrRYoc_2P_HMcqBFos4iCaF9G8Zerg1flBjZo2p4yhLRud_hz-YlD7jsoH-PHzHbTDANYxeJzcYukXAq-KIaw0M7gdvWJyNsDkDqNhRNi92xyjBnZffgRNHic2n-AstPXTSAynMgcGIBsYlQY3g9Ka7AL4YK-gkknF_rBTygDKaoglPOGD0YZ4NDsPbg8xqnFuB7L6mJL4VJ7UaDDk8Ee-5F8A37kTfMw1uW1X_mIVbWFQge-1kK8gmpdOyGc_PUTzJtoCeEUbNZs7w0OD76MqitsicYi2ICGfu2hH1GRXr6J6reKRx7DjxHSi-cxF8RxXW1zLmHOLtmyqBkT1dlUN9vgAGz6A2hqEbMjqU_mQ0xlpqZLXlbCadCfuVElIUSJbdflJP2JHLg0--FsU9TFOW1865b36JP1IwgUZDW5oeWcPZEd3WB1SUvkK8SxG8FO0vvGuPP-v66vM5uVPp0dnGBgDx-eU3cq8B1E9C3kX8r5c_tz5Rcj7LyHvD2x1_3doeyF7ELJj2tAdHDv9bOhEKWSfZ3qodF_1KsOhvNVNeZOy77J16G-q7Lpez7Kci9tc1reyuFVdXZY4Vp2eMxpkIZuilkXZFXXT5c1tLqpmvOli0jM2KOoCN0Umj72JXBmFcOBQVm3dd5lRI5qQRklKix-QvELKOFl-iJeexmMJoi4MBQ7_hWFik2bwx8930bzBOy4eQ_rNZCE1AdQ0YQjwQbzC5GxgZRkCe9KYHd4Mvz0e8XqM-eQ2Ie_pK13b0-7dPzixkPdEF4S8f-Gfg_w3AAD__yLdSgQ">