https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102951
Bug ID: 102951
Summary: failure to optimize MIN_EXPR of subobject addresses of
the same object
Product: gcc
Version: 12.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: ---
GCC fails to fold the MIN_EXPR below to the lower address. The test case
affects C because the C front end emits a MIN_EXPR but not C++ because the C++
front end emits an if statement.
$ cat z.c && gcc -O2 -S -Wall -fdump-tree-optimized=/dev/stdout z.c
extern int a[];
void f (void)
{
int *p1 = &a[1];
int *p2 = &a[2];
int *d = p1 < p2 ? p1 : p2;
*d = 0;
}
;; Function f (f, funcdef_no=0, decl_uid=1979, cgraph_uid=1, symbol_order=0)
void f ()
{
int * d;
<bb 2> [local count: 1073741824]:
d_1 = MIN_EXPR <&a[2], &a[1]>; // the two statements can be folded into
*d_1 = 0; // MEM[(int *)&a + 4B] = 0
return;
}