<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/62808>62808</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Missed optimization opportunity: merging offset calculations for large objects
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
plabath
</td>
</tr>
</table>
<pre>
Given code like:
```
struct X {
int a;
int x[1<<30];
int b;
int q;
int c;
};
void f(X&x) {
x.a = 42;
x.b = 47;
x.c = 44;
}
```
clang/llvm will produce:
```
movl $42, (%rdi)
movabsq $4294967300, %rax # imm = 0x100000004
movl $47, (%rdi,%rax)
movabsq $4294967308, %rax # imm = 0x10000000C
movl $44, (%rdi,%rax)
retq
```
There's an obvious opportunity to merge the two movabsq instructions. Gcc takes advantage of it, and produces:
```
movabsq $4294967300, %rax
movl $42, (%rdi)
movl $47, (%rdi,%rax)
movl $44, 8(%rdi,%rax)
ret
```
Godbolt link: https://godbolt.org/z/89ejhxo9P
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJykVE1v4yAQ_TXjy6gRHn8ffGgTpaeV9rCHXjGQmBabFHCa9tevbKcfadpVdhdZRjyGmTdvBrj3etsrVUN2A9kq4kNorat3hjc8tFFj5XN9q_eqR2GlQqMfFCTXwFbAriFnx29a-uAGEfAOobiZEdR9QA7J6xJxQg6Q3cSQLCFZJgyy1ZlBc4Y8niHiDYHi3cP831stcQNU3gHlB6DqAyVEPCw4QrLClE68HhbNDBefYDHD6UnErxQQhvdboLUx-w6ftDG4c1YO4lvJ8Dg6uzfjDJSmBLREoBIoc1IDVWemvPGPs2mVVnmRMDYfyRw_4OkASlB33ZQAO8RsHun30YtP0Zez24tolH9JY_k9jfRCGk6Fxy-V_dUqp4AKj7xH2-y1HTza3c66MPQ6PGOw2Cm3VRhaheHJvmWk-7mRte39Am-FwMAflEcu97wPfKvQblCHkSDv5WuF_QUl_lPd_qcf_qV4p0qXl0n9ZYLz_9bKxpqARvcPkFxjG8Ju0oTWQOvtvLuwbrweL0DrslL37cFWPyNZJ7JKKh6pOs7LNGNVnsdRWwveSCIhYlWwsqiKXBRZRvlG5qXkSspI18QoYVlcxRnFLF4oKrM05U1T5DJOVQYpUx3XZjHexzF2pL0fVJ1TycrI8EYZP717RL16wmkTiMZn0NXjmatm2HpImdE--HcvQQej6h_aeyXR7oLu9Asf--Vjg40ijA2m-y3azcargIIbMZjJ0uPGOjR8bEDb3CsRfDQ4U3-STYd2aBbCdsdH5Thd7ZwdzwCtJ9IeaD0l9TsAAP__LIuPjA">