From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by sourceware.org (Postfix) with ESMTPS id 4AC533858D1E for ; Mon, 17 Jul 2023 02:43:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4AC533858D1E 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 (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 36H00SLt012207 for ; Sun, 16 Jul 2023 19:43:12 -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=7I/B9mO1NmDnGi3W1+MjH0qIsG2YvSBE9LKJpqGOQ9Y=; b=Au1al2E46JO4zof4p7i6uFydpJ2gvzGsTYsih+PnQ+PZrAHT3KTe4OsZwQXvLiQLNvkQ ESOFQXJPmWtQlh9cKO5L6gUs938wmLdjebf2+c2n855wlfpQttlkDYaZm0V0UiC+oANN QCa00P0rH7tIUVF/HyNZnv/wsvMLLb4KNtFjNehN/NVf7pv1H0uJhEzThRfupgqpx64L Z9zKY+1LdN81YtW+v4hFSYTCCtt3n5Uz+4BTKi+y7TdkMCR2oYderxVdcnhVhXs00HSC RoNzrEQdwyZ1I6JqUkNDq0vW5SQ2t2a0aYQ9lc8VwKtm5OBC3q27PgvSj45Od4bDOrd2 2Q== Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3rus6dbp1u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Sun, 16 Jul 2023 19:43:12 -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.48; Sun, 16 Jul 2023 19:43:11 -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.48 via Frontend Transport; Sun, 16 Jul 2023 19:43:11 -0700 Received: from vpnclient.wrightpinski.org.com (unknown [10.69.242.187]) by maili.marvell.com (Postfix) with ESMTP id ED0273F7063; Sun, 16 Jul 2023 19:43:10 -0700 (PDT) From: Andrew Pinski To: CC: Andrew Pinski Subject: [PATCH] PR 95923: More (boolean) bitop simplifications in match.pd Date: Sun, 16 Jul 2023 19:42:47 -0700 Message-ID: <20230717024247.1263484-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: uSq-gZ3VRqgaPS50oKQWNxQoIKWjPis9 X-Proofpoint-ORIG-GUID: uSq-gZ3VRqgaPS50oKQWNxQoIKWjPis9 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-07-17_01,2023-07-13_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,T_SCC_BODY_TEXT_LINE 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 the boolean version of some of the simplifications that were added with r8-4395-ge268a77b59cb78. That are the following: (a | b) & (a == b) --> a & b a | (a == b) --> a | (b ^ 1) (a & b) | (a == b) --> a == b OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions. gcc/ChangeLog: PR tree-optimization/95923 * match.pd ((a|b)&(a==b),a|(a==b),(a&b)|(a==b)): New transformation. gcc/testsuite/ChangeLog: PR tree-optimization/95923 * gcc.dg/tree-ssa/bitops-2.c: New test. * gcc.dg/tree-ssa/bool-checks-1.c: New test. --- gcc/match.pd | 15 +++++++ gcc/testsuite/gcc.dg/tree-ssa/bitops-2.c | 41 +++++++++++++++++++ gcc/testsuite/gcc.dg/tree-ssa/bool-checks-1.c | 22 ++++++++++ 3 files changed, 78 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/bitops-2.c create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/bool-checks-1.c diff --git a/gcc/match.pd b/gcc/match.pd index 351d9285e92..5e812d804d0 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -1226,11 +1226,21 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (bit_and:c (bit_ior @0 @1) (bit_not (bit_xor:c @0 @1))) (bit_and @0 @1)) +/* (a | b) & (a == b) --> a & b (boolean version of the above). */ +(simplify + (bit_and:c (bit_ior @0 @1) (nop_convert? (eq:c @0 @1))) + (bit_and @0 @1)) + /* a | ~(a ^ b) --> a | ~b */ (simplify (bit_ior:c @0 (bit_not:s (bit_xor:c @0 @1))) (bit_ior @0 (bit_not @1))) +/* a | (a == b) --> a | (b^1) (boolean version of the above). */ +(simplify + (bit_ior:c @0 (nop_convert? (eq:c @0 @1))) + (bit_ior @0 (bit_xor @1 { build_one_cst (type); }))) + /* (a | b) | (a &^ b) --> a | b */ (for op (bit_and bit_xor) (simplify @@ -1242,6 +1252,11 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (bit_ior:c (bit_and:c @0 @1) (bit_not@2 (bit_xor @0 @1))) @2) +/* (a & b) | (a == b) --> a == b */ +(simplify + (bit_ior:c (bit_and:c @0 @1) (nop_convert?@2 (eq @0 @1))) + @2) + /* ~(~a & b) --> a | ~b */ (simplify (bit_not (bit_and:cs (bit_not @0) @1)) diff --git a/gcc/testsuite/gcc.dg/tree-ssa/bitops-2.c b/gcc/testsuite/gcc.dg/tree-ssa/bitops-2.c new file mode 100644 index 00000000000..d8128f3ca53 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/bitops-2.c @@ -0,0 +1,41 @@ +/* { dg-do run } */ +/* { dg-options "-O -fdump-tree-optimized-raw" } */ + +#define DECLS(n,VOL) \ +__attribute__((noinline,noclone)) \ +_Bool h##n(_Bool A,_Bool B){ \ + VOL _Bool C = A | B; \ + VOL _Bool D = A == B; \ + return C & D; \ +} \ +__attribute__((noinline,noclone)) \ +_Bool i##n(_Bool A,_Bool B){ \ + VOL _Bool C = A == B; \ + return A | C; \ +} \ +__attribute__((noinline,noclone)) \ +_Bool k##n(_Bool A,_Bool B){ \ + VOL _Bool C = A & B; \ + VOL _Bool D = A == B; \ + return C | D; \ +} \ + +DECLS(0,) +DECLS(1,volatile) + +int main(){ + for(int A = 0; A <= 1; ++A) + for(int B = 0; B <= 1; ++B) + { + if (h0 (A, B) != h1 (A, B)) __builtin_abort(); + if (i0 (A, B) != i1 (A, B)) __builtin_abort(); + if (k0 (A, B) != k1 (A, B)) __builtin_abort(); + } +} + +/* { dg-final { scan-tree-dump-times "bit_not_expr," 1 "optimized"} } */ +/* { dg-final { scan-tree-dump-times "bit_and_expr," 3 "optimized"} } */ +/* { dg-final { scan-tree-dump-times "bit_ior_expr," 4 "optimized"} } */ +/* { dg-final { scan-tree-dump-times "eq_expr," 4 "optimized"} } */ +/* { dg-final { scan-tree-dump-times "ne_expr," 7 "optimized"} } */ +/* { dg-final { scan-tree-dump-not "bit_xor_expr," "optimized"} } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/bool-checks-1.c b/gcc/testsuite/gcc.dg/tree-ssa/bool-checks-1.c new file mode 100644 index 00000000000..370a23aad3e --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/bool-checks-1.c @@ -0,0 +1,22 @@ +/* { dg-do compile } */ +/* { dg-options "-O1 -fdump-tree-optimized-raw" } */ +/* PR tree-optimization/95923 */ + +_Bool f(_Bool a, _Bool b) +{ + if (!a && !b) + return 0; + if (!a && b) + return 0; + if (a && !b) + return 0; + return 1; +} + +/* { dg-final { scan-tree-dump-times "bit_and_expr," 1 "optimized"} } */ +/* { dg-final { scan-tree-dump-not "bit_not_expr," "optimized"} } */ +/* { dg-final { scan-tree-dump-not "bit_ior_expr," "optimized"} } */ +/* { dg-final { scan-tree-dump-not "bit_xor_expr," "optimized"} } */ +/* { dg-final { scan-tree-dump-not "eq_expr," "optimized"} } */ +/* { dg-final { scan-tree-dump-not "ne_expr," "optimized"} } */ +/* { dg-final { scan-tree-dump-not "gimple_cond" "optimized"} } */ -- 2.31.1