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 19C2F3856089 for ; Wed, 19 Jul 2023 01:52:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 19C2F3856089 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 36IIGVZg005070 for ; Tue, 18 Jul 2023 18:52:36 -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=38mXDTuHwjcUfqlai7Sv9uApsJEkaY/oeZ40At7EakI=; b=dvwkY3AJq5V9ViDGqNzP6HTgVqiqQx8kjV122r+/+UCNAe+osDo/ZCbqNqcBk8iEgr83 sEq+FsqxnO9fmUOZTJ1jviv+YNKzaXj+q5YlKyTFYKKs73IdzOoz6Iw6ZySm47uS9o2T iu0HbxHCzdEELw9HDVz/ag7vT5ho/4HCYAyYP8E5afFc5sdEYnvcU1gWhceNZmN8Y8dt LJ7Ch1oGAtCKwv0kIAn5sXt/S4ky4Yk05bcgpskroNUszwum7MAT1WnRDbcOfK37eb8X azCzty9/baks0TltdOF7ZsruuDZYoQXCcBy+131sYCGAyRsfJvNI5ZDk0w1m/GV0J5ay wA== Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3rwyc799uv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Tue, 18 Jul 2023 18:52:36 -0700 Received: from DC5-EXCH02.marvell.com (10.69.176.39) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server (TLS) id 15.0.1497.48; Tue, 18 Jul 2023 18:52:35 -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; Tue, 18 Jul 2023 18:52:34 -0700 Received: from vpnclient.wrightpinski.org.com (unknown [10.69.242.187]) by maili.marvell.com (Postfix) with ESMTP id ECE873F705E; Tue, 18 Jul 2023 18:52:34 -0700 (PDT) From: Andrew Pinski To: CC: Andrew Pinski Subject: [PATCH] Fix PR110726: a | (a == b) can sometimes produce wrong code Date: Tue, 18 Jul 2023 18:52:21 -0700 Message-ID: <20230719015221.1383859-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: 5wohNVRfZIGEfrbkJ8yWaK7sWB4enbNb X-Proofpoint-ORIG-GUID: 5wohNVRfZIGEfrbkJ8yWaK7sWB4enbNb 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-18_19,2023-07-18_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: So I had missed/forgot that EQ_EXPR could have an non boolean type for generic when I implemented r14-2556-g0407ae8a7732d9. This patch adds check for one bit precision intergal type which fixes the problem. OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions. PR tree-optimization/110726 gcc/ChangeLog: * match.pd ((a|b)&(a==b),a|(a==b),(a&b)|(a==b)): Add checks to make sure the type was one bit precision intergal type. gcc/testsuite/ChangeLog: * gcc.c-torture/execute/bitops-1.c: New test. --- gcc/match.pd | 12 +++++-- .../gcc.c-torture/execute/bitops-1.c | 33 +++++++++++++++++++ 2 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gcc.c-torture/execute/bitops-1.c diff --git a/gcc/match.pd b/gcc/match.pd index 054e6585876..4dfe92623f7 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -1229,7 +1229,9 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) /* (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)) + (if (INTEGRAL_TYPE_P (TREE_TYPE (@0)) + && TYPE_PRECISION (TREE_TYPE (@0)) == 1) + (bit_and @0 @1))) /* a | ~(a ^ b) --> a | ~b */ (simplify @@ -1239,7 +1241,9 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) /* 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); }))) + (if (INTEGRAL_TYPE_P (TREE_TYPE (@0)) + && TYPE_PRECISION (TREE_TYPE (@0)) == 1) + (bit_ior @0 (bit_xor @1 { build_one_cst (type); })))) /* (a | b) | (a &^ b) --> a | b */ (for op (bit_and bit_xor) @@ -1255,7 +1259,9 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) /* (a & b) | (a == b) --> a == b */ (simplify (bit_ior:c (bit_and:c @0 @1) (nop_convert?@2 (eq @0 @1))) - @2) + (if (INTEGRAL_TYPE_P (TREE_TYPE (@0)) + && TYPE_PRECISION (TREE_TYPE (@0)) == 1) + @2)) /* ~(~a & b) --> a | ~b */ (simplify diff --git a/gcc/testsuite/gcc.c-torture/execute/bitops-1.c b/gcc/testsuite/gcc.c-torture/execute/bitops-1.c new file mode 100644 index 00000000000..cfaa6b9fd26 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/bitops-1.c @@ -0,0 +1,33 @@ +/* PR tree-optimization/110726 */ + +#define DECLS(n,VOL) \ +__attribute__((noinline,noclone)) \ +int h##n(VOL int A, VOL int B){ \ + return (A | B) & (A == B); \ +} \ +__attribute__((noinline,noclone)) \ +int i##n(VOL int A, VOL int B){ \ + return A | (A == B); \ +} \ +__attribute__((noinline,noclone)) \ +int k##n(VOL int A, VOL int B){ \ + return (A & B) | (A == B); \ +} \ + +DECLS(0,) +DECLS(1,volatile) + +int values[] = { 0, 1, 2, 3, -1, -2, -3, 0x10080 }; +int numvalues = sizeof(values)/sizeof(values[0]); + +int main(){ + for(int A = 0; A < numvalues; A++) + for(int B = 0; B < numvalues; B++) + { + int a = values[A]; + int b = values[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(); + } +} -- 2.31.1