From 3a7bf46a97e3d316a2d034ca622b68508bbe609b Mon Sep 17 00:00:00 2001 From: ebotcazou Date: Fri, 1 Jun 2012 17:03:19 +0000 Subject: [PATCH] PR middle-end/53501 * fold-const.c (fold_binary_loc): Refine previous change. testsuite/ * c-c++-common/restrict-2.c: Revert previous change. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gcc-4_7-branch@188119 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/ChangeLog | 5 +++++ gcc/fold-const.c | 30 ++++++++++++++++++------------ gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/c-c++-common/restrict-2.c | 2 +- 4 files changed, 28 insertions(+), 13 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 61b039243dc..8c5c03631e4 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2012-06-01 Eric Botcazou + + PR middle-end/53501 + * fold-const.c (fold_binary_loc): Refine previous change. + 2012-06-01 Oleg Endo Backport from mainline diff --git a/gcc/fold-const.c b/gcc/fold-const.c index f3fdf493944..26d43e41e82 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -10022,15 +10022,18 @@ fold_binary_loc (location_t loc, } } - /* Handle (A1 * C1) + (A2 * C2) with A1, A2 or C1, C2 being the - same or one. Make sure type is not saturating. - fold_plusminus_mult_expr will re-associate. */ - if ((TREE_CODE (op0) == MULT_EXPR - || TREE_CODE (op1) == MULT_EXPR) + /* Handle (A1 * C1) + (A2 * C2) with A1, A2 or C1, C2 being the same or + one. Make sure the type is not saturating and has the signedness of + the stripped operands, as fold_plusminus_mult_expr will re-associate. + ??? The latter condition should use TYPE_OVERFLOW_* flags instead. */ + if ((TREE_CODE (arg0) == MULT_EXPR + || TREE_CODE (arg1) == MULT_EXPR) && !TYPE_SATURATING (type) + && TYPE_UNSIGNED (type) == TYPE_UNSIGNED (TREE_TYPE (arg0)) + && TYPE_UNSIGNED (type) == TYPE_UNSIGNED (TREE_TYPE (arg1)) && (!FLOAT_TYPE_P (type) || flag_associative_math)) { - tree tem = fold_plusminus_mult_expr (loc, code, type, op0, op1); + tree tem = fold_plusminus_mult_expr (loc, code, type, arg0, arg1); if (tem) return tem; } @@ -10634,15 +10637,18 @@ fold_binary_loc (location_t loc, && (tem = distribute_real_division (loc, code, type, arg0, arg1))) return tem; - /* Handle (A1 * C1) - (A2 * C2) with A1, A2 or C1, C2 being the - same or one. Make sure type is not saturating. - fold_plusminus_mult_expr will re-associate. */ - if ((TREE_CODE (op0) == MULT_EXPR - || TREE_CODE (op1) == MULT_EXPR) + /* Handle (A1 * C1) - (A2 * C2) with A1, A2 or C1, C2 being the same or + one. Make sure the type is not saturating and has the signedness of + the stripped operands, as fold_plusminus_mult_expr will re-associate. + ??? The latter condition should use TYPE_OVERFLOW_* flags instead. */ + if ((TREE_CODE (arg0) == MULT_EXPR + || TREE_CODE (arg1) == MULT_EXPR) && !TYPE_SATURATING (type) + && TYPE_UNSIGNED (type) == TYPE_UNSIGNED (TREE_TYPE (arg0)) + && TYPE_UNSIGNED (type) == TYPE_UNSIGNED (TREE_TYPE (arg1)) && (!FLOAT_TYPE_P (type) || flag_associative_math)) { - tree tem = fold_plusminus_mult_expr (loc, code, type, op0, op1); + tree tem = fold_plusminus_mult_expr (loc, code, type, arg0, arg1); if (tem) return tem; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index c5dbcb2522f..9c7eabf6bd3 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,9 @@ 2012-06-01 Eric Botcazou + * c-c++-common/restrict-2.c: Revert previous change. + +2012-06-01 Eric Botcazou + PR ada/53517 * gnat.dg/lto14.adb: Skip on Solaris. diff --git a/gcc/testsuite/c-c++-common/restrict-2.c b/gcc/testsuite/c-c++-common/restrict-2.c index 42ed398f670..3f71b77b9ce 100644 --- a/gcc/testsuite/c-c++-common/restrict-2.c +++ b/gcc/testsuite/c-c++-common/restrict-2.c @@ -10,5 +10,5 @@ void foo (float * __restrict__ a, float * __restrict__ b, int n, int j) /* We should move the RHS of the store out of the loop. */ -/* { dg-final { scan-tree-dump-times "Moving statement" 10 "lim1" } } */ +/* { dg-final { scan-tree-dump-times "Moving statement" 11 "lim1" } } */ /* { dg-final { cleanup-tree-dump "lim1" } } */ -- 2.11.0