[Bug tree-optimization/94416] New: passing a restricted pointer to a function can be assumed not to modify an accessed object
msebor at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Mon Mar 30 23:21:11 GMT 2020
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94416
Bug ID: 94416
Summary: passing a restricted pointer to a function can be
assumed not to modify an accessed object
Product: gcc
Version: 10.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: msebor at gcc dot gnu.org
Target Milestone: ---
In the test case below, the subtraction can safely be folded to zero because a
is a restricted pointer (as is effectively also b), *a is read, and if (a == b)
were true, the call g(b) couldn't also modify *a either via *(int*)b or by any
other means; as a result, a == b must either be false or g(b) cannot modify *a.
Clang folds the subtraction but GCC does not.
$ cat c.c && gcc -O2 -S -Wall -fdump-tree-optimized=/dev/stdout c.c
void g (void *);
int f (int * restrict a, void * /* restrict */ b)
{
int t = *a;
g (b);
return *a - t; // can be folded to zero
}
;; Function f (f, funcdef_no=0, decl_uid=1933, cgraph_uid=1, symbol_order=0)
f (int * restrict a, void * restrict b)
{
int t;
int _1;
int _7;
<bb 2> [local count: 1073741824]:
t_4 = *a_3(D);
g (b_5(D));
_1 = *a_3(D);
_7 = _1 - t_4;
return _7;
}
More information about the Gcc-bugs
mailing list