diff options
author | Roger Sayle <roger@nextmovesoftware.com> | 2021-09-22 19:17:49 +0100 |
---|---|---|
committer | Roger Sayle <roger@nextmovesoftware.com> | 2021-09-22 19:17:49 +0100 |
commit | 8f571e64713cc72561f84241863496e473eae4c6 (patch) | |
tree | 4e844b47051f80796967e0a819e774833b79e1b6 /gcc/tree-ssa-sccvn.c | |
parent | 2f2dcbe4717ce7a117671234940f8b74809f3973 (diff) | |
download | gcc-8f571e64713cc72561f84241863496e473eae4c6.zip gcc-8f571e64713cc72561f84241863496e473eae4c6.tar.gz gcc-8f571e64713cc72561f84241863496e473eae4c6.tar.bz2 |
More NEGATE_EXPR folding in match.pd
As observed by Jakub in comment #2 of PR 98865, the expression -(a>>63)
is optimized in GENERIC but not in GIMPLE. Investigating further it
turns out that this is one of a few transformations performed by
fold_negate_expr in fold-const.c that aren't yet performed by match.pd.
This patch moves/duplicates them there, and should be relatively safe
as these transformations are already performed by the compiler, but
just in different passes.
This revised patch adds a Boolean simplify argument to tree-ssa-sccvn.c's
vn_nary_build_or_lookup_1 to control whether simplification should be
performed before value numbering, updating the callers, but then
avoiding simplification when constructing/value-numbering NEGATE_EXPR.
This avoids the regression of gcc.dg/tree-ssa/ssa-free-88.c, and enables
the new test case(s) to pass.
2021-09-22 Roger Sayle <roger@nextmovesoftware.com>
Richard Biener <rguenther@suse.de>
gcc/ChangeLog
* match.pd (negation simplifications): Implement some negation
folding transformations from fold-const.c's fold_negate_expr.
* tree-ssa-sccvn.c (vn_nary_build_or_lookup_1): Add a SIMPLIFY
argument, to control whether the op should be simplified prior
to looking up/assigning a value number.
(vn_nary_build_or_lookup): Update call to vn_nary_build_or_lookup_1.
(vn_nary_simplify): Likewise.
(visit_nary_op): Likewise, but when constructing a NEGATE_EXPR
now call vn_nary_build_or_lookup_1 disabling simplification.
gcc/testsuite/ChangeLog
* gcc.dg/fold-negate-1.c: New test case.
Diffstat (limited to 'gcc/tree-ssa-sccvn.c')
-rw-r--r-- | gcc/tree-ssa-sccvn.c | 35 |
1 files changed, 19 insertions, 16 deletions
diff --git a/gcc/tree-ssa-sccvn.c b/gcc/tree-ssa-sccvn.c index bfa516b..a901f51 100644 --- a/gcc/tree-ssa-sccvn.c +++ b/gcc/tree-ssa-sccvn.c @@ -2321,11 +2321,13 @@ vn_reference_lookup_or_insert_for_pieces (tree vuse, } /* Return a value-number for RCODE OPS... either by looking up an existing - value-number for the simplified result or by inserting the operation if - INSERT is true. */ + value-number for the possibly simplified result or by inserting the + operation if INSERT is true. If SIMPLIFY is false, return a value + number for the unsimplified expression. */ static tree -vn_nary_build_or_lookup_1 (gimple_match_op *res_op, bool insert) +vn_nary_build_or_lookup_1 (gimple_match_op *res_op, bool insert, + bool simplify) { tree result = NULL_TREE; /* We will be creating a value number for @@ -2333,15 +2335,16 @@ vn_nary_build_or_lookup_1 (gimple_match_op *res_op, bool insert) So first simplify and lookup this expression to see if it is already available. */ /* For simplification valueize. */ - unsigned i; - for (i = 0; i < res_op->num_ops; ++i) - if (TREE_CODE (res_op->ops[i]) == SSA_NAME) - { - tree tem = vn_valueize (res_op->ops[i]); - if (!tem) - break; - res_op->ops[i] = tem; - } + unsigned i = 0; + if (simplify) + for (i = 0; i < res_op->num_ops; ++i) + if (TREE_CODE (res_op->ops[i]) == SSA_NAME) + { + tree tem = vn_valueize (res_op->ops[i]); + if (!tem) + break; + res_op->ops[i] = tem; + } /* If valueization of an operand fails (it is not available), skip simplification. */ bool res = false; @@ -2440,7 +2443,7 @@ vn_nary_build_or_lookup_1 (gimple_match_op *res_op, bool insert) static tree vn_nary_build_or_lookup (gimple_match_op *res_op) { - return vn_nary_build_or_lookup_1 (res_op, true); + return vn_nary_build_or_lookup_1 (res_op, true, true); } /* Try to simplify the expression RCODE OPS... of type TYPE and return @@ -2454,7 +2457,7 @@ vn_nary_simplify (vn_nary_op_t nary) gimple_match_op op (gimple_match_cond::UNCOND, nary->opcode, nary->type, nary->length); memcpy (op.ops, nary->op, sizeof (tree) * nary->length); - return vn_nary_build_or_lookup_1 (&op, false); + return vn_nary_build_or_lookup_1 (&op, false, true); } /* Elimination engine. */ @@ -5006,7 +5009,7 @@ visit_nary_op (tree lhs, gassign *stmt) 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[i] = vn_nary_build_or_lookup_1 (&match_op, false, true); ops[j] = rhs[j]; if (ops[i] && (ops[0] = vn_nary_op_lookup_pieces (2, code, @@ -5014,7 +5017,7 @@ visit_nary_op (tree lhs, gassign *stmt) { gimple_match_op match_op (gimple_match_cond::UNCOND, NEGATE_EXPR, type, ops[0]); - result = vn_nary_build_or_lookup (&match_op); + result = vn_nary_build_or_lookup_1 (&match_op, true, false); if (result) { bool changed = set_ssa_val_to (lhs, result); |