[Bug middle-end/82918] New: No aliasing is possible on non equal pointers
antoshkka at gmail dot com
gcc-bugzilla@gcc.gnu.org
Thu Nov 9 15:41:00 GMT 2017
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82918
Bug ID: 82918
Summary: No aliasing is possible on non equal pointers
Product: gcc
Version: 8.0
Status: UNCONFIRMED
Keywords: alias, missed-optimization
Severity: normal
Priority: P3
Component: middle-end
Assignee: unassigned at gcc dot gnu.org
Reporter: antoshkka at gmail dot com
Target Milestone: ---
Following code
struct array {
int data[3];
};
void foo2(array& value, const array& value2) {
if (&value == &value2) return;
value.data[0] = value2.data[0];
value.data[1] = value2.data[0];
value.data[2] = value2.data[0];
}
produces the following assembly:
foo2(array&, array const&):
cmp rdi, rsi
je .L1
mov eax, DWORD PTR [rsi]
mov DWORD PTR [rdi], eax
mov eax, DWORD PTR [rsi] <=== This is not required
mov DWORD PTR [rdi+4], eax
mov DWORD PTR [rdi+8], eax
.L1:
rep ret
GCC already understands that value.data[1] and value.data[2] do not alias with
value2.data[0].
However GCC assumes that value1.data[0] may alias value2.data[0], which is not
possible, because of `if (&value == &value2) return;`
Please add the optimization, as it affects many cases, especially C++ assign
and move assign operators, where checking for `this == &rhs` is a common
pattern.
More information about the Gcc-bugs
mailing list