aboutsummaryrefslogtreecommitdiff
path: root/gcc/tree-ssa-reassoc.c
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2018-03-16 08:06:41 +0000
committerJakub Jelinek <jakub@redhat.com>2018-03-16 08:06:41 +0000
commit883204452b19b92cf969590986bdc3dd391291ca (patch)
tree403b3c0cc2e831ced8bc874ee678a2f81afae208 /gcc/tree-ssa-reassoc.c
parent5f0887476adae7adbd12ce4d72af098eda0b4895 (diff)
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. git-svn-id: https://gcc.gnu.org/svn/gcc/trunk@258586 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/tree-ssa-reassoc.c')
-rw-r--r--gcc/tree-ssa-reassoc.c14
1 files changed, 11 insertions, 3 deletions
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. */