<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/76698>76698</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[clang] feature request: optimize multiple strcat() to stpcpy()
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
IAKOBVS
</td>
</tr>
</table>
<pre>
Since GCC 4.7.1,
void f(char *a, const char *b, const char *c)
{
strcat(a, b);
strcat(a, c);
}
is transformed into
f:
mov QWORD PTR [rsp-24], rbx
mov QWORD PTR [rsp-16], rbp
mov rbx, rdi
mov QWORD PTR [rsp-8], r12
sub rsp, 24
mov rbp, rdx
mov r12, rsi
call strlen
lea rdi, [rbx+rax]
mov rsi, r12
call stpcpy
mov rsi, rbp
mov rbx, QWORD PTR [rsp]
mov rbp, QWORD PTR [rsp+8]
mov r12, QWORD PTR [rsp+16]
mov rdi, rax
add rsp, 24
jmp strcpy
whereas Clang (trunk) does no such optimization:
f: # @f
push r14
push rbx
push rax
mov rbx, rdx
mov r14, rdi
call strcat@PLT
mov rdi, r14
mov rsi, rbx
add rsp, 8
pop rbx
pop r14
jmp strcat@PLT # TAILCALL
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyMVUtvozoY_TVmYzWCDxNgwSIP5aq6kdrbVnfWxjjBHYMZ23Ta-fUjQ8gDaGdYxInP9zjf8cGhxohjzXmGojWKth5tbal0dr_692H9_7OXq-IjexY14_ifzQaTRbwIEGyQv0X-qv98U6LABwQJK6nGCFYUwQYzVRuLh618usUQpKcy8br_go3VjFoESVcidxHhgGE8gtk1jOLtNSdhsNW0NgelK15gUVt1DR9QuLqUdU-l3rr1v28PT1v8-PKEUbTWprkDgqKta6fz92nKJDxYnsOb-Q6ujsML8ZcMkqFiALcZps37iqZxOJDPGjZ9w4H_GQigA8yICaNSnuSWvL7FJKd9biFcrqPo5llr-u5ozhMwYpb_pU_Dmo8xuVPSH2QcqzVL4qTAJBbWyeeke3FmcvojHrHt5XAq3FSjRfHVEb1WDR6MfVZgCPlZcs2pwRtJ6yNGkFjd1t8RpLhQ3OBaYdOyEqvGikr8olao-srWw-qsjhGEGBH_cNu9aU3Zj0pmgInfz-HjISfOnsFdjznXX3nNvdrEf9y_fFL9JPGZ7MQpX2ufjKZRzZl0D5x3xnJcn9LAEc8-TueX1f1-s9rvMfaKLCzSMKUez4LYJ0EcR3HglRkhLGRhWvgxoUmwTJcpi3KWwDKOclJw4okMfCB-4IO_DNMwWOSHgCQ5ARpAnBxIiojPKyrkQsq3aqH00RPGtDyLl8s08STNuTTdjQ7AnH0QgLvcdebi7_L2aBDxpTDWXCpYYWX3N9BnRFt84NS2mmPNf7TcWOekk9s4rlppRSP55VJ2zrRqeJu7316rZVZa2xjnTNgh2B2FLdt8wVSFYOd6n5a7RqtXziyCXTeKQbDrpvkdAAD__4-XwvM">