From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1666) id 3B9CD38425B2; Tue, 10 May 2022 13:43:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3B9CD38425B2 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Richard Biener To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-263] Use gimple-match folding in fold_build_cond_expr X-Act-Checkin: gcc X-Git-Author: Richard Biener X-Git-Refname: refs/heads/master X-Git-Oldrev: da6305558bab9e24943848e4fc5bd8738d7e8f9b X-Git-Newrev: 9801ca737b1dcbf51c0d07db59dd204a047dd3f7 Message-Id: <20220510134305.3B9CD38425B2@sourceware.org> Date: Tue, 10 May 2022 13:43:05 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 10 May 2022 13:43:05 -0000 https://gcc.gnu.org/g:9801ca737b1dcbf51c0d07db59dd204a047dd3f7 commit r13-263-g9801ca737b1dcbf51c0d07db59dd204a047dd3f7 Author: Richard Biener Date: Tue May 10 15:39:46 2022 +0200 Use gimple-match folding in fold_build_cond_expr The following cleans up if-conversions fold_build_cond_expr to use gimple-match folding instead of GENERIC folding. 2022-05-10 Richard Biener * tree-if-conv.cc (fold_build_cond_expr): Use match-and-simplify to simplify the condition. (ifcvt_follow_ssa_use_edges): Remove. (predicate_scalar_phi): Use follow_all_ssa_edges. Diff: --- gcc/tree-if-conv.cc | 46 +++++++++++----------------------------------- 1 file changed, 11 insertions(+), 35 deletions(-) diff --git a/gcc/tree-if-conv.cc b/gcc/tree-if-conv.cc index 7495ed653c0..57cc38567d3 100644 --- a/gcc/tree-if-conv.cc +++ b/gcc/tree-if-conv.cc @@ -459,8 +459,6 @@ fold_or_predicates (location_t loc, tree c1, tree c2) static tree fold_build_cond_expr (tree type, tree cond, tree rhs, tree lhs) { - tree rhs1, lhs1, cond_expr; - /* If COND is comparison r != 0 and r has boolean type, convert COND to SSA_NAME to accept by vect bool pattern. */ if (TREE_CODE (cond) == NE_EXPR) @@ -472,34 +470,20 @@ fold_build_cond_expr (tree type, tree cond, tree rhs, tree lhs) && (integer_zerop (op1))) cond = op0; } - cond_expr = fold_ternary (COND_EXPR, type, cond, rhs, lhs); - - if (cond_expr == NULL_TREE) - return build3 (COND_EXPR, type, cond, rhs, lhs); - - STRIP_USELESS_TYPE_CONVERSION (cond_expr); - if (is_gimple_val (cond_expr)) - return cond_expr; - - if (TREE_CODE (cond_expr) == ABS_EXPR) + gimple_match_op cexpr (gimple_match_cond::UNCOND, COND_EXPR, + type, cond, rhs, lhs); + if (cexpr.resimplify (NULL, follow_all_ssa_edges)) { - rhs1 = TREE_OPERAND (cond_expr, 1); - STRIP_USELESS_TYPE_CONVERSION (rhs1); - if (is_gimple_val (rhs1)) - return build1 (ABS_EXPR, type, rhs1); + if (gimple_simplified_result_is_gimple_val (&cexpr)) + return cexpr.ops[0]; + else if (cexpr.code == ABS_EXPR) + return build1 (ABS_EXPR, type, cexpr.ops[0]); + else if (cexpr.code == MIN_EXPR + || cexpr.code == MAX_EXPR) + return build2 ((tree_code)cexpr.code, type, cexpr.ops[0], cexpr.ops[1]); } - if (TREE_CODE (cond_expr) == MIN_EXPR - || TREE_CODE (cond_expr) == MAX_EXPR) - { - lhs1 = TREE_OPERAND (cond_expr, 0); - STRIP_USELESS_TYPE_CONVERSION (lhs1); - rhs1 = TREE_OPERAND (cond_expr, 1); - STRIP_USELESS_TYPE_CONVERSION (rhs1); - if (is_gimple_val (rhs1) && is_gimple_val (lhs1)) - return build2 (TREE_CODE (cond_expr), type, lhs1, rhs1); - } return build3 (COND_EXPR, type, cond, rhs, lhs); } @@ -1897,14 +1881,6 @@ gen_phi_arg_condition (gphi *phi, vec *occur, return cond; } -/* Local valueization callback that follows all-use SSA edges. */ - -static tree -ifcvt_follow_ssa_use_edges (tree val) -{ - return val; -} - /* Replace a scalar PHI node with a COND_EXPR using COND as condition. This routine can handle PHI nodes with more than two arguments. @@ -2007,7 +1983,7 @@ predicate_scalar_phi (gphi *phi, gimple_stmt_iterator *gsi) new_stmt = gimple_build_assign (res, rhs); gsi_insert_before (gsi, new_stmt, GSI_SAME_STMT); gimple_stmt_iterator new_gsi = gsi_for_stmt (new_stmt); - if (fold_stmt (&new_gsi, ifcvt_follow_ssa_use_edges)) + if (fold_stmt (&new_gsi, follow_all_ssa_edges)) { new_stmt = gsi_stmt (new_gsi); update_stmt (new_stmt);