From patchwork Sat Jun 19 21:42:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Pan2 via Gcc-patches" X-Patchwork-Id: 1494711 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=VbkxuHjc; dkim-atps=neutral Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4G6q7d4WPYz9sRf for ; Sun, 20 Jun 2021 07:44:29 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 629773891C20 for ; Sat, 19 Jun 2021 21:44:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 629773891C20 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1624139067; bh=nasoK1kpOOhiE4hlxLR9CKyZd4Zj3GgnW9jfM06ZRZ0=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=VbkxuHjc6VFSNl1T9u1/10ZVT+jK7RnvCgLkTxZnvD7UnVL2r59qlEedmPaMDBqA+ yzZFcVOJI55CKGxGURzgvjehrK/7V3oSjdoPPR4uqVv5ot0keYQfVqYvISjmXBo+P4 hDhesqtJQMun9RhALExnTgxXDsyXCQOK3WVVHQzk= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by sourceware.org (Postfix) with ESMTPS id B793D38515EB for ; Sat, 19 Jun 2021 21:43:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B793D38515EB Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 15JLh0eR028693 for ; Sat, 19 Jun 2021 14:43:05 -0700 Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0a-0016f401.pphosted.com with ESMTP id 399dxrhjv8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Sat, 19 Jun 2021 14:43:05 -0700 Received: from DC5-EXCH01.marvell.com (10.69.176.38) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Sat, 19 Jun 2021 14:43:04 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server id 15.0.1497.18 via Frontend Transport; Sat, 19 Jun 2021 14:43:03 -0700 Received: from linux.wrightpinski.org.com (unknown [10.69.242.197]) by maili.marvell.com (Postfix) with ESMTP id B25725C68E5; Sat, 19 Jun 2021 14:43:03 -0700 (PDT) To: Subject: [PATCH 5/7] Allow match-and-simplified phiopt to run in early phiopt Date: Sat, 19 Jun 2021 14:42:59 -0700 Message-ID: <1624138980-5805-1-git-send-email-apinski@marvell.com> X-Mailer: git-send-email 1.8.3.1 MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: x1uh9kIDr5DsNzatPlpUAbzcZwfL50pU X-Proofpoint-GUID: x1uh9kIDr5DsNzatPlpUAbzcZwfL50pU X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391, 18.0.790 definitions=2021-06-19_14:2021-06-18, 2021-06-19 signatures=0 X-Spam-Status: No, score=-14.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: apinski--- via Gcc-patches From: "Li, Pan2 via Gcc-patches" Reply-To: apinski@marvell.com Cc: Andrew Pinski Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" From: Andrew Pinski To move a few things more to match-and-simplify from phiopt, we need to allow match_simplify_replacement to run in early phiopt. To do this, we need to mark some match patterns if they can be done in early phiopt or not. OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions. gcc/ChangeLog: * generic-match-head.c (phiopt_earlymode): New function. * gimple-match-head.c (phiopt_earlymode): New function. * match.pd (A ? CST0 : CST1): Disable for early phiopt. (x >= 0 ? ~y : y): Likewise. (x >= 0 ? y : ~y): Likewise. * tree-pass.h (PROP_gimple_lomp_dev): Increment bit by one. (PROP_rtl_split_insns): Likewise. (PROP_phioptearly): New define. * tree-ssa-phiopt.c (tree_ssa_phiopt_worker): Set and unset PROP_phioptearly on curr_properties if early. --- gcc/generic-match-head.c | 7 +++++ gcc/gimple-match-head.c | 7 +++++ gcc/match.pd | 76 ++++++++++++++++++++++++++---------------------- gcc/tree-pass.h | 5 ++-- gcc/tree-ssa-phiopt.c | 8 +++-- 5 files changed, 63 insertions(+), 40 deletions(-) diff --git a/gcc/generic-match-head.c b/gcc/generic-match-head.c index f426208..90ebf84 100644 --- a/gcc/generic-match-head.c +++ b/gcc/generic-match-head.c @@ -91,6 +91,13 @@ optimize_vectors_before_lowering_p () return true; } +/* Return true if phiopt is in early mode. */ +static inline bool +phiopt_earlymode () +{ + return false; +} + /* Return true if successive divisions can be optimized. Defer to GIMPLE opts. */ diff --git a/gcc/gimple-match-head.c b/gcc/gimple-match-head.c index 7112c11..1eafbb7 100644 --- a/gcc/gimple-match-head.c +++ b/gcc/gimple-match-head.c @@ -1159,6 +1159,13 @@ canonicalize_math_after_vectorization_p () return !cfun || (cfun->curr_properties & PROP_gimple_lvec) != 0; } +/* Return true if phiopt is in early mode. */ +static inline bool +phiopt_earlymode () +{ + return !cfun || (cfun->curr_properties & PROP_phioptearly) != 0; +} + /* Return true if we can still perform transformations that may introduce vector operations that are not supported by the target. Vector lowering normally handles those, but after that pass, it becomes unsafe. */ diff --git a/gcc/match.pd b/gcc/match.pd index 39fb57e..f38baf2 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -3728,39 +3728,40 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) #if GIMPLE (simplify (cond @0 INTEGER_CST@1 INTEGER_CST@2) - (switch - (if (integer_zerop (@2)) - (switch - /* a ? 1 : 0 -> a if 0 and 1 are integral types. */ - (if (integer_onep (@1)) - (convert (convert:boolean_type_node @0))) - /* a ? -1 : 0 -> -a. */ - (if (INTEGRAL_TYPE_P (type) && integer_all_onesp (@1)) - (negate (convert (convert:boolean_type_node @0)))) - /* a ? powerof2cst : 0 -> a << (log2(powerof2cst)) */ - (if (INTEGRAL_TYPE_P (type) && integer_pow2p (@1)) - (with { - tree shift = build_int_cst (integer_type_node, tree_log2 (@1)); - } - (lshift (convert (convert:boolean_type_node @0)) { shift; }))))) - (if (integer_zerop (@1)) - (with { - tree booltrue = constant_boolean_node (true, boolean_type_node); - } + (if (!phiopt_earlymode ()) + (switch + (if (integer_zerop (@2)) (switch - /* a ? 0 : 1 -> !a. */ - (if (integer_onep (@2)) - (convert (bit_xor (convert:boolean_type_node @0) { booltrue; } ))) - /* a ? -1 : 0 -> -(!a). */ - (if (INTEGRAL_TYPE_P (type) && integer_all_onesp (@2)) - (negate (convert (bit_xor (convert:boolean_type_node @0) { booltrue; } )))) - /* a ? powerof2cst : 0 -> (!a) << (log2(powerof2cst)) */ - (if (INTEGRAL_TYPE_P (type) && integer_pow2p (@2)) + /* a ? 1 : 0 -> a if 0 and 1 are integral types. */ + (if (integer_onep (@1)) + (convert (convert:boolean_type_node @0))) + /* a ? -1 : 0 -> -a. */ + (if (INTEGRAL_TYPE_P (type) && integer_all_onesp (@1)) + (negate (convert (convert:boolean_type_node @0)))) + /* a ? powerof2cst : 0 -> a << (log2(powerof2cst)) */ + (if (INTEGRAL_TYPE_P (type) && integer_pow2p (@1)) (with { - tree shift = build_int_cst (integer_type_node, tree_log2 (@2)); + tree shift = build_int_cst (integer_type_node, tree_log2 (@1)); } - (lshift (convert (bit_xor (convert:boolean_type_node @0) { booltrue; } )) - { shift; })))))))) + (lshift (convert (convert:boolean_type_node @0)) { shift; }))))) + (if (integer_zerop (@1)) + (with { + tree booltrue = constant_boolean_node (true, boolean_type_node); + } + (switch + /* a ? 0 : 1 -> !a. */ + (if (integer_onep (@2)) + (convert (bit_xor (convert:boolean_type_node @0) { booltrue; } ))) + /* a ? -1 : 0 -> -(!a). */ + (if (INTEGRAL_TYPE_P (type) && integer_all_onesp (@2)) + (negate (convert (bit_xor (convert:boolean_type_node @0) { booltrue; } )))) + /* a ? powerof2cst : 0 -> (!a) << (log2(powerof2cst)) */ + (if (INTEGRAL_TYPE_P (type) && integer_pow2p (@2)) + (with { + tree shift = build_int_cst (integer_type_node, tree_log2 (@2)); + } + (lshift (convert (bit_xor (convert:boolean_type_node @0) { booltrue; } )) + { shift; }))))))))) #endif /* Simplification moved from fold_cond_expr_with_comparison. It may also @@ -4891,7 +4892,8 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) /* x >= 0 ? ~y : y into ~((x >> (prec-1)) ^ y). */ (simplify (cond (cmp @0 integer_zerop) (bit_not @1) @1) - (if (INTEGRAL_TYPE_P (type) + (if (!phiopt_earlymode () + && INTEGRAL_TYPE_P (type) && INTEGRAL_TYPE_P (TREE_TYPE (@0)) && !TYPE_UNSIGNED (TREE_TYPE (@0)) && TYPE_PRECISION (TREE_TYPE (@0)) == TYPE_PRECISION (type)) @@ -4906,7 +4908,8 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) /* x >= 0 ? y : ~y into (x >> (prec-1)) ^ y. */ (simplify (cond (cmp @0 integer_zerop) @1 (bit_not @1)) - (if (INTEGRAL_TYPE_P (type) + (if (!phiopt_earlymode () + && INTEGRAL_TYPE_P (type) && INTEGRAL_TYPE_P (TREE_TYPE (@0)) && !TYPE_UNSIGNED (TREE_TYPE (@0)) && TYPE_PRECISION (TREE_TYPE (@0)) == TYPE_PRECISION (type)) @@ -4924,7 +4927,8 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (cond (ne (bit_and @0 integer_pow2p@1) integer_zerop) INTEGER_CST@2 integer_zerop) - (if (!POINTER_TYPE_P (type) && integer_pow2p (@2)) + (if (!phiopt_earlymode () + && !POINTER_TYPE_P (type) && integer_pow2p (@2)) (with { int shift = (wi::exact_log2 (wi::to_wide (@2)) - wi::exact_log2 (wi::to_wide (@1))); @@ -4942,7 +4946,8 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) ncmp (ge lt) (simplify (cmp (bit_and (convert?@2 @0) integer_pow2p@1) integer_zerop) - (if (INTEGRAL_TYPE_P (TREE_TYPE (@0)) + (if (!phiopt_earlymode () + && INTEGRAL_TYPE_P (TREE_TYPE (@0)) && type_has_mode_precision_p (TREE_TYPE (@0)) && element_precision (@2) >= element_precision (@0) && wi::only_sign_bit_p (wi::to_wide (@1), element_precision (@0))) @@ -4955,7 +4960,8 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (cond (lt @0 integer_zerop) INTEGER_CST@1 integer_zerop) - (if (integer_pow2p (@1) + (if (!phiopt_earlymode () + && integer_pow2p (@1) && !TYPE_UNSIGNED (TREE_TYPE (@0))) (with { int shift = element_precision (@0) - wi::exact_log2 (wi::to_wide (@1)) - 1; diff --git a/gcc/tree-pass.h b/gcc/tree-pass.h index 15693fe..07ee151 100644 --- a/gcc/tree-pass.h +++ b/gcc/tree-pass.h @@ -222,8 +222,9 @@ protected: of math functions; the current choices have been optimized. */ -#define PROP_gimple_lomp_dev (1 << 16) /* done omp_device_lower */ -#define PROP_rtl_split_insns (1 << 17) /* RTL has insns split. */ +#define PROP_phioptearly (1 << 16) /* Sets while phiopt is in early mode. */ +#define PROP_gimple_lomp_dev (1 << 17) /* done omp_device_lower */ +#define PROP_rtl_split_insns (1 << 18) /* RTL has insns split. */ #define PROP_gimple \ (PROP_gimple_any | PROP_gimple_lcf | PROP_gimple_leh | PROP_gimple_lomp) diff --git a/gcc/tree-ssa-phiopt.c b/gcc/tree-ssa-phiopt.c index 3b3762a..8b289be 100644 --- a/gcc/tree-ssa-phiopt.c +++ b/gcc/tree-ssa-phiopt.c @@ -175,6 +175,8 @@ tree_ssa_phiopt_worker (bool do_store_elim, bool do_hoist_loads, bool early_p) unsigned n, i; bool cfgchanged = false; hash_set *nontrap = 0; + if (early_p) + cfun->curr_properties |= PROP_phioptearly; calculate_dominance_info (CDI_DOMINATORS); @@ -345,9 +347,8 @@ tree_ssa_phiopt_worker (bool do_store_elim, bool do_hoist_loads, bool early_p) /* Do the replacement of conditional if it can be done. */ if (!early_p && two_value_replacement (bb, bb1, e2, phi, arg0, arg1)) cfgchanged = true; - else if (!early_p - && match_simplify_replacement (bb, bb1, e1, e2, phi, - arg0, arg1)) + else if (match_simplify_replacement (bb, bb1, e1, e2, phi, + arg0, arg1)) cfgchanged = true; else if (abs_replacement (bb, bb1, e1, e2, phi, arg0, arg1)) cfgchanged = true; @@ -364,6 +365,7 @@ tree_ssa_phiopt_worker (bool do_store_elim, bool do_hoist_loads, bool early_p) } free (bb_order); + cfun->curr_properties &= ~PROP_phioptearly; if (do_store_elim) delete nontrap;