{"id":1839980,"url":"http://patchwork.ozlabs.org/api/patches/1839980/?format=json","web_url":"http://patchwork.ozlabs.org/project/gcc/patch/patch-17719-tamar@arm.com/","project":{"id":17,"url":"http://patchwork.ozlabs.org/api/projects/17/?format=json","name":"GNU Compiler Collection","link_name":"gcc","list_id":"gcc-patches.gcc.gnu.org","list_email":"gcc-patches@gcc.gnu.org","web_url":null,"scm_url":null,"webscm_url":null,"list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<patch-17719-tamar@arm.com>","list_archive_url":null,"date":"2023-09-27T00:49:50","name":"middle-end Fold vec_cond into conditional ternary or binary operation when sharing operand [PR109154]","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"6ef4069f5eab5d9ac5f92f61633f16d6aac02a34","submitter":{"id":69689,"url":"http://patchwork.ozlabs.org/api/people/69689/?format=json","name":"Tamar Christina","email":"Tamar.Christina@arm.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/gcc/patch/patch-17719-tamar@arm.com/mbox/","series":[{"id":375018,"url":"http://patchwork.ozlabs.org/api/series/375018/?format=json","web_url":"http://patchwork.ozlabs.org/project/gcc/list/?series=375018","date":"2023-09-27T00:49:50","name":"middle-end Fold vec_cond into conditional ternary or binary operation when sharing operand [PR109154]","version":1,"mbox":"http://patchwork.ozlabs.org/series/375018/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/1839980/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/1839980/checks/","tags":{},"related":[],"headers":{"Return-Path":"<gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org>","X-Original-To":["incoming@patchwork.ozlabs.org","gcc-patches@gcc.gnu.org"],"Delivered-To":["patchwork-incoming@legolas.ozlabs.org","gcc-patches@gcc.gnu.org"],"Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (1024-bit key;\n unprotected) header.d=armh.onmicrosoft.com header.i=@armh.onmicrosoft.com\n header.a=rsa-sha256 header.s=selector2-armh-onmicrosoft-com\n header.b=yHyUVwoF;\n\tdkim=pass (1024-bit key) header.d=armh.onmicrosoft.com\n header.i=@armh.onmicrosoft.com header.a=rsa-sha256\n header.s=selector2-armh-onmicrosoft-com header.b=yHyUVwoF;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org\n (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org;\n envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org;\n receiver=patchwork.ozlabs.org)","sourceware.org;\n dmarc=pass (p=none dis=none) header.from=arm.com","sourceware.org; spf=pass smtp.mailfrom=arm.com"],"Received":["from server2.sourceware.org (server2.sourceware.org\n [IPv6:2620:52:3:1:0:246e:9693:128c])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4RwJ1d6QXNz1ypJ\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 27 Sep 2023 10:50:25 +1000 (AEST)","from server2.sourceware.org (localhost [IPv6:::1])\n\tby sourceware.org (Postfix) with ESMTP id 5E260385DC18\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 27 Sep 2023 00:50:23 +0000 (GMT)","from EUR02-VI1-obe.outbound.protection.outlook.com\n (mail-vi1eur02on2082.outbound.protection.outlook.com [40.107.241.82])\n by sourceware.org (Postfix) with ESMTPS id CAE6A3858017\n for <gcc-patches@gcc.gnu.org>; Wed, 27 Sep 2023 00:50:08 +0000 (GMT)","from AM0PR06CA0125.eurprd06.prod.outlook.com (2603:10a6:208:ab::30)\n by PAVPR08MB9138.eurprd08.prod.outlook.com (2603:10a6:102:30d::10)\n with Microsoft SMTP Server (version=TLS1_2,\n cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6813.28; Wed, 27 Sep\n 2023 00:50:03 +0000","from AM7EUR03FT021.eop-EUR03.prod.protection.outlook.com\n (2603:10a6:208:ab:cafe::5d) by AM0PR06CA0125.outlook.office365.com\n (2603:10a6:208:ab::30) with Microsoft SMTP Server (version=TLS1_2,\n cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.35 via Frontend\n Transport; Wed, 27 Sep 2023 00:50:03 +0000","from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by\n AM7EUR03FT021.mail.protection.outlook.com (100.127.140.243) with\n Microsoft\n SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id\n 15.20.6838.21 via Frontend Transport; Wed, 27 Sep 2023 00:50:03 +0000","(\"Tessian outbound b5a0f4347031:v175\");\n Wed, 27 Sep 2023 00:50:03 +0000","from c9cde379f05d.1\n by 64aa7808-outbound-1.mta.getcheckrecipient.com id\n 86E5F6A3-9872-4095-9820-2DE329B3BCCA.1;\n Wed, 27 Sep 2023 00:49:55 +0000","from EUR04-HE1-obe.outbound.protection.outlook.com\n by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id\n c9cde379f05d.1\n (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384);\n Wed, 27 Sep 2023 00:49:55 +0000","from VI1PR08MB5325.eurprd08.prod.outlook.com (2603:10a6:803:13e::17)\n by AS8PR08MB9743.eurprd08.prod.outlook.com (2603:10a6:20b:615::18)\n with Microsoft SMTP Server (version=TLS1_2,\n cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6813.28; Wed, 27 Sep\n 2023 00:49:53 +0000","from VI1PR08MB5325.eurprd08.prod.outlook.com\n ([fe80::662f:8e26:1bf8:aaa1]) by VI1PR08MB5325.eurprd08.prod.outlook.com\n ([fe80::662f:8e26:1bf8:aaa1%7]) with mapi id 15.20.6813.027; Wed, 27 Sep 2023\n 00:49:53 +0000"],"DMARC-Filter":"OpenDMARC Filter v1.4.2 sourceware.org CAE6A3858017","DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com;\n s=selector2-armh-onmicrosoft-com;\n h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck;\n bh=/0NXhtr2S9GJsJSVN3lNvmloNHCjij5O0/VxUl6npng=;\n b=yHyUVwoFqWsaDmPp42j2grlmcG0xBYF3ayXD3VH4XqeK2/NrxgZQ+XdgrLKa4gpgizDw57KDAOm2IqfdzQEnS6wOu8Okd3u2XafpKpZp6xV7t8sDRDnS+r1nc9PiqcDDSJo5xI0xB6xIgV6n16MqnQOWxfZtB8WDTOVOPOtieBk=","v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com;\n s=selector2-armh-onmicrosoft-com;\n h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck;\n bh=/0NXhtr2S9GJsJSVN3lNvmloNHCjij5O0/VxUl6npng=;\n b=yHyUVwoFqWsaDmPp42j2grlmcG0xBYF3ayXD3VH4XqeK2/NrxgZQ+XdgrLKa4gpgizDw57KDAOm2IqfdzQEnS6wOu8Okd3u2XafpKpZp6xV7t8sDRDnS+r1nc9PiqcDDSJo5xI0xB6xIgV6n16MqnQOWxfZtB8WDTOVOPOtieBk="],"X-MS-Exchange-Authentication-Results":"spf=pass (sender IP is 63.35.35.123)\n smtp.mailfrom=arm.com; dkim=pass (signature was verified)\n header.d=armh.onmicrosoft.com;dmarc=pass action=none header.from=arm.com;","Received-SPF":"Pass (protection.outlook.com: domain of arm.com designates\n 63.35.35.123 as permitted sender) receiver=protection.outlook.com;\n client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com;\n pr=C","X-CheckRecipientChecked":"true","X-CR-MTA-CID":"fd33413ae5b10f01","X-CR-MTA-TID":"64aa7808","ARC-Seal":"i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none;\n b=izTo1kUwPjOw2B7rOjNA2NcO9JO1Gs1/CkDQ3kNqA3Q8c1qbtaQBVBn7XRd/Zg46UUTB6Do+dTKy4GkdrBAGd/fP/G6Sr99a7dxMk2pZqzE62Hdb3XwdvhJsGQU4DpIGItiYEIda3HliMv0lfA1sAiRAefdu5jrBYkguGBr++dSBmIcXh9A7jdMJKHgBeBg7wvtQhx59hUx4l/F3gjRJ2E2MYCLpIvyr2yDSWkroNuJfLtdmHK9zCoUF0OXbMkuKogxGxaKx+ROfYhdJ8kdr8f8/zwWbVIU82gBKoAapm3Ot4Tka0xZPiEYM3XhPJlRr5HZXchh/w1TbAtjIX6wgsQ==","ARC-Message-Signature":"i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com;\n s=arcselector9901;\n 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;\n bh=/0NXhtr2S9GJsJSVN3lNvmloNHCjij5O0/VxUl6npng=;\n b=Ky3UnoLPD3Kravl2lcrXVy1gOSeYR9ODn0g6bJ3mNK0SFbGrLl9qpc4aXeDf/b0kLvJw/Z+EIi1o+DgVvj5wtWFxyr4mcVNQlIZeKkryk0uPOvJrlGH+wKeAypooGWnosd146pKK8xgpxx5TsGREmo86h5fMkciekmsmgDfsUtVRyyspwKk63BYfbdwtgApyuQKBHcYYs9yO1LiYR1cTpesdkqXdgrZb7INADHiexnheVju5x8w/riumdtoUWdD4xFRc6Yxhv3nZ1C9Nvw4LKrpoT9iAcgpEtgAKpjoJOxcx8VeXWJC1Ak5FyvVRClO+s1Giea4QC9svJYz7vTA2bg==","ARC-Authentication-Results":"i=1; mx.microsoft.com 1; spf=pass\n smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass\n header.d=arm.com; arc=none","Authentication-Results-Original":"dkim=none (message not signed)\n header.d=none;dmarc=none action=none header.from=arm.com;","Date":"Wed, 27 Sep 2023 01:49:50 +0100","From":"Tamar Christina <tamar.christina@arm.com>","To":"gcc-patches@gcc.gnu.org","Cc":"nd@arm.com, rguenther@suse.de, jlaw@ventanamicro.com","Subject":"[PATCH]middle-end Fold vec_cond into conditional ternary or binary\n operation when sharing operand [PR109154]","Message-ID":"<patch-17719-tamar@arm.com>","Content-Type":"multipart/mixed; boundary=\"AV6cmv8nNspGJ5EP\"","Content-Disposition":"inline","X-ClientProxiedBy":"LO3P123CA0013.GBRP123.PROD.OUTLOOK.COM\n (2603:10a6:600:ba::18) To VI1PR08MB5325.eurprd08.prod.outlook.com\n (2603:10a6:803:13e::17)","MIME-Version":"1.0","X-MS-TrafficTypeDiagnostic":"\n VI1PR08MB5325:EE_|AS8PR08MB9743:EE_|AM7EUR03FT021:EE_|PAVPR08MB9138:EE_","X-MS-Office365-Filtering-Correlation-Id":"32aabe8e-3228-42ae-566f-08dbbef3afbe","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":"\n JXAud7iGN+/84+Vw635csc/Abcb4LtDbLmRQCyBoM/cra7dAyjWcZBo59ywkWZ0cOvCEKXZbyAUA95HnW33/8/wmg8R3rXuTkol45oOykKab7AhvX4/Ab5EsqwZPWs/mkPcLhfrCQE4QsvnHoilWpLLRKD2QaHeOHz8jbaCDVprOOKvJYG6QZqvbIKsOYSMMqCcmu0XtpFks84zMTrkXtfjWuKC2N4plqi9vtnGCF1BiGbFNXYM28oqE1tmEfVLf4rIrLI3y/RnrsTKExMeAoIvt8WA7VdNUa2F0hqF1arDC1skobkGDMm+b6KEw2p2hVtL/avN4ZUJwX8bz9+R03K3ZC3g0s5iMsliP2DbBINVcVGWUz7E+jaZR2NxDJHPBOpYOF/I4e+xI0y5JnmbxLtvLlUbnjsuLlSjGC9WLQ5xq/YtUL7OKwsEhHNH86u7UbDhPlQrI5Ti04THL2qQk1JUCI+yBS4T0DXrFtSZu4fqm5Uz0SkbWHAjxx5MrNIV4LoCi82GYPJl0i05np5e4N+frC8jAjOHfVKjzSuw0uNXAsTNLSM0zcLTjIYzgykVXrycXACNQywIPftioq1DQHcDMRfcVBlsuRISkCBTK2S9Wd+HEWbANEaDxIxbPojqa","X-Forefront-Antispam-Report-Untrusted":"CIP:255.255.255.255; CTRY:; LANG:en;\n SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:VI1PR08MB5325.eurprd08.prod.outlook.com;\n PTR:; CAT:NONE;\n SFS:(13230031)(366004)(136003)(346002)(396003)(376002)(39860400002)(230922051799003)(1800799009)(186009)(451199024)(26005)(478600001)(86362001)(2616005)(36756003)(83380400001)(6486002)(6506007)(5660300002)(44144004)(38100700002)(33964004)(6512007)(8676002)(8936002)(2906002)(4326008)(316002)(41300700001)(84970400001)(66946007)(66476007)(66556008)(6916009)(235185007)(44832011)(4216001)(2700100001);\n DIR:OUT; SFP:1101;","X-MS-Exchange-Transport-CrossTenantHeadersStamped":["AS8PR08MB9743","PAVPR08MB9138"],"Original-Authentication-Results":"dkim=none (message not signed)\n header.d=none;dmarc=none action=none header.from=arm.com;","X-EOPAttributedMessage":"0","X-MS-Exchange-Transport-CrossTenantHeadersStripped":"\n AM7EUR03FT021.eop-EUR03.prod.protection.outlook.com","X-MS-PublicTrafficType":"Email","X-MS-Office365-Filtering-Correlation-Id-Prvs":"\n e8a2476f-ba98-4350-0df1-08dbbef3a93d","X-Microsoft-Antispam":"BCL:0;","X-Microsoft-Antispam-Message-Info":"\n cYv2ZWAULbBbK7qCCcWl742pZx0J60lj2DAi0d+HWEXNG+YtQTFd+L8Q3d8rGjmgJQfccu6JJrQynsrsqMKGiYxXFVaUg+K45YKXDcWBuyFU3+u65FZ5R0rq+bMcfhfp3l8XdHACWd8bUUKB8H5JFGIPwQrdb0fceXVJKpKAmotfrRTEYgi6JaSMff8s0rH/2DGFhcV0dlkXIvAc4tk7+ycBTiPRouvm3G5VnChKg6ZS40DdaBADDem15Wx152yqKGRfV65bQVN+oeUjf4ToJglVK/tNc4q6Jk4GUlk3H9UdIY0dse4EPZ0L8DYcvumFwqDmE/ZOe+BH4QJkMmEAj9VgkCMa2PPMcDzyH84mwZMrUa+tY87caOkrgvkTbxAqJoterTLF3eyPV6HEzAppm8SQSaeD4WTHYISl22QJjdfwOD5rE0ZUg1hhURbSP9o0CwlvjfBGLSxdnRD4wZQc3kSm19V80Cc5MeuXNqzzy6r9zehZellTS42ag7mVLc0z8vBR8WThM0oaWMxSmbt6Wp6+TeA8JAdr6iOBQITGRDthsJr0mqd/qe+PoJVFaYsFfev/f+nfi8DhcZxAv6TR1wNs2osLTeklKFli9F5jvDuOlB5jQKQis9INjvU23qIUhsYmB4YVaPEiAgTFSuZu7T3qsNItSa4fF1LqX0mifi3m9abU63OE5qo7Q3ZQeKp4XfV8HWa12Xf7zZeLMUxOKMbGrPGa6VEg0ByuFo4Y8BXc4gPe4K+nFZ9PHRdvAOfdvDG1HJeU0UwBvSHRcIeKl57e0Y5ZGRFMv/a/T+1AdW5bLt8VRrkSfWjI2s0lGus/7qGk0YBJ9Z533F585T241A==","X-Forefront-Antispam-Report":"CIP:63.35.35.123; CTRY:IE; LANG:en; SCL:1; SRV:;\n IPV:CAL; SFV:NSPM; H:64aa7808-outbound-1.mta.getcheckrecipient.com;\n PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com; CAT:NONE;\n SFS:(13230031)(4636009)(346002)(39860400002)(376002)(136003)(396003)(230922051799003)(1800799009)(82310400011)(186009)(451199024)(46966006)(36840700001)(40470700004)(40480700001)(6506007)(82740400003)(356005)(2906002)(40460700003)(47076005)(6486002)(83380400001)(235185007)(81166007)(36860700001)(33964004)(70206006)(44144004)(70586007)(6512007)(5660300002)(26005)(8936002)(4326008)(6916009)(336012)(107886003)(478600001)(44832011)(316002)(8676002)(41300700001)(2616005)(86362001)(36756003)(84970400001)(4216001)(2700100001);\n DIR:OUT; SFP:1101;","X-OriginatorOrg":"arm.com","X-MS-Exchange-CrossTenant-OriginalArrivalTime":"27 Sep 2023 00:50:03.7093 (UTC)","X-MS-Exchange-CrossTenant-Network-Message-Id":"\n 32aabe8e-3228-42ae-566f-08dbbef3afbe","X-MS-Exchange-CrossTenant-Id":"f34e5979-57d9-4aaa-ad4d-b122a662184d","X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp":"\n TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d; Ip=[63.35.35.123];\n Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com]","X-MS-Exchange-CrossTenant-AuthSource":"\n AM7EUR03FT021.eop-EUR03.prod.protection.outlook.com","X-MS-Exchange-CrossTenant-AuthAs":"Anonymous","X-MS-Exchange-CrossTenant-FromEntityHeader":"HybridOnPrem","X-Spam-Status":"No, score=-12.0 required=5.0 tests=BAYES_00, DKIM_SIGNED,\n DKIM_VALID, FORGED_SPF_HELO, GIT_PATCH_0, KAM_DMARC_NONE, KAM_LOTSOFHASH,\n KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_NONE,\n TXREP, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.6","X-Spam-Checker-Version":"SpamAssassin 3.4.6 (2021-04-09) on\n server2.sourceware.org","X-BeenThere":"gcc-patches@gcc.gnu.org","X-Mailman-Version":"2.1.30","Precedence":"list","List-Id":"Gcc-patches mailing list <gcc-patches.gcc.gnu.org>","List-Unsubscribe":"<https://gcc.gnu.org/mailman/options/gcc-patches>,\n <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe>","List-Archive":"<https://gcc.gnu.org/pipermail/gcc-patches/>","List-Post":"<mailto:gcc-patches@gcc.gnu.org>","List-Help":"<mailto:gcc-patches-request@gcc.gnu.org?subject=help>","List-Subscribe":"<https://gcc.gnu.org/mailman/listinfo/gcc-patches>,\n <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe>","Errors-To":"gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org"},"content":"Hi All,\n\nWhen we have a vector conditional on a masked target which is doing a selection\non the result of a conditional operation where one of the operands of the\nconditional operation is the other operand of the select, then we can fold the\nvector conditional into the operation.\n\nConcretely this transforms\n\n  c = mask1 ? (masked_op mask2 a b) : b\n\ninto\n\n  c = masked_op (mask1 & mask2) a b\n\nThe mask is then propagated upwards by the compiler.  In the SVE case we don't\nend up needing a mask AND here since `mask2` will end up in the instruction\ncreating `mask` which gives us a natural &.\n\nSuch transformations are more common now in GCC 13+ as PRE has not started\nunsharing of common code in case it can make one branch fully independent.\n\ne.g. in this case `b` becomes a loop invariant value after PRE.\n\nThis transformation removes the extra select for masked architectures but\ndoesn't fix the general case.\n\nBootstrapped Regtested on aarch64-none-linux-gnu and no issues.\n\nOk for master?\n\nThanks,\nTamar\n\ngcc/ChangeLog:\n\n\tPR tree-optimization/109154\n\t* match.pd: Add new cond_op rule.\n\ngcc/testsuite/ChangeLog:\n\n\tPR tree-optimization/109154\n\t* gcc.target/aarch64/sve/pre_cond_share_1.c: New test.\n\n--- inline copy of patch -- \ndiff --git a/gcc/match.pd b/gcc/match.pd\nindex 8ebde06dcd4b26d694826cffad0fb17e1136600a..20b9ea211385d9cc3876a5002f771267533e8868 100644\n\n\n\n\n--\ndiff --git a/gcc/match.pd b/gcc/match.pd\nindex 8ebde06dcd4b26d694826cffad0fb17e1136600a..20b9ea211385d9cc3876a5002f771267533e8868 100644\n--- a/gcc/match.pd\n+++ b/gcc/match.pd\n@@ -8827,6 +8827,30 @@ and,\n   (IFN_COND_ADD @0 @1 (vec_cond @2 @3 integer_zerop) @1)\n    (IFN_COND_ADD (bit_and @0 @2) @1 @3 @1))\n \n+/* Detect simplification for vector condition folding where\n+\n+  c = mask1 ? (masked_op mask2 a b) : b\n+\n+  into\n+\n+  c = masked_op (mask1 & mask2) a b\n+\n+  where the operation can be partially applied to one operand. */\n+\n+(for cond_op (COND_BINARY)\n+ (simplify\n+  (vec_cond @0\n+   (cond_op:s @1 @2 @3 @4) @3)\n+  (cond_op (BIT_AND_EXPR @1 @0) @2 @3 @4)))\n+\n+/* And same for ternary expressions.  */\n+\n+(for cond_op (COND_TERNARY)\n+ (simplify\n+  (vec_cond @0\n+   (cond_op:s @1 @2 @3 @4 @5) @4)\n+  (cond_op (BIT_AND_EXPR @1 @0) @2 @3 @4 @5)))\n+\n /* For pointers @0 and @2 and nonnegative constant offset @1, look for\n    expressions like:\n \ndiff --git a/gcc/testsuite/gcc.target/aarch64/sve/pre_cond_share_1.c b/gcc/testsuite/gcc.target/aarch64/sve/pre_cond_share_1.c\nnew file mode 100644\nindex 0000000000000000000000000000000000000000..b51d0f298ea1fcf556365fe4afc875ebcd67584b\n--- /dev/null\n+++ b/gcc/testsuite/gcc.target/aarch64/sve/pre_cond_share_1.c\n@@ -0,0 +1,132 @@\n+/* { dg-do compile } */\n+/* { dg-options \"-Ofast -fdump-tree-optimized\" } */\n+\n+#include <stdint.h>\n+#include <stddef.h>\n+#include <math.h>\n+#include <float.h>\n+\n+typedef struct __attribute__((__packed__)) _Atom {\n+    float x, y, z;\n+    int32_t type;\n+} Atom;\n+\n+typedef struct __attribute__((__packed__)) _FFParams {\n+    int32_t hbtype;\n+    float radius;\n+    float hphb;\n+    float elsc;\n+} FFParams;\n+\n+#ifndef PPWI\n+#define PPWI (64)\n+#endif\n+\n+#ifndef ITERS\n+#define ITERS 8\n+#endif\n+\n+#define DIFF_TOLERANCE_PCT 0.025f\n+\n+#define POSES_SIZE 393216\n+#define PROTEIN_SIZE 938\n+#define LIGAND_SIZE 26\n+#define FORCEFIELD_SIZE 34\n+\n+#define ZERO 0.0f\n+#define QUARTER 0.25f\n+#define HALF 0.5f\n+#define ONE 1.0f\n+#define TWO 2.0f\n+#define FOUR 4.0f\n+#define CNSTNT 45.0f\n+\n+// Energy evaluation parameters\n+#define HBTYPE_F 70\n+#define HBTYPE_E 69\n+#define HARDNESS 38.0f\n+#define NPNPDIST 5.5f\n+#define NPPDIST 1.0f\n+\n+void\n+fasten_main(size_t group, size_t ntypes, size_t nposes, size_t natlig, size_t natpro,        //\n+            const Atom *protein, const Atom *ligand,                                         //\n+            const float *transforms_0, const float *transforms_1, const float *transforms_2, //\n+            const float *transforms_3, const float *transforms_4, const float *transforms_5, //\n+            const FFParams *forcefield, float *energies                                      //\n+) {\n+\n+    float etot[PPWI];\n+    float lpos_x[PPWI];\n+\n+    for (int l = 0; l < PPWI; l++) {\n+        etot[l] = 0.f;\n+        lpos_x[l] = 0.f;\n+    }\n+\n+    // Loop over ligand atoms\n+    for (int il = 0; il < natlig; il++) {\n+        // Load ligand atom data\n+        const Atom l_atom = ligand[il];\n+        const FFParams l_params = forcefield[l_atom.type];\n+        const int lhphb_ltz = l_params.hphb < 0.f;\n+        const int lhphb_gtz = l_params.hphb > 0.f;\n+\n+        // Transform ligand atom\n+\n+        // Loop over protein atoms\n+        for (int ip = 0; ip < natpro; ip++) {\n+            // Load protein atom data\n+            const Atom p_atom = protein[ip];\n+            const FFParams p_params = forcefield[p_atom.type];\n+\n+            const float radij = p_params.radius + l_params.radius;\n+            const float r_radij = ONE / radij;\n+\n+            const float elcdst = (p_params.hbtype == HBTYPE_F && l_params.hbtype == HBTYPE_F) ? FOUR\n+                                                                                              : TWO;\n+            const float elcdst1 = (p_params.hbtype == HBTYPE_F && l_params.hbtype == HBTYPE_F)\n+                                  ? QUARTER : HALF;\n+            const int type_E = ((p_params.hbtype == HBTYPE_E || l_params.hbtype == HBTYPE_E));\n+\n+            const int phphb_ltz = p_params.hphb < 0.f;\n+            const int phphb_gtz = p_params.hphb > 0.f;\n+            const int phphb_nz = p_params.hphb != 0.f;\n+            const float p_hphb = p_params.hphb * (phphb_ltz && lhphb_gtz ? -ONE : ONE);\n+            const float l_hphb = l_params.hphb * (phphb_gtz && lhphb_ltz ? -ONE : ONE);\n+            const float distdslv = (phphb_ltz ? (lhphb_ltz ? NPNPDIST : NPPDIST) : (lhphb_ltz\n+                                                                                    ? NPPDIST\n+                                                                                    : -FLT_MAX));\n+            const float r_distdslv = ONE / distdslv;\n+\n+            const float chrg_init = l_params.elsc * p_params.elsc;\n+            const float dslv_init = p_hphb + l_hphb;\n+\n+            for (int l = 0; l < PPWI; l++) {\n+                // Calculate distance between atoms\n+                const float x = lpos_x[l] - p_atom.x;\n+                const float distij = (x * x);\n+\n+                // Calculate the sum of the sphere radii\n+                const float distbb = distij - radij;\n+\n+                const int zone1 = (distbb < ZERO);\n+\n+                // Calculate formal and dipole charge interactions\n+                float chrg_e = chrg_init * ((zone1 ? ONE : (ONE - distbb * elcdst1)) *\n+                                            (distbb < elcdst ? ONE : ZERO));\n+                float neg_chrg_e = -fabsf(chrg_e);\n+                chrg_e = type_E ? neg_chrg_e : chrg_e;\n+                etot[l] += chrg_e * CNSTNT;\n+            }\n+        }\n+    }\n+\n+    // Write result\n+    for (int l = 0; l < PPWI; l++) {\n+        energies[group * PPWI + l] = etot[l] * HALF;\n+    }\n+}\n+\n+/* { dg-final { scan-tree-dump-times {\\.COND_MUL} 1 \"optimized\" } } */\n+/* { dg-final { scan-tree-dump-times {\\.VCOND} 1 \"optimized\" } } */","diff":"--- a/gcc/match.pd\n+++ b/gcc/match.pd\n@@ -8827,6 +8827,30 @@ and,\n   (IFN_COND_ADD @0 @1 (vec_cond @2 @3 integer_zerop) @1)\n    (IFN_COND_ADD (bit_and @0 @2) @1 @3 @1))\n \n+/* Detect simplification for vector condition folding where\n+\n+  c = mask1 ? (masked_op mask2 a b) : b\n+\n+  into\n+\n+  c = masked_op (mask1 & mask2) a b\n+\n+  where the operation can be partially applied to one operand. */\n+\n+(for cond_op (COND_BINARY)\n+ (simplify\n+  (vec_cond @0\n+   (cond_op:s @1 @2 @3 @4) @3)\n+  (cond_op (BIT_AND_EXPR @1 @0) @2 @3 @4)))\n+\n+/* And same for ternary expressions.  */\n+\n+(for cond_op (COND_TERNARY)\n+ (simplify\n+  (vec_cond @0\n+   (cond_op:s @1 @2 @3 @4 @5) @4)\n+  (cond_op (BIT_AND_EXPR @1 @0) @2 @3 @4 @5)))\n+\n /* For pointers @0 and @2 and nonnegative constant offset @1, look for\n    expressions like:\n \ndiff --git a/gcc/testsuite/gcc.target/aarch64/sve/pre_cond_share_1.c b/gcc/testsuite/gcc.target/aarch64/sve/pre_cond_share_1.c\nnew file mode 100644\nindex 0000000000000000000000000000000000000000..b51d0f298ea1fcf556365fe4afc875ebcd67584b\n--- /dev/null\n+++ b/gcc/testsuite/gcc.target/aarch64/sve/pre_cond_share_1.c\n@@ -0,0 +1,132 @@\n+/* { dg-do compile } */\n+/* { dg-options \"-Ofast -fdump-tree-optimized\" } */\n+\n+#include <stdint.h>\n+#include <stddef.h>\n+#include <math.h>\n+#include <float.h>\n+\n+typedef struct __attribute__((__packed__)) _Atom {\n+    float x, y, z;\n+    int32_t type;\n+} Atom;\n+\n+typedef struct __attribute__((__packed__)) _FFParams {\n+    int32_t hbtype;\n+    float radius;\n+    float hphb;\n+    float elsc;\n+} FFParams;\n+\n+#ifndef PPWI\n+#define PPWI (64)\n+#endif\n+\n+#ifndef ITERS\n+#define ITERS 8\n+#endif\n+\n+#define DIFF_TOLERANCE_PCT 0.025f\n+\n+#define POSES_SIZE 393216\n+#define PROTEIN_SIZE 938\n+#define LIGAND_SIZE 26\n+#define FORCEFIELD_SIZE 34\n+\n+#define ZERO 0.0f\n+#define QUARTER 0.25f\n+#define HALF 0.5f\n+#define ONE 1.0f\n+#define TWO 2.0f\n+#define FOUR 4.0f\n+#define CNSTNT 45.0f\n+\n+// Energy evaluation parameters\n+#define HBTYPE_F 70\n+#define HBTYPE_E 69\n+#define HARDNESS 38.0f\n+#define NPNPDIST 5.5f\n+#define NPPDIST 1.0f\n+\n+void\n+fasten_main(size_t group, size_t ntypes, size_t nposes, size_t natlig, size_t natpro,        //\n+            const Atom *protein, const Atom *ligand,                                         //\n+            const float *transforms_0, const float *transforms_1, const float *transforms_2, //\n+            const float *transforms_3, const float *transforms_4, const float *transforms_5, //\n+            const FFParams *forcefield, float *energies                                      //\n+) {\n+\n+    float etot[PPWI];\n+    float lpos_x[PPWI];\n+\n+    for (int l = 0; l < PPWI; l++) {\n+        etot[l] = 0.f;\n+        lpos_x[l] = 0.f;\n+    }\n+\n+    // Loop over ligand atoms\n+    for (int il = 0; il < natlig; il++) {\n+        // Load ligand atom data\n+        const Atom l_atom = ligand[il];\n+        const FFParams l_params = forcefield[l_atom.type];\n+        const int lhphb_ltz = l_params.hphb < 0.f;\n+        const int lhphb_gtz = l_params.hphb > 0.f;\n+\n+        // Transform ligand atom\n+\n+        // Loop over protein atoms\n+        for (int ip = 0; ip < natpro; ip++) {\n+            // Load protein atom data\n+            const Atom p_atom = protein[ip];\n+            const FFParams p_params = forcefield[p_atom.type];\n+\n+            const float radij = p_params.radius + l_params.radius;\n+            const float r_radij = ONE / radij;\n+\n+            const float elcdst = (p_params.hbtype == HBTYPE_F && l_params.hbtype == HBTYPE_F) ? FOUR\n+                                                                                              : TWO;\n+            const float elcdst1 = (p_params.hbtype == HBTYPE_F && l_params.hbtype == HBTYPE_F)\n+                                  ? QUARTER : HALF;\n+            const int type_E = ((p_params.hbtype == HBTYPE_E || l_params.hbtype == HBTYPE_E));\n+\n+            const int phphb_ltz = p_params.hphb < 0.f;\n+            const int phphb_gtz = p_params.hphb > 0.f;\n+            const int phphb_nz = p_params.hphb != 0.f;\n+            const float p_hphb = p_params.hphb * (phphb_ltz && lhphb_gtz ? -ONE : ONE);\n+            const float l_hphb = l_params.hphb * (phphb_gtz && lhphb_ltz ? -ONE : ONE);\n+            const float distdslv = (phphb_ltz ? (lhphb_ltz ? NPNPDIST : NPPDIST) : (lhphb_ltz\n+                                                                                    ? NPPDIST\n+                                                                                    : -FLT_MAX));\n+            const float r_distdslv = ONE / distdslv;\n+\n+            const float chrg_init = l_params.elsc * p_params.elsc;\n+            const float dslv_init = p_hphb + l_hphb;\n+\n+            for (int l = 0; l < PPWI; l++) {\n+                // Calculate distance between atoms\n+                const float x = lpos_x[l] - p_atom.x;\n+                const float distij = (x * x);\n+\n+                // Calculate the sum of the sphere radii\n+                const float distbb = distij - radij;\n+\n+                const int zone1 = (distbb < ZERO);\n+\n+                // Calculate formal and dipole charge interactions\n+                float chrg_e = chrg_init * ((zone1 ? ONE : (ONE - distbb * elcdst1)) *\n+                                            (distbb < elcdst ? ONE : ZERO));\n+                float neg_chrg_e = -fabsf(chrg_e);\n+                chrg_e = type_E ? neg_chrg_e : chrg_e;\n+                etot[l] += chrg_e * CNSTNT;\n+            }\n+        }\n+    }\n+\n+    // Write result\n+    for (int l = 0; l < PPWI; l++) {\n+        energies[group * PPWI + l] = etot[l] * HALF;\n+    }\n+}\n+\n+/* { dg-final { scan-tree-dump-times {\\.COND_MUL} 1 \"optimized\" } } */\n+/* { dg-final { scan-tree-dump-times {\\.VCOND} 1 \"optimized\" } } */\n","prefixes":[]}