From patchwork Tue Sep 5 21:15:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christoph_M=C3=BCllner?= X-Patchwork-Id: 137547 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ab0a:0:b0:3f2:4152:657d with SMTP id m10csp1932245vqo; Tue, 5 Sep 2023 14:17:08 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHw7qOsOnTw4gFa1nzJ+OZzogET76fWLb2s8p7mNNNqlSojlA6ht7bGVrovUvgiHdRtT56f X-Received: by 2002:aa7:ce1a:0:b0:52c:9ce1:f117 with SMTP id d26-20020aa7ce1a000000b0052c9ce1f117mr601792edv.40.1693948628306; Tue, 05 Sep 2023 14:17:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693948628; cv=none; d=google.com; s=arc-20160816; b=B7XozE7zUOCcVVIYrDX58zD4u0H8+W4OCRAbnE33H2n1FFtmFWDNLe3OLzFpYjYQI6 jBQLJHoHTXcla29NyUpzBGjHRP1TnB9KY1hsQnem+Dg37W5NroEWrrY3dBiBTow4/v7N JYfCFflKq9+TxuX9hz6ROoL8VmKru9l31MSrq3YjufgxrYn9Tz00I7kl0qqD9YKAQqwH 6mks1ha7ligronbmrAqmP3ep8GHOFNjZwQ/NUzEHlCRKkr+7M+ztPCn8dIfutFuy6CsZ hElL+5woVzQeOmvssXS3M2V2QeB8e+NXrNzWb1jlQBbilVL4Xg/L8+KGgOC2CRrxDRGV 1Xbw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:to:from:dkim-signature :dmarc-filter:delivered-to; bh=47ZDmeyB4U76+BpiZtaQaZTlMMK4FwrhEQ+0yai1j88=; fh=rhzHQJhq9WV4qpo88d7UFjCUBpstN9AhlgFhCyDisF8=; b=cqka5rmI0NksUBoFS9Js5Mu7/lYpGY0d5cH3TU4brHAvj8tf/Ka3fDqEVLvk4g+tmD xEte5eY10RANY1Wfv0eHlfmrGC6Ju/cc/NTVtS3xcdQOags9EQbLuW9KuZvYETpsihQv wbm3igvr4jzrPUi7PFQcAAVn86C4M9HjOdJwwnSNK/4wrmwqqBKpQJXjte40wHVMCa0n 3MfG0k17pNrYqnZQ2ehhIx2aSr1vIg4r6JJqm0Zlx/uSInS8gb/2QgmcJOBTLv0g36Jr 8UXWW0XO37rUWpN9Z1Ea6qxuroy5OlOTB8nhxMXOrGU2PLBL1xnOhBagKu8wym/KVXFh 5gKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@vrull.eu header.s=google header.b="T1D6Rcj/"; 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" Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id v26-20020aa7d9da000000b005288906402dsi1125273eds.348.2023.09.05.14.17.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Sep 2023 14:17:08 -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=fail header.i=@vrull.eu header.s=google header.b="T1D6Rcj/"; 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" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 72028385771C for ; Tue, 5 Sep 2023 21:16:34 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-ed1-x52e.google.com (mail-ed1-x52e.google.com [IPv6:2a00:1450:4864:20::52e]) by sourceware.org (Postfix) with ESMTPS id 2D08C3858D28 for ; Tue, 5 Sep 2023 21:16:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2D08C3858D28 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=vrull.eu Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=vrull.eu Received: by mail-ed1-x52e.google.com with SMTP id 4fb4d7f45d1cf-52e297c7c39so3460464a12.2 for ; Tue, 05 Sep 2023 14:16:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vrull.eu; s=google; t=1693948563; x=1694553363; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=47ZDmeyB4U76+BpiZtaQaZTlMMK4FwrhEQ+0yai1j88=; b=T1D6Rcj/Z1nFlgiiR+UFsalSCIJyLjyOT1TIuXQFJ8a9bescvuyF/Jn7+7E6N4NfSl uvo63Anoti6Y0oMGaRNIEJ9umFPKU/h6/yAwZuc09VyPndf+BIuKlkwnB1X796etn3Ib JtjKxJrzIeAOEHC3Gp8XBxjvGgYyDm2+l/j2fUf9rjJTO3Y7KtBWZcYmh0Y5FvCwoA08 nXhsk17w2Wt4Iro799c3IAGqMk8Hh0FMRR81a+4xVe29NQ4CoPMFxyAZmPfNNsh50uOV aaFEYvL3N15PY/fZbZdkPm2tkRQsvCS6OzlciCbovmd+hxNoaMVWLnYlnCIfkXL3w1DI uKUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693948563; x=1694553363; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=47ZDmeyB4U76+BpiZtaQaZTlMMK4FwrhEQ+0yai1j88=; b=eacP1nDSfqi5zrS5Wuga5CqmTLiZ+ldygJ/SF3nGcxEWPkUWeZc4ZMkU8rSq+St1yn Uw2+kr12Ef9SDLGffoiXUxPT4SAN/cTqQwDugalwMDSvBBiuSj5mQJB6hch0s8sciHH/ 9bslXU2RP+/6dlu1xhvtM1mo1PMXLY8UzThOJpYmSdEz6i4lyhjZYNDNrsaM9cKOaGb6 ut2xDDhW05GnRHw16PJ1gbnBNmqUuIHuLfITT4Ne0Zzyzj+U44fy/VI6M0aUMpDKXkC+ +KTtHAeu0F9LVpynFIYjatNX2hUeV+J8ZDEXCfeLbdYX9JxMrgO+D1G1qw0iCLnM4W/v jLUw== X-Gm-Message-State: AOJu0Ywlca5nK/c+O2I+n6WFV+1Z8Cn4JDJw4aImvLnm+zkcCfhIIeSS k4PirOYUe2buVRxlqahLz5LmH4nz8VMewOryG78= X-Received: by 2002:aa7:db57:0:b0:522:2782:537 with SMTP id n23-20020aa7db57000000b0052227820537mr670282edt.15.1693948563394; Tue, 05 Sep 2023 14:16:03 -0700 (PDT) Received: from beast.fritz.box (62-178-148-172.cable.dynamic.surfer.at. [62.178.148.172]) by smtp.gmail.com with ESMTPSA id v19-20020aa7d653000000b0052540e85390sm7524842edr.43.2023.09.05.14.16.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Sep 2023 14:16:03 -0700 (PDT) From: Christoph Muellner To: gcc-patches@gcc.gnu.org, Kito Cheng , Jim Wilson , Palmer Dabbelt , Andrew Waterman , Philipp Tomsich , Jeff Law Subject: [PATCH] riscv: Synthesize all 11-bit-rotate constants with rori Date: Tue, 5 Sep 2023 23:15:59 +0200 Message-ID: <20230905211559.2871358-1-christoph.muellner@vrull.eu> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_MANYTO, KAM_SHORT, LIKELY_SPAM_BODY, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776233876685046554 X-GMAIL-MSGID: 1776233876685046554 From: Christoph Müllner Some constants can be built up using LI+RORI instructions. The current implementation requires one of the upper 32-bits to be a zero bit, which is not neccesary. Let's drop this requirement in order to be able to synthesize a constant like 0xffffffff00ffffffL. The tests for LI+RORI are made more strict to detect regression in the calculation of the LI constant and the rotation amount. Signed-off-by: Christoph Müllner gcc/ChangeLog: * config/riscv/riscv.cc (riscv_build_integer_1): Don't require one zero bit in the upper 32 bits for LI+RORI synthesis. gcc/testsuite/ChangeLog: * gcc.target/riscv/xtheadbb-li-rotr.c: New tests. * gcc.target/riscv/zbb-li-rotr.c: Likewise. --- gcc/config/riscv/riscv.cc | 7 +- .../gcc.target/riscv/xtheadbb-li-rotr.c | 66 +++++++++++++++++-- gcc/testsuite/gcc.target/riscv/zbb-li-rotr.c | 57 +++++++++++++++- 3 files changed, 118 insertions(+), 12 deletions(-) diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc index ef63079de8e..d8917d75087 100644 --- a/gcc/config/riscv/riscv.cc +++ b/gcc/config/riscv/riscv.cc @@ -572,10 +572,9 @@ riscv_build_integer_1 (struct riscv_integer_op codes[RISCV_MAX_INTEGER_OPS], int trailing_ones = ctz_hwi (~value); /* If all bits are one except a few that are zero, and the zero bits - are within a range of 11 bits, and at least one of the upper 32-bits - is a zero, then we can generate a constant by loading a small - negative constant and rotating. */ - if (leading_ones < 32 + are within a range of 11 bits, then we can synthesize a constant + by loading a small negative constant and rotating. */ + if (leading_ones < 64 && ((64 - leading_ones - trailing_ones) < 12)) { codes[0].code = UNKNOWN; diff --git a/gcc/testsuite/gcc.target/riscv/xtheadbb-li-rotr.c b/gcc/testsuite/gcc.target/riscv/xtheadbb-li-rotr.c index ecd50448d77..136dcb01cf4 100644 --- a/gcc/testsuite/gcc.target/riscv/xtheadbb-li-rotr.c +++ b/gcc/testsuite/gcc.target/riscv/xtheadbb-li-rotr.c @@ -1,34 +1,88 @@ /* { dg-do compile } */ /* { dg-options "-march=rv64gc_xtheadbb" } */ +/* { dg-skip-if "" { *-*-* } {"-O0" "-Os" "-Og" "-Oz" "-flto" } } */ +/* { dg-final { check-function-bodies "**" "" } } */ +/* +**li_th_srri_1: +** li a[0-9]+,-18 +** th.srri a[0-9]+,a[0-9]+,21 +** ret +*/ long -li_rori (void) +li_th_srri_1 (void) { return 0xffff77ffffffffffL; } +/* +**li_th_srri_2: +** li a[0-9]+,-18 +** th.srri a[0-9]+,a[0-9]+,5 +** ret +*/ long -li_rori_2 (void) +li_th_srri_2 (void) { return 0x77ffffffffffffffL; } +/* +**li_th_srri_3: +** li a[0-9]+,-18 +** th.srri a[0-9]+,a[0-9]+,36 +** ret +*/ long -li_rori_3 (void) +li_th_srri_3 (void) { return 0xfffffffeefffffffL; } +/* +**li_th_srri_4: +** li a[0-9]+,-86 +** th.srri a[0-9]+,a[0-9]+,3 +** ret +*/ long -li_rori_4 (void) +li_th_srri_4 (void) { return 0x5ffffffffffffff5L; } +/* +**li_th_srri_5: +** li a[0-9]+,-86 +** th.srri a[0-9]+,a[0-9]+,4 +** ret +*/ long -li_rori_5 (void) +li_th_srri_5 (void) { return 0xaffffffffffffffaL; } -/* { dg-final { scan-assembler-times "th.srri\t" 5 } } */ +/* +**li_th_srri_6: +** li a[0-9]+,-256 +** th.srri a[0-9]+,a[0-9]+,40 +** ret +*/ +long +li_th_srri_6 (void) +{ + return 0xffffffff00ffffffL; +} + +/* +**li_th_srri_7: +** li a[0-9]+,-2048 +** th.srri a[0-9]+,a[0-9]+,16 +** ret +*/ +long +li_th_srri_7 (void) +{ + return 0xf800ffffffffffffL; +} diff --git a/gcc/testsuite/gcc.target/riscv/zbb-li-rotr.c b/gcc/testsuite/gcc.target/riscv/zbb-li-rotr.c index 500264a49dd..594c3dcaa49 100644 --- a/gcc/testsuite/gcc.target/riscv/zbb-li-rotr.c +++ b/gcc/testsuite/gcc.target/riscv/zbb-li-rotr.c @@ -1,35 +1,88 @@ /* { dg-do compile } */ /* { dg-options "-march=rv64gc_zbb -mabi=lp64" } */ +/* { dg-skip-if "" { *-*-* } {"-O0" "-Os" "-Og" "-Oz" "-flto" } } */ +/* { dg-final { check-function-bodies "**" "" } } */ +/* +**li_rori_1: +** li a[0-9]+,-18 +** rori a[0-9]+,a[0-9]+,21 +** ret +*/ long -li_rori (void) +li_rori_1 (void) { return 0xffff77ffffffffffL; } +/* +**li_rori_2: +** li a[0-9]+,-18 +** rori a[0-9]+,a[0-9]+,5 +** ret +*/ long li_rori_2 (void) { return 0x77ffffffffffffffL; } +/* +**li_rori_3: +** li a[0-9]+,-18 +** rori a[0-9]+,a[0-9]+,36 +** ret +*/ long li_rori_3 (void) { return 0xfffffffeefffffffL; } +/* +**li_rori_4: +** li a[0-9]+,-86 +** rori a[0-9]+,a[0-9]+,3 +** ret +*/ long li_rori_4 (void) { return 0x5ffffffffffffff5L; } +/* +**li_rori_5: +** li a[0-9]+,-86 +** rori a[0-9]+,a[0-9]+,4 +** ret +*/ long li_rori_5 (void) { return 0xaffffffffffffffaL; } +/* +**li_rori_6: +** li a[0-9]+,-256 +** rori a[0-9]+,a[0-9]+,40 +** ret +*/ +long +li_rori_6 (void) +{ + return 0xffffffff00ffffffL; +} -/* { dg-final { scan-assembler-times "rori\t" 5 } } */ +/* +**li_rori_7: +** li a[0-9]+,-2048 +** rori a[0-9]+,a[0-9]+,16 +** ret +*/ +long +li_rori_7 (void) +{ + return 0xf800ffffffffffffL; +}