From patchwork Fri Apr 28 17:02:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 88684 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1075759vqo; Fri, 28 Apr 2023 10:03:32 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6pWhsx7rTYQO+y9BcYTWcucwyRALph7jPUaMft5Tc2O+Kn/WzakcldVA7FvF3zWlBCesPB X-Received: by 2002:a17:906:da88:b0:94f:6003:c3cf with SMTP id xh8-20020a170906da8800b0094f6003c3cfmr6249688ejb.16.1682701412302; Fri, 28 Apr 2023 10:03:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682701412; cv=none; d=google.com; s=arc-20160816; b=ZMDqaFNlojDL1xKlB5NtPeEI+H+VLM7h94dwso+OQ+NlZNNY3j72ZqS92Idcn8hOTT ZoYVP/jng1VeeZNls6JM3UYFQEvIPQBRCAoBk6WHazuCQyRuLlnMRB7VScLdngARQZsW aFJUPVOe9TARegCUV2OKpg8ZaD1+wlrcjspKFOMhloHyWWieIYI6qeK6R1LFCCpizYL2 eZ/csIqVllQcACYwLQA/TCGSkb95TM1pEoMw2TgPeyvUrjD0bmB30nYnWtWa6TdJ6J3x h5Oqu78R2SXzRkLXW+PYfo9AU2lqKo91nK+9QrywmRZj+6ODLcX80LX3XaALojQyi/NI 6o0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=M+sPSmZkJODL8RE4ECPd5nOeZOWrHpuV9AtuAvaeeYM=; b=qNRybQzc104SCFDa/0OwXY+cMnDSR3fhfZgIhLulBWyXp0TN7MYh30tUpfzVUDkdQV sqONXfEa/pa0+oRMFfcULY4CycR9PT1u3fhLbfbxsUz2CaiGA9ZBn8vLv3uBVMvtF9e8 OhCpv9lCJPFK5TruRnz3Nqduley36mcCTtyTNFeMgIi6uKMlNL3N0ZWUB/+p63E1oM1Q LDZDZ3gaMSl5qEGHnNdwTh02UIVuSxzlfeTyK7dBClmJTwMMrEe/Up9C0wED/VKg226K QQ80rGsJDR9aezsoOhEX4+a1x7Q/2gQenFKriJs4SNIs1bnCdZg7TiOlv7E94B1qSh21 fhVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Dc0Zu+V2; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id y15-20020a17090614cf00b0094f7fed1764si16665554ejc.322.2023.04.28.10.03.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Apr 2023 10:03:32 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Dc0Zu+V2; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A3F573857001 for ; Fri, 28 Apr 2023 17:03:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A3F573857001 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1682701393; bh=M+sPSmZkJODL8RE4ECPd5nOeZOWrHpuV9AtuAvaeeYM=; h=To:CC:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=Dc0Zu+V208WBWqvYhhpPTByk4vWn2K1/U0GlxBySAh0vOw6O+rdSmew1WzspxPdCE uJLbKyyytr9MmQhbJeHOutldnjw7igoF2QnO7dEmZV+gf5nsImmNhJly5E+OCVJmHj MXbX7jej+a6zMeS2ru00GQfOkeAx6TSe77liLa94= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by sourceware.org (Postfix) with ESMTPS id 034A93858436 for ; Fri, 28 Apr 2023 17:02:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 034A93858436 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 33SA59Ak003400 for ; Fri, 28 Apr 2023 10:02:24 -0700 Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3q85x6309v-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Fri, 28 Apr 2023 10:02:23 -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; Fri, 28 Apr 2023 10:02:22 -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; Fri, 28 Apr 2023 10:02:22 -0700 Received: from vpnclient.wrightpinski.org.com (unknown [10.69.242.187]) by maili.marvell.com (Postfix) with ESMTP id 0FD385B6930; Fri, 28 Apr 2023 10:02:21 -0700 (PDT) To: CC: Andrew Pinski Subject: [PATCH 1/2] PHIOPT: Allow moving of some builtin calls Date: Fri, 28 Apr 2023 10:02:12 -0700 Message-ID: <20230428170213.677572-2-apinski@marvell.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230428170213.677572-1-apinski@marvell.com> References: <20230428170213.677572-1-apinski@marvell.com> MIME-Version: 1.0 X-Proofpoint-GUID: H2DhzgIqTuBC2w7mvicY7_AW7abJ8tlU X-Proofpoint-ORIG-GUID: H2DhzgIqTuBC2w7mvicY7_AW7abJ8tlU X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-04-28_04,2023-04-27_01,2023-02-09_01 X-Spam-Status: No, score=-14.5 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_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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Andrew Pinski via Gcc-patches From: Andrew Pinski Reply-To: Andrew Pinski Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1764440315725060202?= X-GMAIL-MSGID: =?utf-8?q?1764440315725060202?= While moving working on moving cond_removal_in_builtin_zero_pattern to match, I noticed that functions were not allowed to move as we reject all non-assignments. This changes to allowing a few calls which are known not to throw/trap. Right now it is restricted to ones which cond_removal_in_builtin_zero_pattern handles but adding more is just adding it to the switch statement. gcc/ChangeLog: * tree-ssa-phiopt.cc (empty_bb_or_one_feeding_into_p): Allow some builtin/internal function calls which are known not to trap/throw. (phiopt_worker::match_simplify_replacement): Use name instead of getting the lhs again. --- gcc/tree-ssa-phiopt.cc | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/gcc/tree-ssa-phiopt.cc b/gcc/tree-ssa-phiopt.cc index 4b43f1abdbc..024a4362093 100644 --- a/gcc/tree-ssa-phiopt.cc +++ b/gcc/tree-ssa-phiopt.cc @@ -548,6 +548,7 @@ empty_bb_or_one_feeding_into_p (basic_block bb, { stmt = nullptr; gimple *stmt_to_move = nullptr; + tree lhs; if (empty_block_p (bb)) return true; @@ -592,17 +593,43 @@ empty_bb_or_one_feeding_into_p (basic_block bb, if (gimple_uses_undefined_value_p (stmt_to_move)) return false; - /* Allow assignments and not no calls. + /* Allow assignments but allow some builtin/internal calls. As const calls don't match any of the above, yet they could still have some side-effects - they could contain gimple_could_trap_p statements, like floating point exceptions or integer division by zero. See PR70586. FIXME: perhaps gimple_has_side_effects or gimple_could_trap_p - should handle this. */ + should handle this. + Allow some known builtin/internal calls that are known not to + trap: logical functions (e.g. bswap and bit counting). */ if (!is_gimple_assign (stmt_to_move)) - return false; + { + if (!is_gimple_call (stmt_to_move)) + return false; + combined_fn cfn = gimple_call_combined_fn (stmt_to_move); + switch (cfn) + { + default: + return false; + case CFN_BUILT_IN_BSWAP16: + case CFN_BUILT_IN_BSWAP32: + case CFN_BUILT_IN_BSWAP64: + case CFN_BUILT_IN_BSWAP128: + CASE_CFN_FFS: + CASE_CFN_PARITY: + CASE_CFN_POPCOUNT: + CASE_CFN_CLZ: + CASE_CFN_CTZ: + case CFN_BUILT_IN_CLRSB: + case CFN_BUILT_IN_CLRSBL: + case CFN_BUILT_IN_CLRSBLL: + lhs = gimple_call_lhs (stmt_to_move); + break; + } + } + else + lhs = gimple_assign_lhs (stmt_to_move); - tree lhs = gimple_assign_lhs (stmt_to_move); gimple *use_stmt; use_operand_p use_p; From patchwork Fri Apr 28 17:02:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 88685 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1075844vqo; Fri, 28 Apr 2023 10:03:36 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6Rbr4OSKPPyAdnhB/D0onbBK/FXlpT91uXGMuQNnMg2gziUlStagKAoHKCoe99L/Ln/NMO X-Received: by 2002:a17:907:3181:b0:94f:558b:8577 with SMTP id xe1-20020a170907318100b0094f558b8577mr5994698ejb.29.1682701416710; Fri, 28 Apr 2023 10:03:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682701416; cv=none; d=google.com; s=arc-20160816; b=t8ui38r8TTahcNk/0c7Lh+9GXA7B81DWYRh2vFmv2R/p/zF1PDDFJN2N62pTWdy+/h +EehXj1qUZUGt1mKIT/BiaYMo7JZi/kAwGS+MvIoSnLBCSEoD85v482ocEYA/axhJ0MQ s4p2T99Eo8Xdt2Hq9EP7Ys5qdNGZ/6QOng3TCYEY90gkMMc8t8bITYIvUAXud0Z/91BU po7Qn1fgdNzNJue/lUOCQo//U82jh94fgge+06iIWPS6pYRBqzzNSn01dec0oywwS5Pd ZOia90/BPS0KGx1eJ3/dRTOE9MWjs2V/MJXjPZm7gGt+lT4F3U6e9wWabpUscbPFwTEE 8ang== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=vjyAA5bNtbw2ugpnRRHUeTCQ6qGJzTrVlmz30deXH6U=; b=he90Hf6Onm/WfIT9+e+YkJ9LkMJoHzQ3ICDGzKVHHs+URhxmHPw3SHmLazKhzIbUmC bIdvCfVI9hmId/n9UFj+5w5lR0M1yMo8ay76/tdMGeJ9TO31xdrNjQPr5GG2XAj523a0 Dd/zRLc1HJv7uQsufMAqlPGe54S0MAi3fAlmJUtXxXyxDOF0oLjuVFbOY/fKzYPUN0MX jX86/amBu6J2hBZExkPtGsVmWa52B/rnpsRIHeF3H79k3FwfniOZAZjHaMUARzmiUL+u C4GzFWK+B3Vpj3t34Pu/pMJAgsdhdN7UaJ9oeFWXF3n0vmjkdue92zIC2A5TmVh1q0u+ w6sA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=j0uIixh2; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id tx19-20020a1709078e9300b009582d919849si12201790ejc.907.2023.04.28.10.03.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Apr 2023 10:03:36 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=j0uIixh2; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 25FA5385843E for ; Fri, 28 Apr 2023 17:03:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 25FA5385843E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1682701396; bh=vjyAA5bNtbw2ugpnRRHUeTCQ6qGJzTrVlmz30deXH6U=; h=To:CC:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=j0uIixh2M2WUGCgJz4PCalAKAA8Ejlgv/yTKVvyo9zm1ehhdvrQMJEuiU/HEj1WJy prE09de98woIaJrB0/VWDTWkKKVIoeAW+/3ZPyn+NlzKtp9sYNe/gD4841GRLUzQOy tV/W10udv5fdJlpd5aDmfLHJNcXhmFbtln4iFCss= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by sourceware.org (Postfix) with ESMTPS id 8680D3858C1F for ; Fri, 28 Apr 2023 17:02:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8680D3858C1F 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 33SA5A6V003432 for ; Fri, 28 Apr 2023 10:02:24 -0700 Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3q85x630a2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Fri, 28 Apr 2023 10:02:24 -0700 Received: from DC5-EXCH01.marvell.com (10.69.176.38) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.48; Fri, 28 Apr 2023 10:02:22 -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; Fri, 28 Apr 2023 10:02:22 -0700 Received: from vpnclient.wrightpinski.org.com (unknown [10.69.242.187]) by maili.marvell.com (Postfix) with ESMTP id 8007E5B6933; Fri, 28 Apr 2023 10:02:22 -0700 (PDT) To: CC: Andrew Pinski Subject: [PATCH 2/2] MATCH: add some of what phiopt's builtin_zero_pattern did Date: Fri, 28 Apr 2023 10:02:13 -0700 Message-ID: <20230428170213.677572-3-apinski@marvell.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230428170213.677572-1-apinski@marvell.com> References: <20230428170213.677572-1-apinski@marvell.com> MIME-Version: 1.0 X-Proofpoint-GUID: CtASQ_mcs4gBixsIy2ykLZC9FLv-njkx X-Proofpoint-ORIG-GUID: CtASQ_mcs4gBixsIy2ykLZC9FLv-njkx X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-04-28_04,2023-04-27_01,2023-02-09_01 X-Spam-Status: No, score=-14.5 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_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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Andrew Pinski via Gcc-patches From: Andrew Pinski Reply-To: Andrew Pinski Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1764440320986283160?= X-GMAIL-MSGID: =?utf-8?q?1764440320986283160?= This adds the patterns for POPCOUNT BSWAP FFS PARITY CLZ and CTZ. For "a != 0 ? FUNC(a) : CST". CLRSB, CLRSBL, and CLRSBLL will be moved next. Note this is not enough to remove cond_removal_in_builtin_zero_pattern as we need to handle the case where there is an NOP_CONVERT inside the conditional to move out of the condition inside match_simplify_replacement. OK? Bootstrapped and tested on x86_64-linux-gnu. gcc/ChangeLog: * match.pd: Add patterns for "a != 0 ? FUNC(a) : CST" for FUNC of POPCOUNT BSWAP FFS PARITY CLZ and CTZ. --- gcc/match.pd | 41 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/gcc/match.pd b/gcc/match.pd index e17597ead26..0e782cde71d 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -52,6 +52,8 @@ along with GCC; see the file COPYING3. If not see gt ge eq ne le lt unordered ordered ungt unge unlt unle uneq ltgt) (define_operator_list simple_comparison lt le eq ne ge gt) (define_operator_list swapped_simple_comparison gt ge eq ne le lt) +(define_operator_list BSWAP BUILT_IN_BSWAP16 BUILT_IN_BSWAP32 + BUILT_IN_BSWAP64 BUILT_IN_BSWAP128) #include "cfn-operators.pd" @@ -4313,8 +4315,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (complex (convert:itype @0) (negate (convert:itype @1))))) /* BSWAP simplifications, transforms checked by gcc.dg/builtin-bswap-8.c. */ -(for bswap (BUILT_IN_BSWAP16 BUILT_IN_BSWAP32 - BUILT_IN_BSWAP64 BUILT_IN_BSWAP128) +(for bswap (BSWAP) (simplify (bswap (bswap @0)) @0) @@ -7780,6 +7781,42 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (bit_xor (PARITY:s @0) (PARITY:s @1)) (PARITY (bit_xor @0 @1))) +/* a != 0 ? FUN(a) : 0 -> Fun(a) for some builtin functions. */ +(for func (POPCOUNT BSWAP FFS PARITY) + (simplify + (cond (ne @0 integer_zerop@1) (func@4 (convert? @2)) integer_zerop@3) + @4)) + +#if GIMPLE +/* a != 0 ? CLZ(a) : CST -> .CLZ(a) where CST is the result of the internal function for 0. */ +(for func (CLZ) + (simplify + (cond (ne @0 integer_zerop@1) (func (convert?@4 @2)) INTEGER_CST@3) + (with { int val; + internal_fn ifn = IFN_LAST; + if (direct_internal_fn_supported_p (IFN_CLZ, type, OPTIMIZE_FOR_BOTH) + && CLZ_DEFINED_VALUE_AT_ZERO (SCALAR_INT_TYPE_MODE (type), + val) == 2) + ifn = IFN_CLZ; + } + (if (ifn == IFN_CLZ && wi::to_widest (@3) == val) + (IFN_CLZ @4))))) + +/* a != 0 ? CTZ(a) : CST -> .CTZ(a) where CST is the result of the internal function for 0. */ +(for func (CTZ) + (simplify + (cond (ne @0 integer_zerop@1) (func (convert?@4 @2)) INTEGER_CST@3) + (with { int val; + internal_fn ifn = IFN_LAST; + if (direct_internal_fn_supported_p (IFN_CTZ, type, OPTIMIZE_FOR_BOTH) + && CTZ_DEFINED_VALUE_AT_ZERO (SCALAR_INT_TYPE_MODE (type), + val) == 2) + ifn = IFN_CTZ; + } + (if (ifn == IFN_CTZ && wi::to_widest (@3) == val) + (IFN_CTZ @4))))) +#endif + /* Common POPCOUNT/PARITY simplifications. */ /* popcount(X&C1) is (X>>C2)&1 when C1 == 1<