From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.15]) by sourceware.org (Postfix) with ESMTPS id D9D7F388217C for ; Fri, 14 Jun 2024 03:11:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D9D7F388217C Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=intel.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org D9D7F388217C Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=198.175.65.15 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1718334719; cv=pass; b=HTaxO9eCWjLn2vTz7BR3N4S6KXVfPFvWC2ub1KM5yo7IWK3QH0NyXVRv8GSW4l+BfVkrAmEAIZUfx3VaHK6uD6OxTRLQVOT1G3XAwD+77ha+dmQs/VLm1lpF+TnuvnMPnaFXZJ14sc00wnCxcqtJvXO+X5OwXR6wcibI+zXR9AY= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1718334719; c=relaxed/simple; bh=Cyy1NRlnFBjWoK9LtvEk4vqPQrv9H/QtuKxyizvDU4c=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=xrN6KR5RGMW5ZMHOe+V4cSQ6Go50VZyKLYkbEfkc/6+SH/vk1HRcUFE+HbcYklL7KRdJpIpxrv/AsiFcF/iEN/2B3USqZ5O7+2XV6COc0oy1MQJl2tUYIoNYKG33ewvlIxkXRtQyEvvxobErVqj83lyYKhhC/uqubyeDChDwOvg= ARC-Authentication-Results: i=2; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1718334717; x=1749870717; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=Cyy1NRlnFBjWoK9LtvEk4vqPQrv9H/QtuKxyizvDU4c=; b=KLBzMi5tOXmodD+W2pJMwQ7YSSQtijOzEgV6y5GPSCjyDh6yuPq7Kp8y 8UepkXwYzCGkj83ASsaQl75qCPdWTSYfHeuBusFDhreQ1CZWf14EtYpsA Fq7tZ18wiVV8lad+hQ5APHngLpz17f6IapaRSjMVbZ3ROjeg2uRRK0bdM R0Q/MgoqIBA9dg/5SYIfNzr1PhKHI+2Nyz13Jx6XizlTYbnOF4bG4jlsN aZdPoN4nAJ9oylGMySIAfHQzz46ePIQ16cFTXXhto3zRHbWm53GOXVbgr sg+Bt46hO7HNCLQ6DrjNc0pMn38Sc9aHeJdr9p5AqEn/Y+egz0o4XWYdR A==; X-CSE-ConnectionGUID: mYBqMNyASBaF2B6/JntZKQ== X-CSE-MsgGUID: b0zJoS1XSBGFMs0xyfc30A== X-IronPort-AV: E=McAfee;i="6700,10204,11102"; a="18988369" X-IronPort-AV: E=Sophos;i="6.08,236,1712646000"; d="scan'208";a="18988369" Received: from fmviesa007.fm.intel.com ([10.60.135.147]) by orvoesa107.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Jun 2024 20:11:55 -0700 X-CSE-ConnectionGUID: DqJifIocQ9+fj8tPkhWKbg== X-CSE-MsgGUID: L9e6UVMTTT2jabeHqUG/RQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,236,1712646000"; d="scan'208";a="40215907" Received: from fmsmsx603.amr.corp.intel.com ([10.18.126.83]) by fmviesa007.fm.intel.com with ESMTP/TLS/AES256-GCM-SHA384; 13 Jun 2024 20:11:55 -0700 Received: from fmsmsx612.amr.corp.intel.com (10.18.126.92) by fmsmsx603.amr.corp.intel.com (10.18.126.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Thu, 13 Jun 2024 20:11:54 -0700 Received: from fmsedg601.ED.cps.intel.com (10.1.192.135) by fmsmsx612.amr.corp.intel.com (10.18.126.92) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39 via Frontend Transport; Thu, 13 Jun 2024 20:11:54 -0700 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (104.47.55.176) by edgegateway.intel.com (192.55.55.70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Thu, 13 Jun 2024 20:11:54 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iJSLNhglpI3MLzJav3DkJu9GOoZyxOQp8QN7Dr9Dr5q2qp6bgijXLq5xAbY3ep/ezy9telD95dgDIzqg0X0FPUtPTsoyjF2Uca/eHYYIZ6yHYnaeCB4n4+hMgjJ1U1RMyF9LNEn1lFqIOzlyxlttRvcbZ7vvniwT7n9pFsUH+j3v22LkfMABlVzrlMvBgny37B/KBSxDkjxVcMYn4c+8c5G6/DB5c5tTljNnN1Qoyl+ya+vI82TgycC8806i09RuGIstxmKpNyPVIdG18KHMg469Ohn9cvX56FmJUsYU8bZrtGkvmI9UEZc6rB2lWnX4SOzRVzpg5p0Jm2ZC/m3j2w== 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=roIiG4bNf5Q+QO99fCOc1vvqQWI+CyhbUIcauVHGsfE=; b=beG5oKm8JTO6zqeMYidr3z0szO1cOFT3718dD3cAmY17Kc3muHs5EnUO+bjTPw0J19RIR5QJL+Eeqzru+7ixJIOPkZ7LaTgpD1Ow40KqUsjoWTe8iLYCSsu2tieYKOGjVCyxnuClDK6mukOp9IrHEQWNQJ8zkT+LGORmsTEgm33t5vsSpDlE+VCUBrFxmnDG9xamObNEoY/Ij0k6MAiA/2Bx9kyTsbZThhd8QUWeKQPacY01n59qraf4tswITndoS5T4X3q4lN/0ZRAuXGZ8U6sOCV1qviOnkHxNZYOA/rWb69FF5cM3FUL5jArpYYRkL3GbPVkjxfQTeD1B0uAv8A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Received: from DM4PR11MB5487.namprd11.prod.outlook.com (2603:10b6:5:39f::22) by DS0PR11MB8668.namprd11.prod.outlook.com (2603:10b6:8:1b6::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7677.20; Fri, 14 Jun 2024 03:11:52 +0000 Received: from DM4PR11MB5487.namprd11.prod.outlook.com ([fe80::8221:de1b:c203:95d2]) by DM4PR11MB5487.namprd11.prod.outlook.com ([fe80::8221:de1b:c203:95d2%7]) with mapi id 15.20.7677.024; Fri, 14 Jun 2024 03:11:52 +0000 From: "Kong, Lingling" To: "gcc-patches@gcc.gnu.org" CC: "Liu, Hongtao" , "Kong, Lingling" , Uros Bizjak Subject: [PATCH 2/3] [APX CFCMOV] Support APX CFCMOV in if_convert pass Thread-Topic: [PATCH 2/3] [APX CFCMOV] Support APX CFCMOV in if_convert pass Thread-Index: AQHavgb4Uo5uNmWEvEGAPhrcgjdVuLHGlSXA Date: Fri, 14 Jun 2024 03:11:52 +0000 Message-ID: References: <20240614025749.743388-1-lingling.kong@intel.com> <20240614025749.743388-3-lingling.kong@intel.com> In-Reply-To: <20240614025749.743388-3-lingling.kong@intel.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; x-ms-publictraffictype: Email x-ms-traffictypediagnostic: DM4PR11MB5487:EE_|DS0PR11MB8668:EE_ x-ms-office365-filtering-correlation-id: 463a9102-750c-4b51-c622-08dc8c1fbcfb x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0;ARA:13230035|1800799019|366011|376009|38070700013; x-microsoft-antispam-message-info: =?us-ascii?Q?96I25sJBBDZpZs9emIhvn5JZfWCRFQixiaUmhdF2TtA957nv6K9kQX+PztVF?= =?us-ascii?Q?bzvXW5Pm6wD5fgSH0ExcFJ+ZjrCEaSyXFo+uMRRkQlnO9L3WR5AL/sMQgACj?= =?us-ascii?Q?1SRu+noHS5BaTEhi8LugaYTbeLP78iZomdPQ9LZd3P1eLWbfrZBCryC9swg2?= =?us-ascii?Q?mkBjN7DRHiwVNfkYxveHb+nbAAwlkxz/AetL8BVW8xQ0z8FyXTUGeUCID+LY?= =?us-ascii?Q?u8f/gsErXufwRaExjY42ncPw83UktSXQZV6W6EwRXN9B0PojgfHC3zI6X1bA?= =?us-ascii?Q?mlr0D3N4N5log+C4PooWuFSlGudbS2x/SHYNc5lCC/S7UkLHDg9zLzBXAhwj?= =?us-ascii?Q?UIoDoD64n60e3LcUkq40M+t4Jxj/VVU/TPLXucDrsBgWchSDgzWV1wZ/PGeq?= =?us-ascii?Q?7NVBfg9H1Ex5BWnPgmfdFHYK/jcqmcDnni887FE3favX+TJVTIBuH4/XmMBu?= =?us-ascii?Q?3On4iYD5rFPIJpZOWa7xcgqmfaD5mVgWgGXR0K6R8KMJ21WnAOKILTGn/0OU?= =?us-ascii?Q?xYnJpN64QnLwu4xorvext3jHc8WMCYQyCJfZRQ+jD0CmTWDKbrCK4Az40jhs?= =?us-ascii?Q?BoCiPk71sUB+GrP4Tc4xDUYQnshTWHkWZq5R3B7ksDOX2/baQUGL6mXjbAve?= =?us-ascii?Q?T8u3iiKEhUsysGYX55rnetGlrX6Kyno5pLAR2s0wwae8cBb1LW1NYcq5wj9T?= =?us-ascii?Q?2Xd6wwBD7D2CpwlyRMUX/vIXxndigJy6wRqXmPLF7+3gKLs4lFv4p1AYo49E?= =?us-ascii?Q?PtJKCDeNIO1WI4V6fcRGOb/V/IQX/liNSxINr3E6WxR/AvQDA5GaVDCGIiAF?= =?us-ascii?Q?cJ3wBFcu/DtGwsDGQ0f8dYcgYZQRtaHdBeE8+GFDwMkrGQdD/ufa5CYak9Yu?= =?us-ascii?Q?BJynEoOSb7nGfLbtBwtFsGpE1u50CZ06FYOGblnW52o661ce9GahCVUKgMiz?= =?us-ascii?Q?edETrcK2YjJskR9tE+J2W5h1FqajF9vOXxAzwa5F72e233+Wggy+d03G0eNq?= =?us-ascii?Q?zDwNcS5BpG2298z4oWdobV1nvA5bXi+TvaruhxmHV8YWnGggL4MLeTXajplE?= =?us-ascii?Q?CjJnmhnNp/+NUeplvkU7bgcrWn5SNeCx+DHEV4BbSdkNOLWxO+0mWeWX96Z/?= =?us-ascii?Q?SBqr39EV+tybEeFAPmjbWnVSVYmFaoUSNwXEuRLwCIF1ZIus39C1AjtkvCCE?= =?us-ascii?Q?TsLQclcjebQshrzVZDa13HK2y6Fgw+5f87xMIL6YdvicM5M0DfpsYfqrRhTq?= =?us-ascii?Q?Tg+MR5EluYJX9gEEIrFTOyCJcZQZlquoODG4i8IXMN4scxneMRd87oB9sBte?= =?us-ascii?Q?QSdVcm+i3QdFuG2ika7abMuhAqN/Vmg1l+jhC1ISyfmxI7zErrjD0UXqChkd?= =?us-ascii?Q?5PAygv8=3D?= x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM4PR11MB5487.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230035)(1800799019)(366011)(376009)(38070700013);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?6czGtrx9axcDXqs7uacxYKBCccUucyLCkK+cSxrfWnL0VHV7oQjKN2BAyfTL?= =?us-ascii?Q?d9BYkaQ/ZGcTo1pMA3QJDUfpy+3jjA7c2OF47FZp2AhqRd8Xsg4+O9k/Xldm?= =?us-ascii?Q?0ftdlbVdaz4u0uDeN8VhdXoECxWGGIqN9YkdM6zymVRDWyKmV/+Rg/plu5Mv?= =?us-ascii?Q?LgYjlqojAXomiYe8ZQGeGhfXdcnJMOlSqxrqut5WmPC5tuifEPDb6qxlQamP?= =?us-ascii?Q?qSMBFZGLVz8dYKmFo3kdGJ+KxWs8FFAiVNIaqPsBomI2DOPG7vuI4fBoe9WL?= =?us-ascii?Q?FcxQYJ1O4/Z0fqJwGEDX78i/EZQ1sedSOpRE/5JvMWlfKoIi7pux2fEH3nU4?= =?us-ascii?Q?0Uc43CEo9LyvJTstZyxjF4bNA0sW0Oxj2VFUUeBwqUWqoxuI+HgOdRYwRXDt?= =?us-ascii?Q?TOu6N8rHwC0tj9KVaLzE93Qg14vc2LZawiklkEO8q5Xz9m5iDQejv63G87vZ?= =?us-ascii?Q?YgZ4ZX73VPWHVheZlPcg/HNVAm5hP+ZRDTguCySVlg/N2v+/aBmop3FCZJ+W?= =?us-ascii?Q?n3p/PtaYDsllYVcvtfgF+tZPMT4Ikg8PSDGgRHj85C6jXTidxZUB9nGSfFLA?= =?us-ascii?Q?zRKllqgj0qnhEQY96183W0NudgXCGUXui09byyVIoc9AnN5mkXXc7b3ysm/G?= =?us-ascii?Q?Je7WALvBGMzZcUPhvmRumsP7FOVH2qc/TXWB8yy+Cl3mYzIEb5+5stW1BC3r?= =?us-ascii?Q?KEl65sdPx7M1JGSIXC1J1PkugRmyAlPW81ArWgIBBZWdJ6GVFxBko9Jwl4iB?= =?us-ascii?Q?DSHnS/vv4uVDTafTslRGMHs2KBpQnR/gW77UEOWtLe8dPnenBa29wYpHEHZa?= =?us-ascii?Q?CWPKbhHKd967KTnYIHgFnnJ69UVBcknqkRJIF2xUGiayjRzmbZsXr+Gi2SPZ?= =?us-ascii?Q?fw+QjDyNxXdAw8QoYEe0dB99G21cwpNPST5Uhsp9kfWGGu3q1hcM9oX2Kkva?= =?us-ascii?Q?uXUgMxeLLLI8GKS5ePXMb0gNtTjBWwoHQ9qzZswOOwmVwpTkk6YtO+5A3fzJ?= =?us-ascii?Q?Hi46t+QnYligtYXdAjB0rqj459DvoktcNDJWdqBJhYXWniVe0TMr60DiX0si?= =?us-ascii?Q?JfxeqQ5a6VGUG6NUa3FL+xIzYS+0GWPbfSfK+D6SdKgnbV7blXgkN9HwcVI8?= =?us-ascii?Q?DjHITfzUOQipbLl8yOmk9A02P0GhMd6M+2l8+M4tVOpHr4Q5od+1D7ExkiAF?= =?us-ascii?Q?9pZ8mmYrefwMNw4aY+z3kTApP073coHTlERekHq9a6ox1CFUVQSE6EeNKP6X?= =?us-ascii?Q?Fkf+XLP68+GP3rIGBFcOzCOBPvJcJTM3b+WP+4kr25B1LjDhs2OUXa2QJKFu?= =?us-ascii?Q?KrNC3mDEp6Xc+hAPssjGP1K1gpWPVkY4AFKYT3rKTVIpGg6DCTJu1UllHDV/?= =?us-ascii?Q?a8TUg+alb4/Z4cfzdkBNqul1/OQuInlKDs8GEO3hdyT2RYsO8sOyWA/e3esp?= =?us-ascii?Q?V5Vs833LowJ6SvR4a5heQadXy3tLPLrvs2O0oJJAkuISPUyqMtH8P2ChSblO?= =?us-ascii?Q?tzKF0W7m1PQIIf/4+9HBKEwDjLxX+PyPU9vgIZxFMwIDKGIQrfV8rhD/0ms7?= =?us-ascii?Q?d/NNksLGZ8jZK5NDbgps1tFevO3ejCwu+TF972hd?= Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: DM4PR11MB5487.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 463a9102-750c-4b51-c622-08dc8c1fbcfb X-MS-Exchange-CrossTenant-originalarrivaltime: 14 Jun 2024 03:11:52.1807 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: OeFHROwAWI78Ibh6KHA0XjzaUUYSzFfW2ZE3MGwyH92dI83frwNRFcZhoxw63ddTbtVtPpM55AJ7mErMObXCjw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR11MB8668 X-OriginatorOrg: intel.com X-Spam-Status: No, score=-13.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,SPF_HELO_NONE,SPF_NONE,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: From: Lingling Kong After added target HOOK TARGET_HAVE_CONDITIONAL_MOVE_MEM_NOTRAP, we could support a conditional move that load or store mem may trap or fault in if convert pass. Conditional move suppress fault for conditional mem store would not move any arithmetic calculations. For conditional mem load now just support a conditional move one trap mem and one no trap and no mem cases. gcc/ChangeLog: * ifcvt.cc (noce_try_cmove_load_mem_notrap): Use target hook to allow convert to cfcmov for conditional load. (noce_try_cmove_store_mem_notrap): Convert to conditional store. (noce_process_if_block): Ditto. --- gcc/ifcvt.cc | 247 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 246 insertions(+), 1 deletion(-) diff --git a/gcc/ifcvt.cc b/gcc/ifcvt.cc index 58ed42673e5..6e3e48af810 100644 --- a/gcc/ifcvt.cc +++ b/gcc/ifcvt.cc @@ -783,6 +783,8 @@ static rtx noce_emit_cmove (struct noce_if_info *, rtx,= enum rtx_code, rtx, rtx, rtx, rtx, rtx =3D NULL, rtx =3D NULL); static bool noce_try_cmove (struct noce_if_info *); static bool noce_try_cmove_arith (struct noce_if_info *); +static bool noce_try_cmove_load_mem_notrap (struct noce_if_info *); +static bool noce_try_cmove_store_mem_notrap (struct noce_if_info *, rtx *,= rtx); static rtx noce_get_alt_condition (struct noce_if_info *, rtx, rtx_insn **= ); static bool noce_try_minmax (struct noce_if_info *); static bool noce_try_abs (struct noce_if_info *); @@ -2401,6 +2403,237 @@ noce_try_cmove_arith (struct noce_if_info *if_info) return false; } =20 +/* When target support suppress memory fault, try more complex cases invol= ving + conditional_move's source or dest may trap or fault. */ + +static bool +noce_try_cmove_load_mem_notrap (struct noce_if_info *if_info) +{ + rtx a =3D if_info->a; + rtx b =3D if_info->b; + rtx x =3D if_info->x; + + if (MEM_P (x)) + return false; + /* Just handle a conditional move from one trap MEM + other non_trap, + non mem cases. */ + if (!(MEM_P (a) ^ MEM_P (b))) + return false; + bool a_trap =3D may_trap_or_fault_p (a); + bool b_trap =3D may_trap_or_fault_p (b); + + if (!(a_trap ^ b_trap)) + return false; + if (a_trap && (!MEM_P (a) || !targetm.have_conditional_move_mem_notrap (= a))) + return false; + if (b_trap && (!MEM_P (b) || !targetm.have_conditional_move_mem_notrap (= b))) + return false; + + rtx orig_b; + rtx_insn *insn_a, *insn_b; + bool a_simple =3D if_info->then_simple; + bool b_simple =3D if_info->else_simple; + basic_block then_bb =3D if_info->then_bb; + basic_block else_bb =3D if_info->else_bb; + rtx target; + enum rtx_code code; + rtx cond =3D if_info->cond; + rtx_insn *ifcvt_seq; + + /* if (test) x =3D *a; else x =3D c - d; + =3D> x =3D c - d; + if (test) + x =3D *a; + */ + + code =3D GET_CODE (cond); + insn_a =3D if_info->insn_a; + insn_b =3D if_info->insn_b; + + machine_mode x_mode =3D GET_MODE (x); + + if (!can_conditionally_move_p (x_mode)) + return false; + + /* Because we only handle one trap MEM + other non_trap, non mem cases, + just move one trap MEM always in then_bb. */ + if (noce_reversed_cond_code (if_info) !=3D UNKNOWN) + { + bool reversep =3D false; + if (b_trap) + reversep =3D true; + + if (reversep) + { + if (if_info->rev_cond) + { + cond =3D if_info->rev_cond; + code =3D GET_CODE (cond); + } + else + code =3D reversed_comparison_code (cond, if_info->jump); + std::swap (a, b); + std::swap (insn_a, insn_b); + std::swap (a_simple, b_simple); + std::swap (then_bb, else_bb); + } + } + + if (then_bb && else_bb + && (!bbs_ok_for_cmove_arith (then_bb, else_bb, if_info->orig_x) + || !bbs_ok_for_cmove_arith (else_bb, then_bb, if_info->orig_x))) + return false; + + start_sequence (); + + /* If one of the blocks is empty then the corresponding B or A value + came from the test block. The non-empty complex block that we will + emit might clobber the register used by B or A, so move it to a pseud= o + first. */ + + rtx tmp_b =3D NULL_RTX; + + /* Don't move trap mem to a pseudo. */ + if (!may_trap_or_fault_p (b) && (b_simple || !else_bb)) + tmp_b =3D gen_reg_rtx (x_mode); + + orig_b =3D b; + + rtx emit_a =3D NULL_RTX; + rtx emit_b =3D NULL_RTX; + rtx_insn *tmp_insn =3D NULL; + bool modified_in_a =3D false; + bool modified_in_b =3D false; + /* If either operand is complex, load it into a register first. + The best way to do this is to copy the original insn. In this + way we preserve any clobbers etc that the insn may have had. + This is of course not possible in the IS_MEM case. */ + + if (! general_operand (b, GET_MODE (b)) || tmp_b) + { + if (insn_b) + { + b =3D tmp_b ? tmp_b : gen_reg_rtx (GET_MODE (b)); + rtx_insn *copy_of_b =3D as_a (copy_rtx (insn_b)); + rtx set =3D single_set (copy_of_b); + + SET_DEST (set) =3D b; + emit_b =3D PATTERN (copy_of_b); + } + else + { + rtx tmp_reg =3D tmp_b ? tmp_b : gen_reg_rtx (GET_MODE (b)); + emit_b =3D gen_rtx_SET (tmp_reg, b); + b =3D tmp_reg; + } + } + + if (tmp_b && then_bb) + { + FOR_BB_INSNS (then_bb, tmp_insn) + /* Don't check inside insn_a. We will have changed it to emit_a + with a destination that doesn't conflict. */ + if (!(insn_a && tmp_insn =3D=3D insn_a) + && modified_in_p (orig_b, tmp_insn)) + { + modified_in_a =3D true; + break; + } + + } + + modified_in_b =3D emit_b !=3D NULL_RTX && modified_in_p (a, emit_b); + /* If insn to set up A clobbers any registers B depends on, try to + swap insn that sets up A with the one that sets up B. If even + that doesn't help, punt. */ + if (modified_in_a && !modified_in_b) + { + if (!noce_emit_bb (emit_b, else_bb, b_simple)) + goto end_seq_and_fail; + + if (!noce_emit_bb (emit_a, then_bb, a_simple)) + goto end_seq_and_fail; + } + else if (!modified_in_a) + { + if (!noce_emit_bb (emit_b, else_bb, b_simple)) + goto end_seq_and_fail; + + if (!noce_emit_bb (emit_a, then_bb, a_simple)) + goto end_seq_and_fail; + } + else + goto end_seq_and_fail; + + target =3D noce_emit_cmove (if_info, x, code, XEXP (cond, 0), XEXP (cond= , 1), + a, b); + + if (! target) + goto end_seq_and_fail; + + if (target !=3D x) + noce_emit_move_insn (x, target); + + ifcvt_seq =3D end_ifcvt_sequence (if_info); + if (!ifcvt_seq || !targetm.noce_conversion_profitable_p (ifcvt_seq, if_i= nfo)) + return false; + + emit_insn_before_setloc (ifcvt_seq, if_info->jump, + INSN_LOCATION (if_info->insn_a)); + if_info->transform_name =3D "noce_try_cmove_load_mem_notrap"; + return true; + + end_seq_and_fail: + end_sequence (); + return false; +} + +static bool +noce_try_cmove_store_mem_notrap (struct noce_if_info *if_info, rtx *x_ptr,= rtx orig_x) +{ + rtx a =3D if_info->a; + rtx b =3D if_info->b; + rtx x =3D orig_x; + machine_mode x_mode =3D GET_MODE (x); + + if (!MEM_P (x) || !rtx_equal_p (x, b)) + return false; + if (!may_trap_or_fault_p (x) || !targetm.have_conditional_move_mem_notra= p (x)) + return false; + if (!if_info->then_simple || !register_operand (a, x_mode)) + return false; + + rtx cond =3D if_info->cond; + enum rtx_code code =3D GET_CODE (cond); + rtx_insn *ifcvt_seq; + + start_sequence (); + + rtx target =3D noce_emit_cmove (if_info, x, code, XEXP (cond, 0), XEXP (= cond, 1), + a, b); + + if (! target) + goto end_seq_and_fail; + + if (target !=3D x) + noce_emit_move_insn (x, target); + + ifcvt_seq =3D end_ifcvt_sequence (if_info); + if (!ifcvt_seq || !targetm.noce_conversion_profitable_p (ifcvt_seq, if_i= nfo)) + return false; + + emit_insn_before_setloc (ifcvt_seq, if_info->jump, + INSN_LOCATION (if_info->insn_a)); + if_info->transform_name =3D "noce_try_cmove_load_mem_notrap"; + if_info->x =3D orig_x; + *x_ptr =3D orig_x; + return true; + + end_seq_and_fail: + end_sequence (); + return false; +} + /* For most cases, the simplified condition we found is the best choice, but this is not the case for the min/max/abs transforms. For these we wish to know that it is A or B in the condition. */ @@ -4121,12 +4354,21 @@ noce_process_if_block (struct noce_if_info *if_info= ) } =20 if (!set_b && MEM_P (orig_x)) + { + /* Conditional_move_suppress_fault for condition mem store would not + move any arithmetic calculations. */ + if (targetm.have_conditional_move_mem_notrap (orig_x) + && HAVE_conditional_move + && noce_try_cmove_store_mem_notrap (if_info, &x, orig_x)) + goto success; + else /* We want to avoid store speculation to avoid cases like if (pthread_mutex_trylock(mutex)) ++global_variable; Rather than go to much effort here, we rely on the SSA optimizers, which do a good enough job these days. */ - return false; + return false; + } =20 if (noce_try_move (if_info)) goto success; @@ -4160,6 +4402,9 @@ noce_process_if_block (struct noce_if_info *if_info) if (HAVE_conditional_move && noce_try_cmove_arith (if_info)) goto success; + if (HAVE_conditional_move + && noce_try_cmove_load_mem_notrap (if_info)) + goto success; if (noce_try_sign_mask (if_info)) goto success; } --=20 2.31.1