Testcase:
/* { dg-do compile } */
/* { dg-options "-O2 -fdump-tree-optimized" } */
static const char f[3] = "?";
int foo()
{
int i = 0;
return f[i] != '?';
}
/* { dg-final { scan-tree-dump "return 0;" "optimized" } } */
/* { dg-final { cleanup-tree-dump "optimized" } } */
Problem is two-fold, for once, fold_const_aggregate_ref does not handle
STRING_CST, second, evaluate_stmt triggers the likelyvalue == CONSTANT
path only, and ccp_fold does not call fold_const_aggregate_ref.
RTL handles this. I have a patch.
--
Summary: store ccp does not handle constant aggregate refs of
STRING_CSTs
Product: gcc
Version: 4.2.0
Status: UNCONFIRMED
Keywords: missed-optimization, TREE
Severity: enhancement
Priority: P3
Component: tree-optimization
AssignedTo: rguenth at gcc dot gnu dot org
ReportedBy: rguenth at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=27497