From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by sourceware.org (Postfix) with ESMTPS id 20F243858C41 for ; Tue, 8 Aug 2023 00:54:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 20F243858C41 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=marvell.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=marvell.com Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 377G3bNE008678 for ; Mon, 7 Aug 2023 17:54:34 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : mime-version : content-transfer-encoding : content-type; s=pfpt0220; bh=rt4WPLD4AvmSRXhTEQdW674fU4dnhVEglY4Pa83exi8=; b=R0BvJkqGk//y6EPqJ09bH9W6OirqBVlweRcueLwNlwYdnx69U+Nng5/6hreIb2S6fVui KvaygYbXruP4zftJqaa37C4jrLmitIBfEnf7LFMeuIG9xkG86Yl6WM7HzjpvNvjs9iSH RNAnBmNjbxSqtZKMZ7QgxPftIDU5Wp/xqVP/HXj4GucJiPZFvPiP9ayJoZADZYWynjCZ 6jkeqnEL+blLWx7ZFaCJv66uYd2+q+HF2js5pA0bbgR2YbYbKI1C24PepRSBlL3WmaAO sfnBDVWiAoTKqNhKtBHUM0ufiIWZtdbqYqWeIPt56f75kZyrODFwTBAo4YXO3YYGhrnC Uw== Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 3s9nxkxpny-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Mon, 07 Aug 2023 17:54:34 -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.48; Mon, 7 Aug 2023 17:54:32 -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.48 via Frontend Transport; Mon, 7 Aug 2023 17:54:32 -0700 Received: from vpnclient.wrightpinski.org.com (unknown [10.69.242.187]) by maili.marvell.com (Postfix) with ESMTP id ECFE93F703F; Mon, 7 Aug 2023 17:54:31 -0700 (PDT) From: Andrew Pinski To: CC: Andrew Pinski Subject: [PATCH] MATCH: [PR110937/PR100798] (a ? ~b : b) should be optimized to b ^ -(a) Date: Mon, 7 Aug 2023 17:54:24 -0700 Message-ID: <20230808005424.2563140-1-apinski@marvell.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Proofpoint-GUID: OunZ7BYr0eku-szw_yy2ZfzonPiZx8Fu X-Proofpoint-ORIG-GUID: OunZ7BYr0eku-szw_yy2ZfzonPiZx8Fu X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-08-07_27,2023-08-03_01,2023-05-22_02 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.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: This adds a simple match pattern for this case. I noticed it a couple of different places. One while I was looking at code generation of a parser and also while I was looking at locations where bitwise_inverted_equal_p should be used more. OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions. PR tree-optimization/110937 PR tree-optimization/100798 gcc/ChangeLog: * match.pd (`a ? ~b : b`): Handle this case. gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/bool-14.c: New test. * gcc.dg/tree-ssa/bool-15.c: New test. * gcc.dg/tree-ssa/phi-opt-33.c: New test. * gcc.dg/tree-ssa/20030709-2.c: Update testcase so `a ? -1 : 0` is not used to hit the match pattern. --- gcc/match.pd | 13 +++++++++++++ gcc/testsuite/gcc.dg/tree-ssa/20030709-2.c | 5 +++-- gcc/testsuite/gcc.dg/tree-ssa/bool-14.c | 15 +++++++++++++++ gcc/testsuite/gcc.dg/tree-ssa/bool-15.c | 18 ++++++++++++++++++ gcc/testsuite/gcc.dg/tree-ssa/phi-opt-33.c | 13 +++++++++++++ 5 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/bool-14.c create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/bool-15.c create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/phi-opt-33.c diff --git a/gcc/match.pd b/gcc/match.pd index 9b4819e5be7..f887c517c81 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -6460,6 +6460,19 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (if (cmp == NE_EXPR) { constant_boolean_node (true, type); }))))))) +#if GIMPLE +/* a?~t:t -> (-(a))^t */ +(simplify + (cond @0 @1 @2) + (if (bitwise_inverted_equal_p (@1, @2)) + (with { + auto prec = TYPE_PRECISION (type); + auto unsign = TYPE_UNSIGNED (type); + tree inttype = build_nonstandard_integer_type (prec, unsign); + } + (convert (bit_xor (negate (convert:inttype @0)) (convert:inttype @2)))))) +#endif + /* Simplify pointer equality compares using PTA. */ (for neeq (ne eq) (simplify diff --git a/gcc/testsuite/gcc.dg/tree-ssa/20030709-2.c b/gcc/testsuite/gcc.dg/tree-ssa/20030709-2.c index 5009cd69cfe..78938f919d4 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/20030709-2.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/20030709-2.c @@ -29,15 +29,16 @@ union tree_node }; int make_decl_rtl (tree, int); void * -get_alias_set (t) +get_alias_set (t, t1) tree t; + void *t1; { long set; if (t->decl.rtl) return (t->decl.rtl->fld[1].rtmem ? 0 : (((t->decl.rtl ? t->decl.rtl: (make_decl_rtl (t, 0), t->decl.rtl)))->fld[1]).rtmem); - return (void*)-1; + return t1; } /* There should be precisely one load of ->decl.rtl. If there is diff --git a/gcc/testsuite/gcc.dg/tree-ssa/bool-14.c b/gcc/testsuite/gcc.dg/tree-ssa/bool-14.c new file mode 100644 index 00000000000..0149380a63b --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/bool-14.c @@ -0,0 +1,15 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized-raw" } */ +/* PR tree-optimization/110937 */ + +_Bool f2(_Bool a, _Bool b) +{ + if (a) + return !b; + return b; +} + +/* We should be able to remove the conditional and convert it to an xor. */ +/* { dg-final { scan-tree-dump-not "gimple_cond " "optimized" } } */ +/* { dg-final { scan-tree-dump-not "gimple_phi " "optimized" } } */ +/* { dg-final { scan-tree-dump-times "bit_xor_expr, " 1 "optimized" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/bool-15.c b/gcc/testsuite/gcc.dg/tree-ssa/bool-15.c new file mode 100644 index 00000000000..1f496663863 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/bool-15.c @@ -0,0 +1,18 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized-raw" } */ +/* PR tree-optimization/110937 */ + +_Bool f2(int x, int y, int w, int z) +{ + _Bool a = x == y; + _Bool b = w == z; + if (a) + return !b; + return b; +} + +/* We should be able to remove the conditional and convert it to an xor. */ +/* { dg-final { scan-tree-dump-not "gimple_cond " "optimized" } } */ +/* { dg-final { scan-tree-dump-not "gimple_phi " "optimized" } } */ +/* { dg-final { scan-tree-dump-not "ne_expr, " "optimized" } } */ +/* { dg-final { scan-tree-dump-times "bit_xor_expr, " 1 "optimized" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-33.c b/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-33.c new file mode 100644 index 00000000000..b79fe44187a --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-33.c @@ -0,0 +1,13 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized-raw" } */ +/* PR tree-optimization/100798 */ + +int f(int a, int t) +{ + return (a=='s' ? ~t : t); +} + +/* This should be convert into t^-(a=='s'). */ +/* { dg-final { scan-tree-dump-times "bit_xor_expr, " 1 "optimized" } } */ +/* { dg-final { scan-tree-dump-times "negate_expr, " 1 "optimized" } } */ +/* { dg-final { scan-tree-dump-not "bit_not_expr, " "optimized" } } */ -- 2.31.1