From patchwork Thu Nov 10 21:34:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philipp Tomsich X-Patchwork-Id: 60372 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 069F4385E004 for ; Thu, 10 Nov 2022 21:35:08 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-lf1-x136.google.com (mail-lf1-x136.google.com [IPv6:2a00:1450:4864:20::136]) by sourceware.org (Postfix) with ESMTPS id C4E7C3858D38 for ; Thu, 10 Nov 2022 21:34:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C4E7C3858D38 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-lf1-x136.google.com with SMTP id be13so5556154lfb.4 for ; Thu, 10 Nov 2022 13:34:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vrull.eu; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=I3ioCCLC5P8cc8fXgMBRar4oHPIEDgmtAe6eiyoCFck=; b=QvJRORkQKM3VbqWtp++1oFuL7ikb8c6IzVxKW6pWfY9GXOj23oWAcA4CRncvOUW3ua qayq0Ol0YsgE6B5X/+n+Q8Vqz3P2oB3Se/v2yfEpINxGtIjnSyk1QTIGeYoGMnBn/Vj5 LQWgrgigoGPN/ENVxATXzJrRDQHam8gQneqPRG65nR3WivSRDbehCsuJdpmka4bC8z5L jB+ZeTOPs97ROWviQ/pVmfqpI6Tkq9XpoG81/dQr1xSlWj3cT3M3aXVjFMb1XZNdbuR1 ZqpERycwAcHo1cs/lVrF6hKdk965vJEEVCEgehzTA2VeMY2/uBm7wZQpG0Y25KPiwGQO rVuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=I3ioCCLC5P8cc8fXgMBRar4oHPIEDgmtAe6eiyoCFck=; b=xoybAU6MQhgfUXBgVRXNxbPOa8UZELNxvwA6nEedzYFA16d0Nas9zYPX5PFaRt+xT7 24ihlcMc5vo+kl29GCSyH2OfQqEAIj4VGASPyVkdYZc4AoSyabo3EPJqUFP6wu24goX9 loRKGIzNPpokFtZ7sWWtbtZgGyKf3Nxn9uFaaQjjvGbgDl81xso2BT3heC66wVcGDrfH ecB4c66gXbf/VEyPoTXpSwsHMKN26y59jjo2Qvwo15+VI+HqqCN9Im5taCUkQyNsGoo/ J8Z2qENPezRAZ/Gw6lNiBbLPrSGMq1+KRAn33wgcVJkY5qmWW1ahyHXL9/8HLHx88w9s 71lw== X-Gm-Message-State: ANoB5pmyIpvlMD6sPZwU6UoQVXnjA3I3RwZYHZBIl0Z2Ywx9tV4wcyiI fKHcZh8KQtFVxQA5d44jxqpvQgmi1Wgj/ggS X-Google-Smtp-Source: AA0mqf4qPFelSF0aYb/q9583yFZNbVuk0FURvvPgXLJEZajI90K/cxkFae18d4slWbjLDk4ZeAhLPw== X-Received: by 2002:a05:6512:238c:b0:4b4:87b8:cc89 with SMTP id c12-20020a056512238c00b004b487b8cc89mr310700lfv.89.1668116087973; Thu, 10 Nov 2022 13:34:47 -0800 (PST) Received: from ubuntu-focal.. ([2a01:4f9:3a:1e26::2]) by smtp.gmail.com with ESMTPSA id u26-20020ac25bda000000b004aab0ca795csm27911lfn.211.2022.11.10.13.34.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Nov 2022 13:34:47 -0800 (PST) From: Philipp Tomsich To: gcc-patches@gcc.gnu.org Cc: Vineet Gupta , Jeff Law , Christoph Muellner , Palmer Dabbelt , Kito Cheng , Philipp Tomsich Subject: [PATCH] RISC-V: Use bseti to cover more immediates than with ori alone Date: Thu, 10 Nov 2022 22:34:45 +0100 Message-Id: <20221110213445.3592438-1-philipp.tomsich@vrull.eu> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-12.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_SHORT, 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Sequences of the form "a | C" with C being the positive half of a signed immediate's range with one extra bit set in addtion are mapped to ori and one binvi to avoid using a temporary (and a multi-insn sequence to load C into that temporary). gcc/ChangeLog: * config/riscv/bitmanip.md (*bseti_extrabit): New pattern gcc/testsuite/ChangeLog: * gcc.target/riscv/zbs-bseti.c: New test. Signed-off-by: Philipp Tomsich --- - Depends on a predicate posted in "RISC-V: Optimize branches testing a bit-range or a shifted immediate". Depending on the order of applying these, I'll take care to pull that part out of the other patch if needed. gcc/config/riscv/bitmanip.md | 19 +++++++++++++++ gcc/testsuite/gcc.target/riscv/zbs-bseti.c | 27 ++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 gcc/testsuite/gcc.target/riscv/zbs-bseti.c diff --git a/gcc/config/riscv/bitmanip.md b/gcc/config/riscv/bitmanip.md index 06126ac4819..436ff4ba958 100644 --- a/gcc/config/riscv/bitmanip.md +++ b/gcc/config/riscv/bitmanip.md @@ -512,6 +512,25 @@ "bseti\t%0,%1,%S2" [(set_attr "type" "bitmanip")]) +; Catch those cases where we can use a bseti + ori or bseti + bseti +; instead of a lui + addi + or sequence. +(define_insn_and_split "*bseti_extrabit" + [(set (match_operand:X 0 "register_operand" "=r") + (ior:X (match_operand:X 1 "register_operand" "r") + (match_operand:X 2 "uimm_extra_bit_operand" "i")))] + "TARGET_ZBS" + "#" + "&& reload_completed" + [(set (match_dup 0) (ior:X (match_dup 1) (match_dup 3))) + (set (match_dup 0) (ior:X (match_dup 0) (match_dup 4)))] +{ + unsigned HOST_WIDE_INT bits = UINTVAL (operands[2]); + unsigned HOST_WIDE_INT topbit = HOST_WIDE_INT_1U << floor_log2 (bits); + + operands[3] = GEN_INT (bits &~ topbit); + operands[4] = GEN_INT (topbit); +}) + ;; As long as the SImode operand is not a partial subreg, we can use a ;; bseti without postprocessing, as the middle end is smart enough to ;; stay away from the signbit. diff --git a/gcc/testsuite/gcc.target/riscv/zbs-bseti.c b/gcc/testsuite/gcc.target/riscv/zbs-bseti.c new file mode 100644 index 00000000000..5738add6348 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/zbs-bseti.c @@ -0,0 +1,27 @@ +/* { dg-do compile } */ +/* { dg-options "-march=rv64gc_zbs -mabi=lp64" } */ +/* { dg-skip-if "" { *-*-* } { "-O0" "-Og" } } */ + +long long foo1 (long long a) +{ + return a | 0x1100; +} + +long long foo2 (long long a) +{ + return a | 0x80000000000000ffull; +} + +long long foo3 (long long a) +{ + return a | 0x8000000100000000ull; +} + +long long foo4 (long long a) +{ + return a | 0xfff; +} + +/* { dg-final { scan-assembler-times "bseti\t" 5 } } */ +/* { dg-final { scan-assembler-times "ori\t" 3 } } */ +