<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/55016>55016</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
failed to fold shift amount offset into shift of a constant, part 2
</td>
</tr>
<tr>
<th>Labels</th>
<td>
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
rotateright
</td>
</tr>
</table>
<pre>
Forking this off from #54890 - that handled a shift-left variant, but there's a similar shift-right fold that could be added:
https://alive2.llvm.org/ce/z/qzh4oK
define i32 @src(i32 %x, i32 %c, i32 %addc) {
%a = add i32 %x, -1
%r = ashr exact i32 -2, %a
ret i32 %r
}
define i32 @tgt(i32 %x, i32 %c, i32 %addc) {
%r = ashr i32 -4, %x
ret i32 %r
}
This should be generalized for other constant values, and it should also work in the more common case of a positive shift constant with "lshr".
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJydU8GSmzAM_Rpz0SQDBgIcOOw2k0uv_QEDArw1OLVFNt2vrwyhmx460-kMYAtJT8-8R2O7n_XFuu96HoBG7cH2PfTOTiBkmmdlFcOBE4pgVHNnsAMFftQ9HQz2BDfltJpJyC_QLMSF6FDIwocqPWmj3KPa6WEk6K3pNrTWLrxtEFTXYSfSFxDxWcQvI9HVcyjkhS9l9A3l0ZjbdLRu4Dctw18--P7xMWb269a0PTvs9YygUwkii71rhSzXQOb3QPCxb5_2PJzDCkTxumHA-hZEeg7E4Ln9kDyVuK3Ejw7wrlpaKw8y1AWAvdIh7RjuQbU4_50zDfS_nJ8IrVSyB5X7P1P5FtT3467LgDM6_v4fLHlvHdigLcs2e2LBWXizoA9D2Bagae9Uxlt4Z0OBnoMdYLIOuW2a7Ayt8sgGY3NcrdfE2m7u-IR91zQyRWn4ILwco65OuyqtVESaDNa90sGDZDcrbd1qsgv3snN9OOTM2S2xjtqxA9ercgQyWpyp_zTawHOX5sg8OQh2eyyHq7Nv2HLzRXu_nviS53FyisY6K_osy1A16akq8jTp2kYFrhiXnUqKODKqQeNrkb-K_BzpWsZSxplMkjxP8_JYZkWcYXXKT21bFmXJBsCJz_fb7pGrVw7NMnhOGu3JfyaV93qYEXd8tdBoXe0sKcL1d4tWyvXK9xeHGS_q">