From 194ac52ab4a35f22abafaec46ac22ac303a61ab8 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Thu, 24 Apr 2008 18:08:11 +0200 Subject: [PATCH] re PR tree-optimization/36008 (Function produces wrong results when inlined.) PR tree-optimization/36008 * fold-const.c (try_move_mult_to_index): If s == NULL, divide the original op1, rather than delta by step. * gcc.c-torture/execute/20080424-1.c: New test. From-SVN: r134634 --- gcc/ChangeLog | 6 ++++ gcc/fold-const.c | 2 +- gcc/testsuite/ChangeLog | 5 +++ .../gcc.c-torture/execute/20080424-1.c | 31 +++++++++++++++++++ 4 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.c-torture/execute/20080424-1.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 31bac1edbcd..5751c5d10df 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2008-04-24 Jakub Jelinek + + PR tree-optimization/36008 + * fold-const.c (try_move_mult_to_index): If s == NULL, divide + the original op1, rather than delta by step. + 2008-04-22 Antoniu Pop Sebastian Pop diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 4015f62e5cd..a4d5760b861 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -6919,7 +6919,7 @@ try_move_mult_to_index (tree addr, tree op1) else { /* Try if delta is a multiple of step. */ - tree tmp = div_if_zero_remainder (EXACT_DIV_EXPR, delta, step); + tree tmp = div_if_zero_remainder (EXACT_DIV_EXPR, op1, step); if (! tmp) continue; delta = tmp; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index fa3768efc2e..01c423c6667 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2008-04-24 Jakub Jelinek + + PR tree-optimization/36008 + * gcc.c-torture/execute/20080424-1.c: New test. + 2008-04-24 Ira Rosen Richard Guenther diff --git a/gcc/testsuite/gcc.c-torture/execute/20080424-1.c b/gcc/testsuite/gcc.c-torture/execute/20080424-1.c new file mode 100644 index 00000000000..4916d907565 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/20080424-1.c @@ -0,0 +1,31 @@ +/* PR tree-optimization/36008 */ + +extern void abort (void); + +int g[48][3][3]; + +void __attribute__ ((noinline)) +bar (int x[3][3], int y[3][3]) +{ + static int i; + if (x != g[i + 8] || y != g[i++]) + abort (); +} + +static inline void __attribute__ ((always_inline)) +foo (int x[][3][3]) +{ + int i; + for (i = 0; i < 8; i++) + { + int k = i + 8; + bar (x[k], x[k - 8]); + } +} + +int +main () +{ + foo (g); + return 0; +} -- 2.30.2