<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/60941>60941</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[Missing optimization] Atomic add or subtract a pointer
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
youngbe
</td>
</tr>
</table>
<pre>
src:
```c
#include <stdatomic.h>
#include <stdint.h>
_Atomic(uintptr_t) y;
_Atomic(uint8_t *) x;
void ppp()
{
++x;
++y;
}
```
gcc-12 -Ofast:
```
ppp:
lock addq $1, x(%rip)
lock addq $1, y(%rip)
ret
```
clang 15.0.6 -Ofast:
```
ppp: # @ppp
.Lppp$local:
movq .Lx$local(%rip), %rax
.p2align 4, 0x90
.LBB0_1: # =>This Inner Loop Header: Depth=1
leaq 1(%rax), %rcx
lock cmpxchgq %rcx, .Lx$local(%rip)
jne .LBB0_1
lock incq .Ly$local(%rip)
retq
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyMVN2OmzwQfZrhxgqyx5CECy7ys9H3Sal60_vIGAe8JTaxzZb06StY8tPt7mqtKGiYc-acsfEI73VllMohXUO6jUQXauvyi-1MVaiosOUl904CXwHdAl3BnL7-5BQj10Y2XakI8I0PpQj2pGVcA3_6AKFNeEgfViMBcNlpE9rgDgEwIxfg6_cAy0MggKsB0t8gL1aXpG1bwCVgNskupiQhhACuAdd3wvTiLgKL7Zv-pnD8r6ScMSSz70fhw79b8RoO-tfUoNlY-ZOIsjyP-gkD3JB-dJg63d58fgS9vA91KnxiVDbCVISlMY3nX7JLvrAAOYGEDoSRGe_HrU4aK0XzV8sn-zK0QOJ9f8s_doEbMgSiv1PiFkWjK0OSIUv7jF5F1mt6YF-wONrjW-BPP2rtyf_GKEf21rbkPyVK5YYSW9WGGviWPey5EqNXNjkU_YND2b85nGnJU9vLujpfQbj5sNcb_9kocu3m3aLayDOJ95fPyzgVzm8OMipzXmY8E5HK2XyxYDzDZRbVeaZEJguWLMojTSiTyYJmZXoUNF3ikc8x0jlS5BSR0yVlmMWpFCzFBctUuqRJwSCh6iR0EzfNyym2roq0953K5zRLWNSIQjV-HBmIRv0iYxIQhwni8oEzK7rKQ0Ib7YO_Vwk6NOOs-aa916Yitg36pH-LoK2BdEteL_twGYh1xHdFcEIGIkhrtQnKRZ1r8jqE1g9fHu4Ad5UOdVfE0p4Ad4PS9Ji1zj4rGQB3oz8PuBv9_wkAAP__MZpS_Q">