From 7b9be7003d3272d2faac9f39a5a6835d583307e0 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Fri, 16 Mar 2018 09:06:41 +0100 Subject: [PATCH] re PR tree-optimization/84841 (ICE: tree check: expected ssa_name, have real_cst in rewrite_expr_tree_parallel, at tree-ssa-reassoc.c:4624) PR tree-optimization/84841 * tree-ssa-reassoc.c (INTEGER_CONST_TYPE): Change to 1 << 4 from 1 << 3. (FLOAT_ONE_CONST_TYPE): Define. (constant_type): Return FLOAT_ONE_CONST_TYPE for -1.0 and 1.0. (sort_by_operand_rank): Put entries with higher constant_type last rather than first to match comments. * gcc.dg/pr84841.c: New test. From-SVN: r258586 --- gcc/ChangeLog | 10 ++++++++++ gcc/testsuite/ChangeLog | 3 +++ gcc/testsuite/gcc.dg/pr84841.c | 9 +++++++++ gcc/tree-ssa-reassoc.c | 14 +++++++++++--- 4 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/pr84841.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 060d7e5b96a..57e92ac762a 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,13 @@ +2018-03-16 Jakub Jelinek + + PR tree-optimization/84841 + * tree-ssa-reassoc.c (INTEGER_CONST_TYPE): Change to 1 << 4 from + 1 << 3. + (FLOAT_ONE_CONST_TYPE): Define. + (constant_type): Return FLOAT_ONE_CONST_TYPE for -1.0 and 1.0. + (sort_by_operand_rank): Put entries with higher constant_type last + rather than first to match comments. + 2018-03-15 Sandra Loosemore * config/nios2/nios2.md (movsi_internal): Fix thinko in diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index dbd76400253..4c03ff22ea7 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,8 @@ 2018-03-16 Jakub Jelinek + PR tree-optimization/84841 + * gcc.dg/pr84841.c: New test. + PR c++/84874 * g++.dg/cpp2a/desig7.C: New test. diff --git a/gcc/testsuite/gcc.dg/pr84841.c b/gcc/testsuite/gcc.dg/pr84841.c new file mode 100644 index 00000000000..4f7422a659f --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr84841.c @@ -0,0 +1,9 @@ +/* PR tree-optimization/84841 */ +/* { dg-do compile } */ +/* { dg-options "-O2 -fassociative-math -frounding-math -fno-signed-zeros -fno-trapping-math -fno-tree-forwprop" } */ + +double +foo (double x) +{ + return -x * 0.1 * 0.1; +} diff --git a/gcc/tree-ssa-reassoc.c b/gcc/tree-ssa-reassoc.c index f41b1207ed8..0e59bb595ea 100644 --- a/gcc/tree-ssa-reassoc.c +++ b/gcc/tree-ssa-reassoc.c @@ -470,7 +470,8 @@ get_rank (tree e) /* We want integer ones to end up last no matter what, since they are the ones we can do the most with. */ -#define INTEGER_CONST_TYPE 1 << 3 +#define INTEGER_CONST_TYPE 1 << 4 +#define FLOAT_ONE_CONST_TYPE 1 << 3 #define FLOAT_CONST_TYPE 1 << 2 #define OTHER_CONST_TYPE 1 << 1 @@ -482,7 +483,14 @@ constant_type (tree t) if (INTEGRAL_TYPE_P (TREE_TYPE (t))) return INTEGER_CONST_TYPE; else if (SCALAR_FLOAT_TYPE_P (TREE_TYPE (t))) - return FLOAT_CONST_TYPE; + { + /* Sort -1.0 and 1.0 constants last, while in some cases + const_binop can't optimize some inexact operations, multiplication + by -1.0 or 1.0 can be always merged with others. */ + if (real_onep (t) || real_minus_onep (t)) + return FLOAT_ONE_CONST_TYPE; + return FLOAT_CONST_TYPE; + } else return OTHER_CONST_TYPE; } @@ -504,7 +512,7 @@ sort_by_operand_rank (const void *pa, const void *pb) if (oea->rank == 0) { if (constant_type (oeb->op) != constant_type (oea->op)) - return constant_type (oeb->op) - constant_type (oea->op); + return constant_type (oea->op) - constant_type (oeb->op); else /* To make sorting result stable, we use unique IDs to determine order. */ -- 2.30.2