public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r10-10766] tree-optimization/105173 - fix insertion logic in reassoc
@ 2022-05-27 13:15 Richard Biener
0 siblings, 0 replies; only message in thread
From: Richard Biener @ 2022-05-27 13:15 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:84ebfc7558d23c5262d35740d1d495bd0884a58c
commit r10-10766-g84ebfc7558d23c5262d35740d1d495bd0884a58c
Author: Richard Biener <rguenther@suse.de>
Date: Wed Apr 6 11:43:01 2022 +0200
tree-optimization/105173 - fix insertion logic in reassoc
The find_insert_point logic around deciding whether to insert
before or after the found insertion point does not handle
the case of _12 = ..;, _12, 1.0 well. The following puts the
logic into find_insert_point itself instead.
2022-04-06 Richard Biener <rguenther@suse.de>
PR tree-optimization/105173
* tree-ssa-reassoc.c (find_insert_point): Get extra
insert_before output argument and compute it.
(insert_stmt_before_use): Adjust.
(rewrite_expr_tree): Likewise.
* gcc.dg/pr105173.c: New testcase.
(cherry picked from commit e1a5e7562d53a8d2256f754714b06595bea72196)
Diff:
---
gcc/testsuite/gcc.dg/pr105173.c | 12 ++++++++++++
gcc/tree-ssa-reassoc.c | 41 +++++++++++++++++++++++++++++------------
2 files changed, 41 insertions(+), 12 deletions(-)
diff --git a/gcc/testsuite/gcc.dg/pr105173.c b/gcc/testsuite/gcc.dg/pr105173.c
new file mode 100644
index 00000000000..3effb2996b0
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr105173.c
@@ -0,0 +1,12 @@
+/* { dg-do compile { target dfp } } */
+/* { dg-options "-Ofast" } */
+
+int i;
+
+int
+foo(char c, _Decimal32 d)
+{
+ d *= i;
+ d *= -(_Decimal64)c;
+ return d;
+}
diff --git a/gcc/tree-ssa-reassoc.c b/gcc/tree-ssa-reassoc.c
index af8df8563bc..ed6195dc7ab 100644
--- a/gcc/tree-ssa-reassoc.c
+++ b/gcc/tree-ssa-reassoc.c
@@ -4798,17 +4798,26 @@ swap_ops_for_binary_stmt (vec<operand_entry *> ops,
}
/* If definition of RHS1 or RHS2 dominates STMT, return the later of those
- two definitions, otherwise return STMT. */
+ two definitions, otherwise return STMT. Sets INSERT_BEFORE to indicate
+ whether RHS1 op RHS2 can be inserted before or needs to be inserted
+ after the returned stmt. */
static inline gimple *
-find_insert_point (gimple *stmt, tree rhs1, tree rhs2)
+find_insert_point (gimple *stmt, tree rhs1, tree rhs2, bool &insert_before)
{
+ insert_before = true;
if (TREE_CODE (rhs1) == SSA_NAME
&& reassoc_stmt_dominates_stmt_p (stmt, SSA_NAME_DEF_STMT (rhs1)))
- stmt = SSA_NAME_DEF_STMT (rhs1);
+ {
+ stmt = SSA_NAME_DEF_STMT (rhs1);
+ insert_before = false;
+ }
if (TREE_CODE (rhs2) == SSA_NAME
&& reassoc_stmt_dominates_stmt_p (stmt, SSA_NAME_DEF_STMT (rhs2)))
- stmt = SSA_NAME_DEF_STMT (rhs2);
+ {
+ stmt = SSA_NAME_DEF_STMT (rhs2);
+ insert_before = false;
+ }
return stmt;
}
@@ -4820,7 +4829,8 @@ insert_stmt_before_use (gimple *stmt, gimple *stmt_to_insert)
gcc_assert (is_gimple_assign (stmt_to_insert));
tree rhs1 = gimple_assign_rhs1 (stmt_to_insert);
tree rhs2 = gimple_assign_rhs2 (stmt_to_insert);
- gimple *insert_point = find_insert_point (stmt, rhs1, rhs2);
+ bool insert_before;
+ gimple *insert_point = find_insert_point (stmt, rhs1, rhs2, insert_before);
gimple_stmt_iterator gsi = gsi_for_stmt (insert_point);
gimple_set_uid (stmt_to_insert, gimple_uid (insert_point));
@@ -4828,7 +4838,7 @@ insert_stmt_before_use (gimple *stmt, gimple *stmt_to_insert)
the point where operand rhs1 or rhs2 is defined. In this case,
stmt_to_insert has to be inserted afterwards. This would
only happen when the stmt insertion point is flexible. */
- if (stmt == insert_point)
+ if (insert_before)
gsi_insert_before (&gsi, stmt_to_insert, GSI_NEW_STMT);
else
insert_stmt_after (stmt_to_insert, insert_point);
@@ -4887,22 +4897,25 @@ rewrite_expr_tree (gimple *stmt, enum tree_code rhs_code, unsigned int opindex,
return lhs), force creation of a new SSA_NAME. */
if (changed || ((rhs1 != oe2->op || rhs2 != oe1->op) && opindex))
{
+ bool insert_before;
gimple *insert_point
- = find_insert_point (stmt, oe1->op, oe2->op);
+ = find_insert_point (stmt, oe1->op, oe2->op, insert_before);
lhs = make_ssa_name (TREE_TYPE (lhs));
stmt
= gimple_build_assign (lhs, rhs_code,
oe1->op, oe2->op);
gimple_set_uid (stmt, uid);
gimple_set_visited (stmt, true);
- if (insert_point == gsi_stmt (gsi))
+ if (insert_before)
gsi_insert_before (&gsi, stmt, GSI_SAME_STMT);
else
insert_stmt_after (stmt, insert_point);
}
else
{
- gcc_checking_assert (find_insert_point (stmt, oe1->op, oe2->op)
+ bool insert_before;
+ gcc_checking_assert (find_insert_point (stmt, oe1->op, oe2->op,
+ insert_before)
== stmt);
gimple_assign_set_rhs1 (stmt, oe1->op);
gimple_assign_set_rhs2 (stmt, oe2->op);
@@ -4958,21 +4971,25 @@ rewrite_expr_tree (gimple *stmt, enum tree_code rhs_code, unsigned int opindex,
{
gimple_stmt_iterator gsi = gsi_for_stmt (stmt);
unsigned int uid = gimple_uid (stmt);
- gimple *insert_point = find_insert_point (stmt, new_rhs1, oe->op);
+ bool insert_before;
+ gimple *insert_point = find_insert_point (stmt, new_rhs1, oe->op,
+ insert_before);
lhs = make_ssa_name (TREE_TYPE (lhs));
stmt = gimple_build_assign (lhs, rhs_code,
new_rhs1, oe->op);
gimple_set_uid (stmt, uid);
gimple_set_visited (stmt, true);
- if (insert_point == gsi_stmt (gsi))
+ if (insert_before)
gsi_insert_before (&gsi, stmt, GSI_SAME_STMT);
else
insert_stmt_after (stmt, insert_point);
}
else
{
- gcc_checking_assert (find_insert_point (stmt, new_rhs1, oe->op)
+ bool insert_before;
+ gcc_checking_assert (find_insert_point (stmt, new_rhs1, oe->op,
+ insert_before)
== stmt);
gimple_assign_set_rhs1 (stmt, new_rhs1);
gimple_assign_set_rhs2 (stmt, oe->op);
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-05-27 13:15 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-27 13:15 [gcc r10-10766] tree-optimization/105173 - fix insertion logic in reassoc Richard Biener
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).