From patchwork Sat Jun 19 21:29:24 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: 1494709 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=2620:52:3:1:0:246e:9693:128c; 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=osNb3lZJ; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (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 4G6pqG6g5Zz9sPf for ; Sun, 20 Jun 2021 07:30:16 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E194D389040C for ; Sat, 19 Jun 2021 21:30:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E194D389040C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1624138213; bh=CvlGsBKneayN2TWAVodikUVzAtgAK6REFmAStWqmnPc=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=osNb3lZJAml/mEkURBhWrwwG8ZPszaZM/lrNqg+kk8TZLO7jzhu0p8p8+R+rC55Ai UYFXXOknW9z2uVKob9sqwFlEfC0FMLPNr4WHKOSnof8LGFkToKPHuDkgrK2yi5ti8J nTmKx8PztDEY2IC55Oen2j14vFpAbI4kHo/ADTHg= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by sourceware.org (Postfix) with ESMTPS id 3155A385EC56 for ; Sat, 19 Jun 2021 21:29:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 3155A385EC56 Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 15JLRXEK029980 for ; Sat, 19 Jun 2021 14:29:29 -0700 Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0b-0016f401.pphosted.com with ESMTP id 399g3qh5xg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Sat, 19 Jun 2021 14:29:29 -0700 Received: from DC5-EXCH01.marvell.com (10.69.176.38) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Sat, 19 Jun 2021 14:29:27 -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:29:27 -0700 Received: from linux.wrightpinski.org.com (unknown [10.69.242.197]) by maili.marvell.com (Postfix) with ESMTP id 6FCDF5B6968; Sat, 19 Jun 2021 14:29:27 -0700 (PDT) To: Subject: [PATCH 4/7] Expand the comparison argument of fold_cond_expr_with_comparison Date: Sat, 19 Jun 2021 14:29:24 -0700 Message-ID: <1624138164-5419-1-git-send-email-apinski@marvell.com> X-Mailer: git-send-email 1.8.3.1 MIME-Version: 1.0 X-Proofpoint-GUID: AhmbXAANLugoRkQ_haRtSjIpCBEkKoqx X-Proofpoint-ORIG-GUID: AhmbXAANLugoRkQ_haRtSjIpCBEkKoqx 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.5 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 make things slightly easiler to convert fold_cond_expr_with_comparison over to match.pd, expanding the arg0 argument into 3 different arguments is done. Also this was simple because we don't use arg0 after grabbing the code and the two operands. Also since we do this, we don't need to fold the comparison to get the inverse but just use invert_tree_comparison directly. OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions. gcc/ChangeLog: * fold-const.c (fold_cond_expr_with_comparison): Exand arg0 into comp_code, arg00, and arg01. (fold_ternary_loc): Use invert_tree_comparison instead of fold_invert_truthvalue for the case where we have A CMP B ? C : A. --- gcc/fold-const.c | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 95673d2..85e90f4 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -126,7 +126,8 @@ static tree range_binop (enum tree_code, tree, tree, int, tree, int); static tree range_predecessor (tree); static tree range_successor (tree); static tree fold_range_test (location_t, enum tree_code, tree, tree, tree); -static tree fold_cond_expr_with_comparison (location_t, tree, tree, tree, tree); +static tree fold_cond_expr_with_comparison (location_t, tree, enum tree_code, + tree, tree, tree, tree); static tree unextend (tree, int, int, tree); static tree extract_muldiv (tree, tree, enum tree_code, tree, bool *); static tree extract_muldiv_1 (tree, tree, enum tree_code, tree, bool *); @@ -5735,20 +5736,19 @@ merge_ranges (int *pin_p, tree *plow, tree *phigh, int in0_p, tree low0, /* Subroutine of fold, looking inside expressions of the form - A op B ? A : C, where ARG0, ARG1 and ARG2 are the three operands - of the COND_EXPR. This function is being used also to optimize - A op B ? C : A, by reversing the comparison first. + A op B ? A : C, where (ARG00, COMP_CODE, ARG01), ARG1 and ARG2 + are the three operands of the COND_EXPR. This function is + being used also to optimize A op B ? C : A, by reversing the + comparison first. Return a folded expression whose code is not a COND_EXPR anymore, or NULL_TREE if no folding opportunity is found. */ static tree fold_cond_expr_with_comparison (location_t loc, tree type, - tree arg0, tree arg1, tree arg2) + enum tree_code comp_code, + tree arg00, tree arg01, tree arg1, tree arg2) { - enum tree_code comp_code = TREE_CODE (arg0); - tree arg00 = TREE_OPERAND (arg0, 0); - tree arg01 = TREE_OPERAND (arg0, 1); tree arg1_type = TREE_TYPE (arg1); tree tem; @@ -12822,7 +12822,10 @@ fold_ternary_loc (location_t loc, enum tree_code code, tree type, && operand_equal_for_comparison_p (TREE_OPERAND (arg0, 0), op1) && !HONOR_SIGNED_ZEROS (element_mode (op1))) { - tem = fold_cond_expr_with_comparison (loc, type, arg0, op1, op2); + tem = fold_cond_expr_with_comparison (loc, type, TREE_CODE (arg0), + TREE_OPERAND (arg0, 0), + TREE_OPERAND (arg0, 1), + op1, op2); if (tem) return tem; } @@ -12831,14 +12834,16 @@ fold_ternary_loc (location_t loc, enum tree_code code, tree type, && operand_equal_for_comparison_p (TREE_OPERAND (arg0, 0), op2) && !HONOR_SIGNED_ZEROS (element_mode (op2))) { - location_t loc0 = expr_location_or (arg0, loc); - tem = fold_invert_truthvalue (loc0, arg0); - if (tem && COMPARISON_CLASS_P (tem)) - { - tem = fold_cond_expr_with_comparison (loc, type, tem, op2, op1); - if (tem) - return tem; - } + enum tree_code comp_code = TREE_CODE (arg0); + tree arg00 = TREE_OPERAND (arg0, 0); + tree arg01 = TREE_OPERAND (arg0, 1); + comp_code = invert_tree_comparison (comp_code, HONOR_NANS (arg00)); + tem = fold_cond_expr_with_comparison (loc, type, comp_code, + arg00, + arg01, + op2, op1); + if (tem) + return tem; } /* If the second operand is simpler than the third, swap them 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; From patchwork Sat Jun 19 21:43:00 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: 1494710 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=PfpvBNfB; 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 4G6q711Bhxz9sRf for ; Sun, 20 Jun 2021 07:43:55 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 550DA3890425 for ; Sat, 19 Jun 2021 21:43:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 550DA3890425 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1624139030; bh=0OQgkVl7ivOHiCz9HHemUcw+NXgDt3Mex2LjAC8xQ88=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=PfpvBNfBBcuYlbltT0acyLLVpMLYdbnVvQcytdY+OqvMczEV47owV03ZGML2QoPtf 98pbvyrCDJh/4nG+sb/Cwa7rcigUXZ4fZNLOwSzutgJCfZ+hiraonDvYRQ5xs9rlFx 8/K7lVQ2RwOEgHWBF3D/Os0X0luHzv4sYuQqrQs8= 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 B4611385EC56 for ; Sat, 19 Jun 2021 21:43:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B4611385EC56 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 15JLh5Jd029727 for ; Sat, 19 Jun 2021 14:43:05 -0700 Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0a-0016f401.pphosted.com with ESMTP id 399dxrhjv9-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-EXCH01.marvell.com (10.69.176.38) 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:04 -0700 Received: from linux.wrightpinski.org.com (unknown [10.69.242.197]) by maili.marvell.com (Postfix) with ESMTP id 1056D5C68E4; Sat, 19 Jun 2021 14:43:04 -0700 (PDT) To: Subject: [PATCH 6/7] Lower for loops before lowering cond in genmatch Date: Sat, 19 Jun 2021 14:43:00 -0700 Message-ID: <1624138980-5805-2-git-send-email-apinski@marvell.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1624138980-5805-1-git-send-email-apinski@marvell.com> References: <1624138980-5805-1-git-send-email-apinski@marvell.com> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: jcjhWlIbX3Ny5lhmlyDPaiihd6U1VEc7 X-Proofpoint-GUID: jcjhWlIbX3Ny5lhmlyDPaiihd6U1VEc7 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.5 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 While converting some fold_cond_expr_with_comparison to match, I found that I wanted to use "for cnd (cond vec_cond)" but that was not causing the lowering of cond to happen. What was happening was the lowering of the for loop was happening after the lowering of the cond. So swapping was the correct thing to do but it also means we need to copy for_subst_vec in lower_cond. OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions. gcc/ChangeLog: * genmatch.c (lower_cond): Copy for_subst_vec for the simplify also. (lower): Swap the order for lower_for and lower_cond. --- gcc/genmatch.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/gcc/genmatch.c b/gcc/genmatch.c index 4d47672..3aee3dd 100644 --- a/gcc/genmatch.c +++ b/gcc/genmatch.c @@ -1306,6 +1306,7 @@ lower_cond (simplify *s, vec& simplifiers) { simplify *ns = new simplify (s->kind, s->id, matchers[i], s->result, s->for_vec, s->capture_ids); + ns->for_subst_vec.safe_splice (s->for_subst_vec); simplifiers.safe_push (ns); } } @@ -1543,24 +1544,23 @@ static void lower (vec& simplifiers, bool gimple) { auto_vec out_simplifiers; - for (unsigned i = 0; i < simplifiers.length (); ++i) - lower_opt (simplifiers[i], out_simplifiers); + for (auto s: simplifiers) + lower_opt (s, out_simplifiers); simplifiers.truncate (0); - for (unsigned i = 0; i < out_simplifiers.length (); ++i) - lower_commutative (out_simplifiers[i], simplifiers); + for (auto s: out_simplifiers) + lower_commutative (s, simplifiers); out_simplifiers.truncate (0); - if (gimple) - for (unsigned i = 0; i < simplifiers.length (); ++i) - lower_cond (simplifiers[i], out_simplifiers); - else - out_simplifiers.safe_splice (simplifiers); - + for (auto s: simplifiers) + lower_for (s, out_simplifiers); simplifiers.truncate (0); - for (unsigned i = 0; i < out_simplifiers.length (); ++i) - lower_for (out_simplifiers[i], simplifiers); + if (gimple) + for (auto s: out_simplifiers) + lower_cond (s, simplifiers); + else + simplifiers.safe_splice (out_simplifiers); } From patchwork Sat Jun 19 21:49:05 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: 1494712 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=2620:52:3:1:0:246e:9693:128c; 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=Ccgle7NK; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (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 4G6qFz2Q0Zz9sRf for ; Sun, 20 Jun 2021 07:49:57 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 946623890435 for ; Sat, 19 Jun 2021 21:49:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 946623890435 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1624139394; bh=J3fsy7UDuFQUJzqD2/jhBGLWReyYQIqOU9Ui0RzpEqg=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=Ccgle7NKXP1Fthusne0QYxvouF73VcwysYVbExLkb9kFCMincD4pcpNEgLQZpGDYU qWAAbHa9kp0m5/zXD2REM4ilSrwsrH3Mqh7+1jcjaACBwdQTuVBqDWvFqrkJMetZBl CDz0SgA3ipMmoRPKCF2XzHbsGy8Knl8UgGjuofUE= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by sourceware.org (Postfix) with ESMTPS id 0692638515EB for ; Sat, 19 Jun 2021 21:49:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0692638515EB Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 15JLm3X0031788 for ; Sat, 19 Jun 2021 14:49:10 -0700 Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0b-0016f401.pphosted.com with ESMTP id 399g3qh72x-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Sat, 19 Jun 2021 14:49:10 -0700 Received: from DC5-EXCH02.marvell.com (10.69.176.39) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Sat, 19 Jun 2021 14:49:08 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server id 15.0.1497.18 via Frontend Transport; Sat, 19 Jun 2021 14:49:08 -0700 Received: from linux.wrightpinski.org.com (unknown [10.69.242.197]) by maili.marvell.com (Postfix) with ESMTP id 28B445E6866; Sat, 19 Jun 2021 14:49:08 -0700 (PDT) To: Subject: [PATCH 7/7] Port most of the A CMP 0 ? A : -A to match Date: Sat, 19 Jun 2021 14:49:05 -0700 Message-ID: <1624139345-6908-1-git-send-email-apinski@marvell.com> X-Mailer: git-send-email 1.8.3.1 MIME-Version: 1.0 X-Proofpoint-GUID: SjAGWukBmXaYpRCGyZRp1uWri6GU88SL X-Proofpoint-ORIG-GUID: SjAGWukBmXaYpRCGyZRp1uWri6GU88SL 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.5 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 improve phiopt and be able to remove abs_replacement, this ports most of "A CMP 0 ? A : -A" from fold_cond_expr_with_comparison to match.pd. There is a few extra changes that are needed to remove the "A CMP 0 ? A : -A" part from fold_cond_expr_with_comparison: * Need to handle (A - B) case * Need to handle UN* comparisons. I will handle those in a different patch. Note phi-opt-15.c test needed to be updated as we get ABSU now instead of not getting ABS. When ABSU was added phiopt was not updated even to use ABSU instead of not creating ABS. OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions. gcc/ChangeLog: * match.pd (A CMP 0 ? A : -A): New patterns. * tree-ssa-phiopt.c (abs_replacement): Delete function. (tree_ssa_phiopt_worker): Don't call abs_replacement. Update comment about abs_replacement. gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/phi-opt-15.c: Update test to expect ABSU and still not expect ABS_EXPR. --- gcc/match.pd | 60 +++++++++++++ gcc/testsuite/gcc.dg/tree-ssa/phi-opt-15.c | 4 +- gcc/tree-ssa-phiopt.c | 134 +---------------------------- 3 files changed, 64 insertions(+), 134 deletions(-) diff --git a/gcc/match.pd b/gcc/match.pd index f38baf2..a5cfb4e5 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -3977,6 +3977,66 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (cnd (logical_inverted_value truth_valued_p@0) @1 @2) (cnd @0 @2 @1))) +/* abs/negative simplifications moved from fold_cond_expr_with_comparison, + Need to handle (A - B) case as fold_cond_expr_with_comparison does. + Need to handle UN* comparisons. + + None of these transformations work for modes with signed + zeros. If A is +/-0, the first two transformations will + change the sign of the result (from +0 to -0, or vice + versa). The last four will fix the sign of the result, + even though the original expressions could be positive or + negative, depending on the sign of A. + + Note that all these transformations are correct if A is + NaN, since the two alternatives (A and -A) are also NaNs. */ + +(for cnd (cond vec_cond) + /* A == 0? A : -A same as -A */ + (for cmp (eq uneq) + (simplify + (cnd (cmp @0 zerop) @0 (negate@1 @0)) + (if (!HONOR_SIGNED_ZEROS (element_mode (type))) + @1)) + (simplify + (cnd (cmp @0 zerop) zerop (negate@1 @0)) + (if (!HONOR_SIGNED_ZEROS (element_mode (type))) + @1)) + ) + /* A != 0? A : -A same as A */ + (for cmp (ne ltgt) + (simplify + (cnd (cmp @0 zerop) @0 (negate @0)) + (if (!HONOR_SIGNED_ZEROS (element_mode (type))) + @0)) + (simplify + (cnd (cmp @0 zerop) @0 zerop) + (if (!HONOR_SIGNED_ZEROS (element_mode (type))) + @0)) + ) + /* A >=/> 0? A : -A same as abs (A) */ + (for cmp (ge gt) + (simplify + (cnd (cmp @0 zerop) @0 (negate @0)) + (if (!HONOR_SIGNED_ZEROS (element_mode (type)) + && !TYPE_UNSIGNED (type)) + (abs @0)))) + /* A <=/< 0? A : -A same as -abs (A) */ + (for cmp (le lt) + (simplify + (cnd (cmp @0 zerop) @0 (negate @0)) + (if (!HONOR_SIGNED_ZEROS (element_mode (type)) + && !TYPE_UNSIGNED (type)) + (if (ANY_INTEGRAL_TYPE_P (type) + && !TYPE_OVERFLOW_WRAPS (type)) + (with { + tree utype = unsigned_type_for (type); + } + (convert (negate (absu:utype @0)))) + (negate (abs @0))))) + ) +) + /* -(type)!A -> (type)A - 1. */ (simplify (negate (convert?:s (logical_inverted_value:s @0))) diff --git a/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-15.c b/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-15.c index ac3018e..6aec689 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-15.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-15.c @@ -9,4 +9,6 @@ foo (int i) return i; } -/* { dg-final { scan-tree-dump-not "ABS" "optimized" } } */ +/* We should not have ABS_EXPR but ABSU_EXPR instead. */ +/* { dg-final { scan-tree-dump-not "ABS_EXPR" "optimized" } } */ +/* { dg-final { scan-tree-dump "ABSU" "optimized" } } */ diff --git a/gcc/tree-ssa-phiopt.c b/gcc/tree-ssa-phiopt.c index 8b289be..ab5aef9 100644 --- a/gcc/tree-ssa-phiopt.c +++ b/gcc/tree-ssa-phiopt.c @@ -62,8 +62,6 @@ static int value_replacement (basic_block, basic_block, edge, edge, gphi *, tree, tree); static bool minmax_replacement (basic_block, basic_block, edge, edge, gphi *, tree, tree); -static bool abs_replacement (basic_block, basic_block, - edge, edge, gphi *, tree, tree); static bool spaceship_replacement (basic_block, basic_block, edge, edge, gphi *, tree, tree); static bool cond_removal_in_popcount_clz_ctz_pattern (basic_block, basic_block, @@ -350,8 +348,6 @@ tree_ssa_phiopt_worker (bool do_store_elim, bool do_hoist_loads, bool early_p) 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; else if (!early_p && cond_removal_in_popcount_clz_ctz_pattern (bb, bb1, e1, e2, phi, arg0, @@ -2550,134 +2546,6 @@ cond_removal_in_popcount_clz_ctz_pattern (basic_block cond_bb, return true; } -/* The function absolute_replacement does the main work of doing the absolute - replacement. Return true if the replacement is done. Otherwise return - false. - bb is the basic block where the replacement is going to be done on. arg0 - is argument 0 from the phi. Likewise for arg1. */ - -static bool -abs_replacement (basic_block cond_bb, basic_block middle_bb, - edge e0 ATTRIBUTE_UNUSED, edge e1, - gphi *phi, tree arg0, tree arg1) -{ - tree result; - gassign *new_stmt; - gimple *cond; - gimple_stmt_iterator gsi; - edge true_edge, false_edge; - gimple *assign; - edge e; - tree rhs, lhs; - bool negate; - enum tree_code cond_code; - - /* If the type says honor signed zeros we cannot do this - optimization. */ - if (HONOR_SIGNED_ZEROS (arg1)) - return false; - - /* OTHER_BLOCK must have only one executable statement which must have the - form arg0 = -arg1 or arg1 = -arg0. */ - - assign = last_and_only_stmt (middle_bb); - /* If we did not find the proper negation assignment, then we cannot - optimize. */ - if (assign == NULL) - return false; - - /* If we got here, then we have found the only executable statement - in OTHER_BLOCK. If it is anything other than arg = -arg1 or - arg1 = -arg0, then we cannot optimize. */ - if (gimple_code (assign) != GIMPLE_ASSIGN) - return false; - - lhs = gimple_assign_lhs (assign); - - if (gimple_assign_rhs_code (assign) != NEGATE_EXPR) - return false; - - rhs = gimple_assign_rhs1 (assign); - - /* The assignment has to be arg0 = -arg1 or arg1 = -arg0. */ - if (!(lhs == arg0 && rhs == arg1) - && !(lhs == arg1 && rhs == arg0)) - return false; - - cond = last_stmt (cond_bb); - result = PHI_RESULT (phi); - - /* Only relationals comparing arg[01] against zero are interesting. */ - cond_code = gimple_cond_code (cond); - if (cond_code != GT_EXPR && cond_code != GE_EXPR - && cond_code != LT_EXPR && cond_code != LE_EXPR) - return false; - - /* Make sure the conditional is arg[01] OP y. */ - if (gimple_cond_lhs (cond) != rhs) - return false; - - if (FLOAT_TYPE_P (TREE_TYPE (gimple_cond_rhs (cond))) - ? real_zerop (gimple_cond_rhs (cond)) - : integer_zerop (gimple_cond_rhs (cond))) - ; - else - return false; - - /* We need to know which is the true edge and which is the false - edge so that we know if have abs or negative abs. */ - extract_true_false_edges_from_block (cond_bb, &true_edge, &false_edge); - - /* For GT_EXPR/GE_EXPR, if the true edge goes to OTHER_BLOCK, then we - will need to negate the result. Similarly for LT_EXPR/LE_EXPR if - the false edge goes to OTHER_BLOCK. */ - if (cond_code == GT_EXPR || cond_code == GE_EXPR) - e = true_edge; - else - e = false_edge; - - if (e->dest == middle_bb) - negate = true; - else - negate = false; - - /* If the code negates only iff positive then make sure to not - introduce undefined behavior when negating or computing the absolute. - ??? We could use range info if present to check for arg1 == INT_MIN. */ - if (negate - && (ANY_INTEGRAL_TYPE_P (TREE_TYPE (arg1)) - && ! TYPE_OVERFLOW_WRAPS (TREE_TYPE (arg1)))) - return false; - - result = duplicate_ssa_name (result, NULL); - - if (negate) - lhs = make_ssa_name (TREE_TYPE (result)); - else - lhs = result; - - /* Build the modify expression with abs expression. */ - new_stmt = gimple_build_assign (lhs, ABS_EXPR, rhs); - - gsi = gsi_last_bb (cond_bb); - gsi_insert_before (&gsi, new_stmt, GSI_NEW_STMT); - - if (negate) - { - /* Get the right GSI. We want to insert after the recently - added ABS_EXPR statement (which we know is the first statement - in the block. */ - new_stmt = gimple_build_assign (result, NEGATE_EXPR, lhs); - - gsi_insert_after (&gsi, new_stmt, GSI_NEW_STMT); - } - - replace_phi_edge_with_variable (cond_bb, e1, phi, result); - - /* Note that we optimized this PHI. */ - return true; -} - /* Auxiliary functions to determine the set of memory accesses which can't trap because they are preceded by accesses to the same memory portion. We do that for MEM_REFs, so we only need to track @@ -3611,7 +3479,7 @@ gate_hoist_loads (void) ABS Replacement --------------- - This transformation, implemented in abs_replacement, replaces + This transformation, implemented in match_simplify_replacement, replaces bb0: if (a >= 0) goto bb2; else goto bb1;