https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96167
Bug ID: 96167
Summary: fails to detect ROL pattern in simple case, but
succeeds when operand goes through memcpy
Product: gcc
Version: 10.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: nok.raven at gmail dot com
Target Milestone: ---
inline void swap(int &x, int &y)
{
int tmp = x;
x = y;
y = tmp;
}
void foo(int (&x)[2])
{
swap(x[0], x[1]);
}
void bar(int (&x)[2])
{
int y[2];
__builtin_memcpy(&y, &x, sizeof x);
swap(y[0], y[1]);
__builtin_memcpy(&x, &y, sizeof x);
}
foo:
movl (%rdi), %eax
movl 4(%rdi), %edx
movl %eax, 4(%rdi)
movl %edx, (%rdi)
ret
bar:
rolq $32, (%rdi)
ret
https://godbolt.org/z/Tcz7YG