Consider:
void abort (void) __attribute__ ((noreturn));
union node
{
int dummy;
union node *ptr;
};
extern void bar (union node *tree);
extern const int global_constant;
void
foo (union node *p)
{
if (global_constant == 1)
abort ();
bar (p->ptr);
if (global_constant == 1)
abort ();
}
Note that if we get to the second "if", we know that global_constant != 1,
so we could remove the second "if".
The tree optimizers do not take this opportunity, but the RTL optimizers do.
--
Summary: tree optimizers do not know that constant global
variables do not change
Product: gcc
Version: unknown
Status: UNCONFIRMED
Keywords: missed-optimization, TREE
Severity: enhancement
Priority: P2
Component: tree-optimization
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: kazu at cs dot umass dot edu
CC: gcc-bugs at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19789