<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/60989>60989</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[optimization] fold the shift into the offset of memory access instruction
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
vfdff
</td>
</tr>
</table>
<pre>
* test: https://gcc.godbolt.org/z/68zEq8x81
```
void update (uint32_t *histogram, uint32_t *records, uint32_t num_records)
{
for (uint32_t i = 0; i < num_records; i++)
histogram[records[i]] += 1;
}
```
* gcc
```
.L3:
ldr w3, [x1], 4
ldr w2, [x0, x3, lsl 2]
add w2, w2, 1
str w2, [x0, x3, lsl 2]
cmp x1, x4
bne .L3
```
* llvm
```
.LBB0_2: // =>This Inner Loop Header: Depth=1
ldr w9, [x1], #4
subs x8, x8, #1
lsl x9, x9, #2 // the shift operand can be fold into address offset ?
ldr w10, [x0, x9]
add w10, w10, #1
str w10, [x0, x9]
b.ne .LBB0_2
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUVE1vgzgQ_TXDZdTIHocABw6hNNqVetx7xYcJXgFmbdOm_fUrOx8tVdPVImQb-83zzLxhKmvVcZIyh7iAuIyqxfXa5K9d23VRrdv3HGiPTloHYo-9c7MFsQc6AB2OTbM56rbWg9tocwQ6fAAddunH0z_pKeXASmB72LHLGz5ftWpxmdvKSQRKFzU5QS8Ogfa9sk4fTTUCPeLXAyMbbVq72p6W8eW2n12uSorzArHTZkWvEESJDEQRlo8re78JVIQ3uzIgfvoTF1doXCiIS4hL9GhRIgdRXG8vf4z4MtIej03zI2LzLHxObxf7Z2hNmN-EDxvi4sT9xfSI2wvwhqArgvnFKRgMdkDyBivSqm2_mJzHi0xo3f-ma8Y5zCcekNv1aT1J9JH9npNheB3vJKUo2Av5qvuP51yMXmAQT3_1yuKf0yQNPms94x-yaqXxLKWcXQ-i5HcSnX1PNJC4hmSX2oZI0xBpejnmX5xYk9rhnJlAeh6BBP3kt-sl2l51DvUsTTW12FQT1hI7PbSoJqe9bkZai7rrrHQI4nAnBs7W4mX3S-AMvVqQ-JaWWzn8QllvJukxV6nWMkZtLtpMZFUkc75LEkFM8Djq83Qbb3cZEzKpkiZOu5rxNE1kkshU7KSoIpUTI8GIYs54KuIN55w6ytIslbxumIAtk2Olho2vHt96ImXtIvMdy9IsGqpaDjY0NKJJvmE4BPIFHJnc2zzUy9HClg3KOvvJ4pQbQifUs1Oj-qic0pP_2YMUn0IFUfznRRDd4ShHbd6xahovlJqsM0vjzaPFDPm3vqlcv9SbRo9Ah_ADnKeH2ei_ZeOADsFl67upD-nfAAAA___Sw38o">