From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR01-HE1-obe.outbound.protection.outlook.com (mail-eopbgr130058.outbound.protection.outlook.com [40.107.13.58]) by sourceware.org (Postfix) with ESMTPS id 00E9C3858D28 for ; Mon, 17 Oct 2022 09:17:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 00E9C3858D28 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=arm.com ARC-Seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=Ut44Xp4vMtj+7Y6tj7NrUtUE9cK2ppRjwhJSPBlfFrHdivlumFSESd5qJAlV2pbXhnwFeRgKiBJoWzsqX6sYFfeeBUPGiGLuCErYnW9r/X1umjkxvOrzaqFSDeN1rjFh+Qufdx41PwT7N8EZx6d0LTLEiRJB/rfj9thxcDG8GlmdsO8pcerkNAvWvFMaEfP91IDTSWMOVIetRpfbX2PesA/gWDLE82x7Yz484yhGgEFPLeb8cCfCMGyF37eBUYgwGBBW69yFSXfnZBbatSJEr8qloWJwnvb5N8+CF2Let0hsZHPLjWYmny62QoUqrjU230Gm1n1aEOCyFZE8OOn09w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=C4kb8gvQ29Wy4f8Q2U6GAkFiWpxk7ILkSMfPSuOVDIc=; b=Yce80MTYt/lP6YEICJB3gbw6Nd1mD+AxCgMgj0PxDUs1ClRBMkolH7XcdGlXHffiFzrfE+ShbSuaRnJ7ddBgyprx+nO55EstlO9UVpBgXQEcbTi37/ufSWB+maobaCSh+kHVQUmuNHzGHrxT5rL41e9bj4WDdOXCtjs3PcgzH/FCcCjCwqB/GG5GvbqtJrs31yQCN0FqLZjvKy1M3lwTGA1k3rEYxpbtYgVwbcSd0TwH141nHYH5FyY6XlcVU2BGkN7MRJSwE9tRuav1vIgNYYtathHerGpx0/B6qkTOWjg1ZKbWgSuT2szbHtvWQsv+9uZfOQOjqUOibJu9QXkqtQ== ARC-Authentication-Results: i=2; mx.microsoft.com 1; spf=pass (sender ip is 63.35.35.123) smtp.rcpttodomain=gcc.gnu.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com; arc=pass (0 oda=1 ltdi=1 spf=[1,1,smtp.mailfrom=arm.com] dkim=[1,1,header.d=arm.com] dmarc=[1,1,header.from=arm.com]) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=C4kb8gvQ29Wy4f8Q2U6GAkFiWpxk7ILkSMfPSuOVDIc=; b=Q+UX6qny6Qalb/bKmUskIzI3CyIDOcD4lF1QLR7kxEmzxPevlbFOYdFHd+Lzjrs1dKcPrE/Cihi99KQzrWDMrswU5jzg9avUl3kelZp6Jggj1jpQswVoBtwAGeU4Y8DbWhn0U43IS0viV4vK2M2BdnRm+nwsgpTTS/cvTCUf9nw= Received: from AM6PR02CA0035.eurprd02.prod.outlook.com (2603:10a6:20b:6e::48) by AS8PR08MB6087.eurprd08.prod.outlook.com (2603:10a6:20b:29c::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5723.29; Mon, 17 Oct 2022 09:17:40 +0000 Received: from AM7EUR03FT065.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:6e:cafe::a7) by AM6PR02CA0035.outlook.office365.com (2603:10a6:20b:6e::48) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5723.26 via Frontend Transport; Mon, 17 Oct 2022 09:17:40 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; pr=C Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by AM7EUR03FT065.mail.protection.outlook.com (100.127.140.250) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5723.20 via Frontend Transport; Mon, 17 Oct 2022 09:17:40 +0000 Received: ("Tessian outbound 2ff13c8f2c05:v130"); Mon, 17 Oct 2022 09:17:40 +0000 X-CR-MTA-TID: 64aa7808 Received: from bed263ec08af.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 7C568CCC-C997-4852-91C3-8F8C041751AC.1; Mon, 17 Oct 2022 09:17:34 +0000 Received: from EUR05-DB8-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id bed263ec08af.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Mon, 17 Oct 2022 09:17:34 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kxoIUpuPibd2svFW6XI/B1c2k6dlTdgzKBtqlfXKo1X+vbo9/yB8c1WSGlJCbH0rp7PZDLnEujgkUpIFpKtXaUGkEL58YGZ3Q6rvCz18B3R7LZbd+mypWt+AsJiONsjyvghaAV7UesT55RuZQz6WCEq931d6QQZNGIGVcniwYR6w4EOuxbueZrJgq0vc8KbNUD2KRFfeDNg2aSdpQR1eFvt7W9dx2i51eLiCbjauvtAJEcZ+E3fMu+qH3MTUC4C+4m1ZxzKp3ys+Si8o87WO9MNLxBCz+r1Qz0u+lWSFoFfwnz1Mt5WkcPsm6Lqbd/kvJG66/RuiteBZe2iZ4h8Idw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=C4kb8gvQ29Wy4f8Q2U6GAkFiWpxk7ILkSMfPSuOVDIc=; b=DZ7ksBNukx+yFuPLOOwmNSMrHhiYC99lENY93uP5z8ntu+1pcpwCn4dSt9AkKphAf/G4A8BHuIPKXxC2P5xo80lsg4aBCkzjrkGeMSaEex8RgacCsCTH+FCHj0Qmvh8kBChHgPWAZ7s+0EG2k8gNWVr0iXZ3T/ueqxgFsaRc/pF93zfCz038vuiotEcHTGQyY2w4LWk5bESdd36T1HcON8Zg4gOfdkVYmrqdSniji85rjdIikNyXGaRYBh0bCUdQ9BYu+SW0fbA8cd29HLsp/NSKxavPB2YDc6b8pwRhoVcskrNeeHT9ygDlFMNBgwjIHOc43solblEFc/SsvQq/Zw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=C4kb8gvQ29Wy4f8Q2U6GAkFiWpxk7ILkSMfPSuOVDIc=; b=Q+UX6qny6Qalb/bKmUskIzI3CyIDOcD4lF1QLR7kxEmzxPevlbFOYdFHd+Lzjrs1dKcPrE/Cihi99KQzrWDMrswU5jzg9avUl3kelZp6Jggj1jpQswVoBtwAGeU4Y8DbWhn0U43IS0viV4vK2M2BdnRm+nwsgpTTS/cvTCUf9nw= Received: from VI1PR08MB5325.eurprd08.prod.outlook.com (2603:10a6:803:13e::17) by VE1PR08MB5696.eurprd08.prod.outlook.com (2603:10a6:800:1ae::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5723.32; Mon, 17 Oct 2022 09:17:27 +0000 Received: from VI1PR08MB5325.eurprd08.prod.outlook.com ([fe80::5025:83a3:7d7b:7705]) by VI1PR08MB5325.eurprd08.prod.outlook.com ([fe80::5025:83a3:7d7b:7705%9]) with mapi id 15.20.5723.032; Mon, 17 Oct 2022 09:17:26 +0000 From: Tamar Christina To: Richard Biener CC: "gcc-patches@gcc.gnu.org" , nd , "jeffreyalaw@gmail.com" , "ebotcazou@adacore.com" Subject: RE: [PATCH]middle-end fix floating out of constants in conditionals Thread-Topic: [PATCH]middle-end fix floating out of constants in conditionals Thread-Index: AQHYzy3a0bo520wY60Wks8jMTS14OK3xhwqAgCDlzMA= Date: Mon, 17 Oct 2022 09:17:26 +0000 Message-ID: References: In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ts-tracking-id: 3E44B7FD33029744AA8BDD097690D5E1.0 x-checkrecipientchecked: true Authentication-Results-Original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; x-ms-traffictypediagnostic: VI1PR08MB5325:EE_|VE1PR08MB5696:EE_|AM7EUR03FT065:EE_|AS8PR08MB6087:EE_ X-MS-Office365-Filtering-Correlation-Id: 256a5a2f-59d5-4bee-9ff3-08dab02070f2 x-checkrecipientrouted: true nodisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: mEEWePtmEdPLIfQ9W42kKW4TaCqT90lskS9PK6JXA4jSXxHVE2EXS9sNN1Ms0v6IaNKUB3OcOAAoaqw/WGfpKNv/Z4x4n37Gf4RbSbK7u4ku+cOxptYCezg5xxYkRlLcrB1DZYBQ5hiI0h4V1gnUUoZUw+nNLZ1Op6cHIW/RDS2O9CKBTmsAVW/J03Dyw0zXkU+hqff5jMmcsOsh+Q6o9pLgGIRLrDDUutjfknaIdnPPvhyCIBH8j/41WD2ErwrAAGUVBn0qhyyrB8keCzDuY/I/9uNEn/UdxLyR6MDbPQAef4knZ/Egf+8snsL218Pk6Gh8r4iK90G/z0c6YyVbrgxquoscyPkfJW8ggAXyMnc/zkQSPYh5kJdpodxRct0RrzlYPg6oNpshU7Bwmtl6wtbWyLisJnR1bG6+iE7zg9y/gDnxrRbOfjqOUoLKYEKfAcr1EixNITXxhE+uI4LRxHf0vDrCiDOxtpPn97wd3n/ySpXd67FwS1zHJod3QXLuPIs4L3DouRPeRwEGkQHY8PVDmToUijoJ8rcGRSgF/wjrGHz088jOtLxfLomfVQWANJaywuvP/F335mKgLmxJ/gwFQeZ/bCKZwDyAI3oT6DqoPEJISq0WIX51H2l9X94P4jhUNMfJo1DkpTWsiynElk0DU9BTBWYd10WN/FQTFaAhqJvaUeuAAvEoM/k1zFkQMgUqxDy//NYab3kakBavT+RzzZfLf8HOhXies/o+27Z8lCsnyvPNXd0A5oWqcKPMFNDOmMelPXe+roFvpcd8UkPSTLlkJh1FnydS38ehHaQ= X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI1PR08MB5325.eurprd08.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(136003)(376002)(346002)(39860400002)(396003)(366004)(451199015)(83380400001)(38070700005)(33656002)(86362001)(38100700002)(122000001)(8936002)(52536014)(5660300002)(53546011)(64756008)(66446008)(66476007)(66556008)(66946007)(76116006)(8676002)(41300700001)(4326008)(2906002)(6506007)(7696005)(186003)(9686003)(26005)(6916009)(54906003)(316002)(478600001)(55016003)(71200400001)(84970400001);DIR:OUT;SFP:1101; Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1PR08MB5696 Original-Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM7EUR03FT065.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: cff3da49-0511-449f-31e0-08dab0206894 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ph+MLH8YqyeMxMDZvlXbcoOVhtQq24mfF5ofrhyRibEKccgU+Ifm7p9UsiBzi2aZ4Qgk4ap7YlgTAzry2nZFjckpCLHAIAAI2O4YZxQWBvZSUi8F0mCh6HmIyX3uWHqmY0b1Az2xZfGdEZ94tmuiyhrLlUswqM8dtZkpUXThSvTb9T6Rs5oxn9tEzy9zoGcvJQDpResEx692JAztYbNVB5HPH4eumNSVMpTW/w3OpXp8CV3KSDBdxojciNJO4bDEI7Mx6WlZ19uon8hWJVcfGJcuB3dq6geVQbFg6CE9F+v9K0bBzEUK2czeHAKxWaxZTtr7gfL/auu9jIvpCWzyTv8LtDmKL9t8nSy/UV/AY3Tf5wC391Qu3ccXw1iOw5/Htf9YmpANrHsDq5T5E5FQxpSo9h8XvGLHam4UwJ2+Mm9PDAWvKCkKgZTLA6NpYCV0AejW+hEmuK2Oe+X/9buFJm1l+kAmXuWpSk0nZvgFnuWnOJPFpzF9Lc42l82wyzj2kcqeECS4d0T5+ShFZzFSN//9/5TJ5kq/nj+UCrNLbvboDFGbsHT+CIDnaMVkY2fsYaqNLK3+svTyAuV9Ani5CHYOTI1j+kHVzClwv4QsmTpIkAwFAoZTI/2WmM50iK647MYFPM2Li8adIcB37m4DLDB735Vr0TgzqYnlPino3SeKSk2+CIQqYQyDe2Pcf7k4NK9UWGcaCodVrk83MdyA+/lMXdZkLVpnzUnHfot8NuFNPzy3+boL+Hn5fTKFZPMru3TnohVVWBr9CRKIygMOZleRpsO2uqz9pAEHU1pB7VvpeCk5N3WOj0OoPJFMF8nA X-Forefront-Antispam-Report: CIP:63.35.35.123;CTRY:IE;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:64aa7808-outbound-1.mta.getcheckrecipient.com;PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com;CAT:NONE;SFS:(13230022)(4636009)(346002)(39860400002)(376002)(136003)(396003)(451199015)(46966006)(40470700004)(36840700001)(336012)(47076005)(186003)(83380400001)(356005)(81166007)(86362001)(36860700001)(82740400003)(5660300002)(2906002)(41300700001)(8936002)(4326008)(6862004)(52536014)(82310400005)(40480700001)(55016003)(8676002)(40460700003)(107886003)(478600001)(9686003)(26005)(53546011)(6506007)(7696005)(316002)(70586007)(70206006)(54906003)(84970400001)(33656002);DIR:OUT;SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Oct 2022 09:17:40.5956 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 256a5a2f-59d5-4bee-9ff3-08dab02070f2 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d;Ip=[63.35.35.123];Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: AM7EUR03FT065.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB6087 X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,FORGED_SPF_HELO,GIT_PATCH_0,KAM_DMARC_NONE,KAM_LOTSOFHASH,KAM_SHORT,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE,TXREP,UNPARSEABLE_RELAY 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: > -----Original Message----- > From: Richard Biener > Sent: Monday, September 26, 2022 11:28 AM > To: Tamar Christina > Cc: gcc-patches@gcc.gnu.org; nd ; jeffreyalaw@gmail.com; > ebotcazou@adacore.com > Subject: Re: [PATCH]middle-end fix floating out of constants in condition= als >=20 > On Fri, 23 Sep 2022, Tamar Christina wrote: >=20 > > Hi All, > > > > The following testcase: > > > > int zoo1 (int a, int b, int c, int d) > > { > > return (a > b ? c : d) & 1; > > } > > > > gets de-optimized by the front-end since somewhere around GCC 4.x due > > to a fix that was added to fold_binary_op_with_conditional_arg. > > > > The folding is supposed to succeed only if we have folded at least one > > of the branches, however the check doesn't tests that all of the > > values are non-constant. So if one of the operators are a constant it > accepts the folding. > > > > This ends up folding > > > > return (a > b ? c : d) & 1; > > > > into > > > > return (a > b ? c & 1 : d & 1); > > > > and thus performing the AND twice. > > > > change changes it to reject the folding if one of the arguments are a > > constant and if the operations being performed are the same. > > > > Secondly it adds a new match.pd rule to now also fold the opposite > > direction, so it now also folds: > > > > return (a > b ? c & 1 : d & 1); > > > > into > > > > return (a > b ? c : d) & 1; > > > > Bootstrapped Regtested on aarch64-none-linux-gnu, x86_64-pc-linux-gnu > > and issues. > > > > Ok for master? > > > > Thanks, > > Tamar > > > > gcc/ChangeLog: > > > > * fold-const.cc (fold_binary_op_with_conditional_arg): Add > relaxation. > > * match.pd: Add ternary constant fold rule. > > * tree-cfg.cc (verify_gimple_assign_ternary): RHS1 of a COND_EXPR > isn't > > a value but an expression itself. > > > > gcc/testsuite/ChangeLog: > > > > * gcc.target/aarch64/if-compare_3.c: New test. > > > > --- inline copy of patch -- > > diff --git a/gcc/fold-const.cc b/gcc/fold-const.cc index > > > 4f4ec81c8d4b6937ade3141a14c695b67c874c35..0ee083f290d12104969f1b335d > c3 > > 3917c97b4808 100644 > > --- a/gcc/fold-const.cc > > +++ b/gcc/fold-const.cc > > @@ -7212,7 +7212,9 @@ fold_binary_op_with_conditional_arg (location_t > loc, > > } > > > > /* Check that we have simplified at least one of the branches. */ > > - if (!TREE_CONSTANT (arg) && !TREE_CONSTANT (lhs) && > !TREE_CONSTANT > > (rhs)) > > + if ((!TREE_CONSTANT (arg) && !TREE_CONSTANT (lhs) && > !TREE_CONSTANT (rhs)) > > + || (TREE_CONSTANT (arg) && TREE_CODE (lhs) =3D=3D TREE_CODE (rhs= ) > > + && !TREE_CONSTANT (lhs))) > > return NULL_TREE; >=20 > I think the better fix would be to only consider TREE_CONSTANT (arg) if i= t > wasn't constant initially. Because clearly "simplify" intends to be "con= stant" > here. In fact I wonder why we test !TREE_CONSTANT (arg) at all, we don't > simplify 'arg' ... The function allows this because even when !TREE_CONSTANT (arg) the true_value or false_value can instead be constant. Yes it's of limited use unless true_value and false_value are 0 or 1. >=20 > Eric added this test (previosuly we'd just always done the folding), but = I think > not enough? >=20 > > > > return fold_build3_loc (loc, cond_code, type, test, lhs, rhs); diff > > --git a/gcc/match.pd b/gcc/match.pd index > > > b225d36dc758f1581502c8d03761544bfd499c01..b61ed70e69b881a49177f10f20 > c1 > > f92712bb8665 100644 > > --- a/gcc/match.pd > > +++ b/gcc/match.pd > > @@ -4318,6 +4318,16 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) > > (op @3 (vec_cond:s @0 @1 @2)) > > (vec_cond @0 (op! @3 @1) (op! @3 @2)))) > > > > +/* Float out binary operations from branches if they can't be folded. > > + Fold (a ? (b op c) : (d op c)) --> (op (a ? b : d) c). */ (for op > > +(plus mult min max bit_and bit_ior bit_xor minus lshift rshift rdiv > > + trunc_div ceil_div floor_div round_div trunc_mod ceil_mod > floor_mod > > + round_mod) > > + (simplify > > + (cond @0 (op @1 @2) (op @3 @2)) > > + (if (!FLOAT_TYPE_P (type) || !(HONOR_NANS (@1) && > flag_trapping_math)) > > + (op (cond @0 @1 @3) @2)))) >=20 > Ick. Adding a reverse tranform is going to be prone to recursing :/ >=20 > Why do you need to care about NANs or FP exceptions? Because the function in fold-const.cc has a check in the start: /* Do not move possibly trapping operations into the conditional as this pessimizes code and causes gimplification issues when applied late. *= / And so I stayed conservative and just didn't want to touch them. > How do you know if they can't be folded? Because otherwise they would have been reduced in fold-const.cc. The new conditions long with the rest in fold-const.cc require: 1. at least one of the operands to be constant 2. if the operands are equal, at least one of them must have been reduced t= o a constant. These two means that (cond @0 (op @1 @2) (op @3 @2)) can't match if it's so= mething that fold-const.cc can handle. > Since match.pd cannot handle arbitrary operations it > isn't a good fit for match.pd patterns, instead this would be a forwprop > pattern or, in case you want to catch GENERIC, a fold-const.cc one? I'll try to move it to fold-const.cc then. Tamar >=20 > Thanks and sorry for the late reply - hope Jeffs approval didn't make you > apply it yet. >=20 > Richard. >=20 > > + > > #if GIMPLE > > (match (nop_atomic_bit_test_and_p @0 @1 @4) > > (bit_and (convert?@4 (ATOMIC_FETCH_OR_XOR_N @2 INTEGER_CST@0 > @3)) > > diff --git a/gcc/testsuite/gcc.target/aarch64/if-compare_3.c > > b/gcc/testsuite/gcc.target/aarch64/if-compare_3.c > > new file mode 100644 > > index > > > 0000000000000000000000000000000000000000..1d97da5c0d6454175881c2199 > 274 > > 71a567a6f0c7 > > --- /dev/null > > +++ b/gcc/testsuite/gcc.target/aarch64/if-compare_3.c > > @@ -0,0 +1,27 @@ > > +/* { dg-do compile } */ > > +/* { dg-additional-options "-O3 -std=3Dc99" } */ > > +/* { dg-final { check-function-bodies "**" "" "" { target { le } } } > > +} */ > > + > > +/* > > +**zoo: > > +** cmp w0, w1 > > +** csel w0, w3, w2, le > > +** ret > > +*/ > > +int zoo (int a, int b, int c, int d) > > +{ > > + return a > b ? c : d; > > +} > > + > > +/* > > +**zoo1: > > +** cmp w0, w1 > > +** csel w0, w3, w2, le > > +** and w0, w0, 1 > > +** ret > > +*/ > > +int zoo1 (int a, int b, int c, int d) { > > + return (a > b ? c : d) & 1; > > +} > > + > > diff --git a/gcc/tree-cfg.cc b/gcc/tree-cfg.cc index > > > b19710392940cf469de52d006603ae1e3deb6b76..aaf1b29da5c598add25dad2c > 38b8 > > 28eaa89c49ce 100644 > > --- a/gcc/tree-cfg.cc > > +++ b/gcc/tree-cfg.cc > > @@ -4244,7 +4244,9 @@ verify_gimple_assign_ternary (gassign *stmt) > > return true; > > } > > > > - if (!is_gimple_val (rhs1) > > + /* In a COND_EXPR the rhs1 is the condition and thus isn't > > + a gimple value by definition. */ if ((!is_gimple_val (rhs1) && > > + rhs_code !=3D COND_EXPR) > > || !is_gimple_val (rhs2) > > || !is_gimple_val (rhs3)) > > { > > > > > > > > > > >=20 > -- > Richard Biener > SUSE Software Solutions Germany GmbH, Frankenstrasse 146, 90461 > Nuernberg, Germany; GF: Ivo Totev, Andrew Myers, Andrew McDonald, > Boudien Moerman; HRB 36809 (AG Nuernberg)