I'm about to backport one patch (a fix for PR48189) to 4.6 branch. Bootstrapped/regtested on x86_64-linux, acked by Jakub on IRC. Will commit soon.
ChangeLog: 2013-04-04 Marek Polacek <pola...@redhat.com> Backported from mainline 2013-01-09 Steven Bosscher <ste...@gcc.gnu.org> Jakub Jelinek <ja...@redhat.com> PR tree-optimization/48189 * predict.c (predict_loops): If max is 0, don't call compare_tree_int. If nitercst is 0, don't predict the exit edge. testsuite/ChangeLog: 2013-04-04 Marek Polacek <pola...@redhat.com> Backported from mainline 2013-01-09 Jakub Jelinek <ja...@redhat.com> PR tree-optimization/48189 * gcc.dg/pr48189.c: New test. --- gcc/predict.c.mp 2013-04-04 11:59:59.816219085 +0200 +++ gcc/predict.c 2013-04-04 12:00:13.418263854 +0200 @@ -1,6 +1,6 @@ /* Branch prediction routines for the GNU compiler. Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010 - Free Software Foundation, Inc. + 2011, 2012, 2013 Free Software Foundation, Inc. This file is part of GCC. @@ -966,7 +966,8 @@ predict_loops (void) if (TREE_CODE (niter) == INTEGER_CST) { if (host_integerp (niter, 1) - && compare_tree_int (niter, max-1) == -1) + && max + && compare_tree_int (niter, max - 1) == -1) nitercst = tree_low_cst (niter, 1) + 1; else nitercst = max; @@ -988,6 +989,11 @@ predict_loops (void) else continue; + /* If the prediction for number of iterations is zero, do not + predict the exit edges. */ + if (nitercst == 0) + continue; + probability = ((REG_BR_PROB_BASE + nitercst / 2) / nitercst); predict_edge (ex, predictor, probability); } --- gcc/testsuite/gcc.dg/pr48189.c.mp 2013-04-04 11:59:45.581173690 +0200 +++ gcc/testsuite/gcc.dg/pr48189.c 2013-04-04 11:59:36.446144550 +0200 @@ -0,0 +1,13 @@ +/* PR tree-optimization/48189 */ +/* { dg-do compile } */ +/* { dg-options "-O --param max-predicted-iterations=0" } */ + +struct S { int s[8]; }; + +void +foo (int *x, struct S *y) +{ + int i; + for (i = 0; y[i].s[i]; i++) + *x++ = y[i].s[i]; +} Marek