diff options
author | Richard Biener <rguenther@suse.de> | 2020-09-17 11:48:36 +0200 |
---|---|---|
committer | Richard Biener <rguenther@suse.de> | 2020-09-17 13:56:15 +0200 |
commit | c7f4be78cb61006492d16375aba5392f580cd633 (patch) | |
tree | fae2071cad4368dfc130f1d0a4512567cd9369b4 | |
parent | 225a08220e444371ae4867b3e2ace275d30af3d3 (diff) | |
download | gcc-c7f4be78cb61006492d16375aba5392f580cd633.zip gcc-c7f4be78cb61006492d16375aba5392f580cd633.tar.gz gcc-c7f4be78cb61006492d16375aba5392f580cd633.tar.bz2 |
CSE negated multiplications and divisions
This adds the capability to look for available negated multiplications
and divisions, replacing them with cheaper negates.
2020-09-17 Richard Biener <rguenther@suse.de>
* tree-ssa-sccvn.c (visit_nary_op): Value-number multiplications
and divisions to negates of available negated forms.
* gcc.dg/tree-ssa/ssa-fre-88.c: New testcase.
-rw-r--r-- | gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-88.c | 18 | ||||
-rw-r--r-- | gcc/tree-ssa-sccvn.c | 35 |
2 files changed, 53 insertions, 0 deletions
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-88.c b/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-88.c new file mode 100644 index 0000000..15d2ca0 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-88.c @@ -0,0 +1,18 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-fre1" } */ + +double y[2]; +void foo (double x) +{ + y[0] = x * -3.; + y[1] = x * 3.; +} +void bar (double x, double z) +{ + y[0] = -z / x; + y[1] = z / x; +} + +/* { dg-final { scan-tree-dump-times " \\* " 1 "fre1" } } */ +/* { dg-final { scan-tree-dump-times " / " 1 "fre1" } } */ +/* { dg-final { scan-tree-dump-times "= -_" 2 "fre1" } } */ diff --git a/gcc/tree-ssa-sccvn.c b/gcc/tree-ssa-sccvn.c index 8fbb1dd..64f1e8c 100644 --- a/gcc/tree-ssa-sccvn.c +++ b/gcc/tree-ssa-sccvn.c @@ -4824,6 +4824,40 @@ visit_nary_op (tree lhs, gassign *stmt) } } break; + case RDIV_EXPR: + case TRUNC_DIV_EXPR: + case MULT_EXPR: + /* Match up ([-]a){/,*}([-])b with v=a{/,*}b, replacing it with -v. */ + if (! HONOR_SIGN_DEPENDENT_ROUNDING (type)) + { + tree rhs[2]; + rhs[0] = rhs1; + rhs[1] = gimple_assign_rhs2 (stmt); + for (unsigned i = 0; i <= 1; ++i) + { + unsigned j = i == 0 ? 1 : 0; + tree ops[2]; + gimple_match_op match_op (gimple_match_cond::UNCOND, + NEGATE_EXPR, type, rhs[i]); + ops[i] = vn_nary_build_or_lookup_1 (&match_op, false); + ops[j] = rhs[j]; + if (ops[i] + && (ops[0] = vn_nary_op_lookup_pieces (2, code, + type, ops, NULL))) + { + gimple_match_op match_op (gimple_match_cond::UNCOND, + NEGATE_EXPR, type, ops[0]); + result = vn_nary_build_or_lookup (&match_op); + if (result) + { + bool changed = set_ssa_val_to (lhs, result); + vn_nary_op_insert_stmt (stmt, result); + return changed; + } + } + } + } + break; default: break; } @@ -5739,6 +5773,7 @@ eliminate_dom_walker::eliminate_insert (basic_block bb, if (!stmt || (!CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (stmt)) && gimple_assign_rhs_code (stmt) != VIEW_CONVERT_EXPR + && gimple_assign_rhs_code (stmt) != NEGATE_EXPR && gimple_assign_rhs_code (stmt) != BIT_FIELD_REF && (gimple_assign_rhs_code (stmt) != BIT_AND_EXPR || TREE_CODE (gimple_assign_rhs2 (stmt)) != INTEGER_CST))) |