From patchwork Sat Aug 20 17:14:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Pan2 via Gcc-patches" X-Patchwork-Id: 640 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f406:0:0:0:0:0 with SMTP id g6csp290293wro; Sat, 20 Aug 2022 10:15:51 -0700 (PDT) X-Google-Smtp-Source: AA6agR4urw7Py3sTTkIMjaOEi75lUGLiWFkB5noI9nyloyqPVcJvnv7kEj1pkGGfVy0rueyBYzU+ X-Received: by 2002:a05:6402:5488:b0:443:39c5:5347 with SMTP id fg8-20020a056402548800b0044339c55347mr10121357edb.204.1661015750888; Sat, 20 Aug 2022 10:15:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661015750; cv=none; d=google.com; s=arc-20160816; b=tAVj6Gx+KAg/yU6+F9RF43pfciYhcr7bI79ocgBMU05YoiRAgz3KiUuPuaEMsXv4RN vBW42kbDVOvHq4VNJpVjsAqm3hn3L/n/HGTABMaC+Q7hfUs4pUVkDOZ6z5wAqqMXDvsx KGN4TCewCRGAoOgk1IHB8+4bXJFvVZCOPCfrF96WIwtU1zWT5JiB2VU3fddFrj9QbY/c /I5S2wB6CGoXb4Yy8n75M7Pi//cvJXTXvWamEVPCMnatLMk/9wxOl1QadzNccuAfI6Jw jUNKFabKXwdj2ntsQ2mJEjDa3/s42qWOSCMv5P3AR0IBQD/X19qgI2j/EYIMIwSd4inp +8Qg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:reply-to:from:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :mime-version:references:in-reply-to:message-id:date:subject:to :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=LSX6Fm4LyVTIqLL6WAPtkDWcBet6L9jG0hBKER1QAyw=; b=w/gr+dZpz2uuJBJbTN/jyxZMJM2k/G8ilI9ERkWy9sVkiVbAr6pxug/6nqeOIACbWB QCGIf8yA2q8y7JT7hiNNQbBmsfuWHVaerkBxY1mhMzBQMK5S8G14W124TSPYIcz7F0UU 7ExW8MjyTVbRUSjsLk68udxb4Ri+b5EO5bVQNs0HQ/YearHdagIQAe48ycrNB8wNhpTD bNRG70PGqflA82yM+JWAgoznF62jHxufOOYbuCrzsL4WQqgg3u0O6QS9PwtHFcIw75Mz Cpkntl/Ve2s77ySsut2yiGoRfb9EZybqbTdtPFlywOx31jE1515nrBobtN2mup8OxPWo PIkw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=gf8zkcbB; 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 5-20020a508e05000000b004458d44003csi5405412edw.499.2022.08.20.10.15.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Aug 2022 10:15:50 -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=gf8zkcbB; 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 489993857B89 for ; Sat, 20 Aug 2022 17:15:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 489993857B89 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1661015722; bh=LSX6Fm4LyVTIqLL6WAPtkDWcBet6L9jG0hBKER1QAyw=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=gf8zkcbBIDvla3LVx6hLRkpw+8bb5OcQkEPzLap21zKEsP+Ks5tBGbh+3z4bcBxFb Gmo1kN4LcT615/zvz7nuTvn9YLFAHkEqDXg8PqfL5U9XsniWYEvuh7R0ROZmRM6B/7 k6BR7/iiLU/Q8yT5mjya2XMFDwQkepRlY52OMY5s= 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 EE2B33858C52 for ; Sat, 20 Aug 2022 17:14:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org EE2B33858C52 Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 27KFl5L4006946 for ; Sat, 20 Aug 2022 10:14:33 -0700 Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3j2x2x0rb0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Sat, 20 Aug 2022 10:14:33 -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.2; Sat, 20 Aug 2022 10:14:32 -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.2 via Frontend Transport; Sat, 20 Aug 2022 10:14:32 -0700 Received: from linux.wrightpinski.org.com (unknown [10.69.242.198]) by maili.marvell.com (Postfix) with ESMTP id 084963F7065; Sat, 20 Aug 2022 10:14:31 -0700 (PDT) To: Subject: [PATCH 1/3] Fix PR 106600: __builtin_bswap32 is not hooked up for ZBB for 32bit Date: Sat, 20 Aug 2022 10:14:24 -0700 Message-ID: <1661015666-14659-2-git-send-email-apinski@marvell.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1661015666-14659-1-git-send-email-apinski@marvell.com> References: <1661015666-14659-1-git-send-email-apinski@marvell.com> MIME-Version: 1.0 X-Proofpoint-GUID: XsjRiwCE7rE50cHXVpcpu9MGGddryHYF X-Proofpoint-ORIG-GUID: XsjRiwCE7rE50cHXVpcpu9MGGddryHYF X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-08-20_08,2022-08-18_01,2022-06-22_01 X-Spam-Status: No, score=-14.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, 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 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: apinski--- via Gcc-patches From: "Li, Pan2 via Gcc-patches" Reply-To: apinski@marvell.com Cc: 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?1741701252026918873?= X-GMAIL-MSGID: =?utf-8?q?1741701252026918873?= From: Andrew Pinski The problem here is the bswap2 pattern had a check for TARGET_64BIT but then used the X iterator. Since the X iterator is either SI or DI depending on the setting TARGET_64BIT, there is no reason for the TARGET_64BIT. OK? Built and tested on both riscv32-linux-gnu and riscv64-linux-gnu. Thanks, Andrew Pinski gcc/ChangeLog: PR target/106600 * config/riscv/bitmanip.md (bswap2): Remove condition on TARGET_64BIT as X is already conditional there. gcc/testsuite/ChangeLog: PR target/106600 * gcc.target/riscv/zbb_32_bswap-1.c: New test. * gcc.target/riscv/zbb_bswap-1.c: New test. Change-Id: Iba3187e5620b0f291f7c38aab597f367b47a22c5 --- gcc/config/riscv/bitmanip.md | 2 +- gcc/testsuite/gcc.target/riscv/zbb_32_bswap-1.c | 11 +++++++++++ gcc/testsuite/gcc.target/riscv/zbb_bswap-1.c | 11 +++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.target/riscv/zbb_32_bswap-1.c create mode 100644 gcc/testsuite/gcc.target/riscv/zbb_bswap-1.c diff --git a/gcc/config/riscv/bitmanip.md b/gcc/config/riscv/bitmanip.md index d1570ce8508..c7ba667f87a 100644 --- a/gcc/config/riscv/bitmanip.md +++ b/gcc/config/riscv/bitmanip.md @@ -272,7 +272,7 @@ (define_insn "rotlsi3_sext" (define_insn "bswap2" [(set (match_operand:X 0 "register_operand" "=r") (bswap:X (match_operand:X 1 "register_operand" "r")))] - "TARGET_64BIT && TARGET_ZBB" + "TARGET_ZBB" "rev8\t%0,%1" [(set_attr "type" "bitmanip")]) diff --git a/gcc/testsuite/gcc.target/riscv/zbb_32_bswap-1.c b/gcc/testsuite/gcc.target/riscv/zbb_32_bswap-1.c new file mode 100644 index 00000000000..3ff7d9de409 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/zbb_32_bswap-1.c @@ -0,0 +1,11 @@ +/* { dg-do compile } */ +/* { dg-options "-march=rv32gc_zbb -mabi=ilp32" } */ +/* { dg-skip-if "" { *-*-* } { "-O0" } } */ + +int foo(int n) +{ + return __builtin_bswap32(n); +} + +/* { dg-final { scan-assembler "rev8" } } */ + diff --git a/gcc/testsuite/gcc.target/riscv/zbb_bswap-1.c b/gcc/testsuite/gcc.target/riscv/zbb_bswap-1.c new file mode 100644 index 00000000000..20feded0df2 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/zbb_bswap-1.c @@ -0,0 +1,11 @@ +/* { dg-do compile } */ +/* { dg-options "-march=rv64gc_zbb -mabi=lp64" } */ +/* { dg-skip-if "" { *-*-* } { "-O0" } } */ + +int foo(int n) +{ + return __builtin_bswap32(n); +} + +/* { dg-final { scan-assembler "rev8" } } */ + From patchwork Sat Aug 20 17:14:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Pan2 via Gcc-patches" X-Patchwork-Id: 639 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f406:0:0:0:0:0 with SMTP id g6csp290286wro; Sat, 20 Aug 2022 10:15:48 -0700 (PDT) X-Google-Smtp-Source: AA6agR5/5tHQF8Go05yC5tp0mdhfdhH6wAUU0QiaXoyECBzoqnH+3eRR3G9JYe8WopszHoR+lMi5 X-Received: by 2002:a05:6402:3324:b0:446:7bcc:6a93 with SMTP id e36-20020a056402332400b004467bcc6a93mr2474318eda.174.1661015748584; Sat, 20 Aug 2022 10:15:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661015748; cv=none; d=google.com; s=arc-20160816; b=RwZSDRYLn6SQYEwrj21K80F04zO5jhU/JWbQPmgtUAsLqY5mOANderhrvg0UJom/sI gWPY8z8KA6LB6ydGKE3+muf945WoaADOuG235vzW+oG5tCUfoZRBfJNJWqKIzEm9j9pA Z23u2rMnHStIAd0cS7ae+X5kvsYlbTp8FokYb2eCmfdzeRWFWiXfsso6XQeyriao29P7 PhZTFxg7rpsGGuYLnqc+H2bbDNMyL9RAMv4AStbp/op3+SIzVp0C4ncv30mKo4KKKDjM 5NKkxd9rO+VZv4nwiq9WDaV/6jtU09QDiPwBSb6N3mBq6WPuToB+3eaJI4PrNF3tnz/D WCGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:reply-to:from:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :mime-version:references:in-reply-to:message-id:date:subject:to :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=xSUlfKTa4w1Jionl1EkhNXbYuFZ5UVOLidnRSvEzgEQ=; b=s+aBEVgkFgAb7L1L6uzFVue/+ZSgKcHdJitTW3blgO+dV9XNiJqd0wf7uANYXrro/T immBSRxyY1iZTd11W3LXhJiQ4uyXeUuZRoEucG9v/ZVE2JadPsgoQ8pGQ24MHX4Q0Rsv a6C0C+qRJiifsrK8cvH8VQ1u5TdsInELUzBKH1FkP1jBVanJMdOmhbfpEFa6sNJ6bxgk Tg70E9uM5hko/qhHDbwh/cFd1NS72+kH9oo5mlvmxYx7o8A6MIXWzjs9AqFdGwBtNkow y0GiHHU9pA1YygHRi91j0KG+84y03RfMVLQzVqIlQ6cfAAXbeDX9bj1KLh9a8E1Q/Iav Kvkw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="R/DR5ixC"; 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 g13-20020a056402090d00b004405af7da47si5612871edz.564.2022.08.20.10.15.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Aug 2022 10:15:48 -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="R/DR5ixC"; 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 140C4385782C for ; Sat, 20 Aug 2022 17:15:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 140C4385782C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1661015721; bh=xSUlfKTa4w1Jionl1EkhNXbYuFZ5UVOLidnRSvEzgEQ=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=R/DR5ixC0Tk1sAwUfMZPxUuaryj7uDG82N6H6rMChBxdJCahc0Z7CkfWZWYKez+em QCs3uro6GH9MrOrEhVO+3UeQZLhXPGUQw1r0QaRzUQDE5upaNLuamXkMxreEiSXkQ6 Pho6+DfBk+nZcrNmhWC0tjeR3yZv7neQ151LKRGU= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by sourceware.org (Postfix) with ESMTPS id CE5223858C83 for ; Sat, 20 Aug 2022 17:14:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org CE5223858C83 Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 27KH0CPS017197 for ; Sat, 20 Aug 2022 10:14:34 -0700 Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 3j2y4jrm0k-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Sat, 20 Aug 2022 10:14:34 -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.18; Sat, 20 Aug 2022 10:14:32 -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.2 via Frontend Transport; Sat, 20 Aug 2022 10:14:32 -0700 Received: from linux.wrightpinski.org.com (unknown [10.69.242.198]) by maili.marvell.com (Postfix) with ESMTP id 5C4ED5B6937; Sat, 20 Aug 2022 10:14:32 -0700 (PDT) To: Subject: [PATCH 2/3] Fix PR 106601: __builtin_bswap16 code gen could be improved with ZBB enabled Date: Sat, 20 Aug 2022 10:14:25 -0700 Message-ID: <1661015666-14659-3-git-send-email-apinski@marvell.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1661015666-14659-1-git-send-email-apinski@marvell.com> References: <1661015666-14659-1-git-send-email-apinski@marvell.com> MIME-Version: 1.0 X-Proofpoint-GUID: vW2JKUmW4rMu7OBp8W8719yHDaCYvnpU X-Proofpoint-ORIG-GUID: vW2JKUmW4rMu7OBp8W8719yHDaCYvnpU X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-08-20_08,2022-08-18_01,2022-06-22_01 X-Spam-Status: No, score=-14.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, 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 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: apinski--- via Gcc-patches From: "Li, Pan2 via Gcc-patches" Reply-To: apinski@marvell.com Cc: 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?1741701249442947324?= X-GMAIL-MSGID: =?utf-8?q?1741701249442947324?= From: Andrew Pinski The default expansion for bswap16 is two extractions (shift/and) followed by an insertation (ior) and then a zero extend. This can be improved with ZBB enabled to just full byteswap followed by a (logical) shift right. This patch adds a new pattern for this which does that. OK? Built and tested on riscv32-linux-gnu and riscv64-linux-gnu. gcc/ChangeLog: PR target/106601 * config/riscv/bitmanip.md (bswaphi2): New pattern. gcc/testsuite/ChangeLog: PR target/106601 * gcc.target/riscv/zbb_32_bswap-2.c: New test. * gcc.target/riscv/zbb_bswap-2.c: New test. Change-Id: If61362c14664cf8685da17779217033689878f86 --- gcc/config/riscv/bitmanip.md | 24 +++++++++++++++++++ .../gcc.target/riscv/zbb_32_bswap-2.c | 12 ++++++++++ gcc/testsuite/gcc.target/riscv/zbb_bswap-2.c | 12 ++++++++++ 3 files changed, 48 insertions(+) create mode 100644 gcc/testsuite/gcc.target/riscv/zbb_32_bswap-2.c create mode 100644 gcc/testsuite/gcc.target/riscv/zbb_bswap-2.c diff --git a/gcc/config/riscv/bitmanip.md b/gcc/config/riscv/bitmanip.md index c7ba667f87a..c4383285d81 100644 --- a/gcc/config/riscv/bitmanip.md +++ b/gcc/config/riscv/bitmanip.md @@ -276,6 +276,30 @@ (define_insn "bswap2" "rev8\t%0,%1" [(set_attr "type" "bitmanip")]) +;; HI bswap can be emulated using SI/DI bswap followed +;; by a logical shift right +;; SI bswap for TARGET_64BIT is already similarly in +;; the common code. +(define_expand "bswaphi2" + [(set (match_operand:HI 0 "register_operand" "=r") + (bswap:HI (match_operand:HI 1 "register_operand" "r")))] + "TARGET_ZBB" +{ + rtx tmp = gen_reg_rtx (word_mode); + rtx newop1 = gen_lowpart (word_mode, operands[1]); + if (TARGET_64BIT) + emit_insn (gen_bswapdi2 (tmp, newop1)); + else + emit_insn (gen_bswapsi2 (tmp, newop1)); + rtx tmp1 = gen_reg_rtx (word_mode); + if (TARGET_64BIT) + emit_insn (gen_lshrdi3 (tmp1, tmp, GEN_INT (64 - 16))); + else + emit_insn (gen_lshrsi3 (tmp1, tmp, GEN_INT (32 - 16))); + emit_move_insn (operands[0], gen_lowpart (HImode, tmp1)); + DONE; +}) + (define_insn "3" [(set (match_operand:X 0 "register_operand" "=r") (bitmanip_minmax:X (match_operand:X 1 "register_operand" "r") diff --git a/gcc/testsuite/gcc.target/riscv/zbb_32_bswap-2.c b/gcc/testsuite/gcc.target/riscv/zbb_32_bswap-2.c new file mode 100644 index 00000000000..679b34c4e41 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/zbb_32_bswap-2.c @@ -0,0 +1,12 @@ +/* { dg-do compile } */ +/* { dg-options "-march=rv32gc_zbb -mabi=ilp32" } */ +/* { dg-skip-if "" { *-*-* } { "-O0" } } */ + +int foo(int n) +{ + return __builtin_bswap16(n); +} + +/* { dg-final { scan-assembler "rev8" } } */ +/* { dg-final { scan-assembler "srli" } } */ + diff --git a/gcc/testsuite/gcc.target/riscv/zbb_bswap-2.c b/gcc/testsuite/gcc.target/riscv/zbb_bswap-2.c new file mode 100644 index 00000000000..c358f6683f3 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/zbb_bswap-2.c @@ -0,0 +1,12 @@ +/* { dg-do compile } */ +/* { dg-options "-march=rv64gc_zbb -mabi=lp64" } */ +/* { dg-skip-if "" { *-*-* } { "-O0" } } */ + +int foo(int n) +{ + return __builtin_bswap16(n); +} + +/* { dg-final { scan-assembler "rev8" } } */ +/* { dg-final { scan-assembler "srli" } } */ + From patchwork Sat Aug 20 17:14:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Pan2 via Gcc-patches" X-Patchwork-Id: 641 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f406:0:0:0:0:0 with SMTP id g6csp290481wro; Sat, 20 Aug 2022 10:16:36 -0700 (PDT) X-Google-Smtp-Source: AA6agR54fQnA5IHLfKZC8iVxJpUW3VI9MO20zgyxG7LVtkv5WOW7GRyU8Sad9kZJv39m5zCf3Uvi X-Received: by 2002:a17:907:a059:b0:73d:62cf:cbc9 with SMTP id gz25-20020a170907a05900b0073d62cfcbc9mr2680978ejc.394.1661015796175; Sat, 20 Aug 2022 10:16:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661015796; cv=none; d=google.com; s=arc-20160816; b=oQYiw3BbY5g0W54mBILC9B3+90CfOP862NGMtBBjSbPYwfyGIeuwU7gVB18vPZZ4He SPiacoRRmSJulZg//1r/HIlg0Li/ha/MclhfwN5yxE/7t6WQDjmCga7smw+n73i3Js/+ 8ZegdIqEwZfb4tfDWH3nFjYEUV6/Q+/e2/2rH6V15856ux+WlaI/Z3TvnWX0dviqj5Ev +IGWtvoREDx9sqp7TA/Yv5AX72Wv3tQkGsU33F50VUskF6lBozNh7wuPoLTha9jMIb0S mAmIF6ydjS5oC+06XlkYIQCTrkFJPxEUmNCFJzXS3NcMy+jKriBpUoGXWB2EFrJnC31E 04jg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:reply-to:from:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :mime-version:references:in-reply-to:message-id:date:subject:to :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=q3klz6QZw8n8Uu8mTANecr1sX3xVr+ROapETnYP5wMA=; b=tS6QXJWHB+5G079420BszydWe/zxJtheUsd/rxp8Rd2YCOu4mJZC6bjw+UZ8HhkJB3 pk+Mv5eHHH5UbRbUfp4VEy+vDsHmtVqbmvasE+4ewCc4HYjewG0vlb13GoU4KzKq1HqR SWu2niBEdLO54eLH9cchtez4cWMTt91wW6RMrx6sozbsZwhLWdBInMMSDZi75aCQ7uLg CwYpRNoL8vhsEDhygNXUfjZ0vCUdn4IglVgYkiCaauv4CHxW3TJQIDCSLyQP+I4XzYMF rtpqT5c458FAi4yyfBrNni1uXzp4veVmZy+sekISKIByHBx9erWD+viVmSlMVudS+dtm d8Zg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=BIDZzSQQ; 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 dz18-20020a0564021d5200b0043c45284ef9si6069320edb.562.2022.08.20.10.16.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Aug 2022 10:16: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=BIDZzSQQ; 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 EB1BB3857C4E for ; Sat, 20 Aug 2022 17:16:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EB1BB3857C4E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1661015780; bh=q3klz6QZw8n8Uu8mTANecr1sX3xVr+ROapETnYP5wMA=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=BIDZzSQQHJ3ORbDaw5LCEZwq/USRY/BiFjASGQ3epeb15dP86KtqcBzMPOcnYga3V lLV4/UmjVArVI99QOP1085wWBVx4miibwmYnnQqd0GP/547Uy2bqEi94cWsSNseqGF 1fbDuPc/y1GjEY22P/ul1iTrfAlSw1Ja10tYuDDY= 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 EB8FC3858CDA for ; Sat, 20 Aug 2022 17:14:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org EB8FC3858CDA Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 27KFl5L5006946 for ; Sat, 20 Aug 2022 10:14:34 -0700 Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3j2x2x0rb0-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Sat, 20 Aug 2022 10:14:34 -0700 Received: from DC5-EXCH02.marvell.com (10.69.176.39) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Sat, 20 Aug 2022 10:14:32 -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.18 via Frontend Transport; Sat, 20 Aug 2022 10:14:32 -0700 Received: from linux.wrightpinski.org.com (unknown [10.69.242.198]) by maili.marvell.com (Postfix) with ESMTP id AF6AA5B693C; Sat, 20 Aug 2022 10:14:32 -0700 (PDT) To: Subject: [PATCH 3/3] Fix PR 106690: enable effective_target_bswap for RISCV targets with ZBB enabled by default Date: Sat, 20 Aug 2022 10:14:26 -0700 Message-ID: <1661015666-14659-4-git-send-email-apinski@marvell.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1661015666-14659-1-git-send-email-apinski@marvell.com> References: <1661015666-14659-1-git-send-email-apinski@marvell.com> MIME-Version: 1.0 X-Proofpoint-GUID: C2i6I0jGWAZjz61AREfaifIAGAfhWIdC X-Proofpoint-ORIG-GUID: C2i6I0jGWAZjz61AREfaifIAGAfhWIdC X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-08-20_08,2022-08-18_01,2022-06-22_01 X-Spam-Status: No, score=-14.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, 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 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: apinski--- via Gcc-patches From: "Li, Pan2 via Gcc-patches" Reply-To: apinski@marvell.com Cc: 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?1741701299491140886?= X-GMAIL-MSGID: =?utf-8?q?1741701299491140886?= From: Andrew Pinski While looking for testcases to quickly test, I Noticed that check_effective_target_bswap was not enabled for riscv when ZBB is enabled. This patch checks if ZBB is enabled when targeting RISCV* for bswap. OK? Ran the testsuite for riscv32-linux-gnu both with and without ZBB enabled. PR testsuite/106690 gcc/testsuite/ChangeLog: * lib/target-supports.exp (check_effective_target_bswap): Return true if riscv and ZBB ISA extension is enabled. Change-Id: I521c91e7fc1a54faa0c8399b685248690022278b --- gcc/testsuite/lib/target-supports.exp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/lib/target-supports.exp index 04a2a8e8659..0f1e1af31e9 100644 --- a/gcc/testsuite/lib/target-supports.exp +++ b/gcc/testsuite/lib/target-supports.exp @@ -8646,6 +8646,13 @@ proc check_effective_target_bswap { } { || [istarget powerpc*-*-*] || [istarget rs6000-*-*] || [istarget s390*-*-*] + || ([istarget riscv*-*-*] + && [check_no_compiler_messages_nocache riscv_zbb object { + #if __riscv_zbb <= 0 + #error ZBB is not enabled + #endif + int i; + } ""]) || ([istarget arm*-*-*] && [check_no_compiler_messages_nocache arm_v6_or_later object { #if __ARM_ARCH < 6