From patchwork Tue Nov 8 20:03:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philipp Tomsich X-Patchwork-Id: 17200 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2921199wru; Tue, 8 Nov 2022 12:03:57 -0800 (PST) X-Google-Smtp-Source: AMsMyM6gepK6pc4eQJyo493mtAGy6ytWx3zYKvUo3+uxmG7tFQsnqvoGQ4rekIMIT4+CUBrcXzsa X-Received: by 2002:a05:6402:1f06:b0:457:149d:beaa with SMTP id b6-20020a0564021f0600b00457149dbeaamr56797000edb.238.1667937837908; Tue, 08 Nov 2022 12:03:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667937837; cv=none; d=google.com; s=arc-20160816; b=WDyCuAX3pQGH09geORbTXeye8gGsmUxQ1deitVSLjaeVqD+8sEV35azFEFaCeQj0tl u5wjoqdv3rxibEMjQYpAFvQV+ZPv2PvZIH9D9yI409hGoyJyi5/dTyxqlLnyG0tJo5fV yh0s+kayTzU4L0FP0oYcOY067BQSCe7CbTQZbPT03fiPgqbPjGXKFlycKS8zsVGjN77Y 90QSzoXluEm7eWgngfk2JoEr2Y+ySzlYpCPOAHxegBImyX/w4uY420IM4Mwhm+sO8YdL GWbYMYRSvBlS6j/1IFB1JNmbKhqvqXq1WA4amXL8EsaIsrDiBzL0/YoUbhMQ8jRQQojS Pzag== 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:cc:to:from:dkim-signature :dmarc-filter:delivered-to; bh=FwV3z3CrCow7t3sFS5knRKLThJVAvbtky7x1t3/hfXI=; b=lIlq+We0uXCik/pLGsIWWKY+OA0oFZ3DeYqTtQPU6/Nh8Tlo5QbnSvZ+3T6t2tifmj nm5aHFGG/m0Bd/5TLhbv6LBf7CK4+OBo91AWKeqGsU7XDQDOd9HfXD4393v+rXY8zQW0 6R4NmHMDMlo3XXQKOtfBH0GKGY1W8h28R23fSdnmkkhFCGHrDeyPhFUsGPBr3SGQXxVC gfuGSMhesOSNvbSGH32gF2gyhihMB0WRHl2tcP30AHqT5hEXM8Tc9H81m3yNgTbAmN4A M1cp0yhRjU+buFBpuw+jv2/pqSyTi1C94bUAI29R9W8MVDOG9RsV21YRvjeBFtbQuCvz LHZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@vrull.eu header.s=google header.b=VJSvM9x0; 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" Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id d16-20020a170906c21000b0076f0940cb28si291808ejz.175.2022.11.08.12.03.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Nov 2022 12:03:57 -0800 (PST) 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=@vrull.eu header.s=google header.b=VJSvM9x0; 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" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6E76D38582AE for ; Tue, 8 Nov 2022 20:03:56 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-lf1-x135.google.com (mail-lf1-x135.google.com [IPv6:2a00:1450:4864:20::135]) by sourceware.org (Postfix) with ESMTPS id 368EC3858D38 for ; Tue, 8 Nov 2022 20:03:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 368EC3858D38 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-x135.google.com with SMTP id p8so22674980lfu.11 for ; Tue, 08 Nov 2022 12:03:29 -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=FwV3z3CrCow7t3sFS5knRKLThJVAvbtky7x1t3/hfXI=; b=VJSvM9x0djYo9nBKxlWyhP43e42zCD/ESkv9HIp+MaMWc0RORKtC7qmhHUqPtdbZIF HqY4zzPBwHNwKAkIu6lAKEX8DCfU2HIfJkF1wvNYDJCD+c6HEoC2ugk801/ib3YkjuBF qxDFcnR5582SWcWMbLnhHp3fd8gw1mjky1mMsPe1UV6lwXrYC1j0eIA59R2Vre8zKhnX /WJ2bIZ9JuJpdgWCEaTRXWSxEx+dZVoYY53sPpeKF/t1HU2y3BBMialgwsgWAZZSZ1qF WI+gqkXthAzixyh/+NwP2+RVky24W3LZue39rBj32UC/3CiKvMQL1CYZo8P6p/EoyoyK H/1g== 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=FwV3z3CrCow7t3sFS5knRKLThJVAvbtky7x1t3/hfXI=; b=0k0KECmVEvFZhu/vIWsZnqxxBZuduCQ4DF/b/Ql/3+UgFI7rbTxFL3QHrM/iiKpmGx eGCXpQ5UVmCZJ0UyjcBpJuvqq0DTwKBr0yvxo8c9CG5xXmjPvnqfn+2PHXb0fQuJXcDb ACl7WOFcDuvJsZH82lvANsUGs77BicT4yCfgMBD+6MxZc6jj/Fpy5ujz84DKFbkS6NzQ OBTwqkprPI39xQVB6GAkpGRS7db0xNSNjgYQNI7LFmOVK8h2sCGi3E4pUkn2pF4kSvjZ FGpH2ecTPdBoumeDs02gKurd/m8wcDcCC+WdKqeARrBusX6T5xiLaDTvsvUKzFKNzlwK X9sw== X-Gm-Message-State: ANoB5plwcSxnnsCMER0GqgH7q500YkETBhAJDNp3648wOasEYvEA27Zc wQqxlmA1VSGpm43Z8asfRd3zVF7c+Z9KjBt/ X-Received: by 2002:ac2:515d:0:b0:4b4:1e69:16d7 with SMTP id q29-20020ac2515d000000b004b41e6916d7mr1061319lfd.293.1667937807145; Tue, 08 Nov 2022 12:03:27 -0800 (PST) Received: from ubuntu-focal.. ([2a01:4f9:3a:1e26::2]) by smtp.gmail.com with ESMTPSA id a13-20020a19f80d000000b00498f23c249dsm244877lff.74.2022.11.08.12.03.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Nov 2022 12:03:26 -0800 (PST) From: Philipp Tomsich To: gcc-patches@gcc.gnu.org Cc: Christoph Muellner , Vineet Gupta , Palmer Dabbelt , Jeff Law , Kito Cheng , Philipp Tomsich Subject: [PATCH] RISC-V: allow bseti on SImode without sign-extension Date: Tue, 8 Nov 2022 21:03:23 +0100 Message-Id: <20221108200323.2719563-1-philipp.tomsich@vrull.eu> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-12.2 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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748959586230951088?= X-GMAIL-MSGID: =?utf-8?q?1748959586230951088?= As long as the SImode operand is not a partial subreg, we can use a bseti without postprocessing to or in a bit, as the middle end is smart enough to stay away from the signbit. gcc/ChangeLog: * config/riscv/bitmanip.md (*bsetidisi): New pattern. gcc/testsuite/ChangeLog: * gcc.target/riscv/zbs-bexti-02.c: New test. Signed-off-by: Philipp Tomsich --- gcc/config/riscv/bitmanip.md | 12 +++++++++ gcc/testsuite/gcc.target/riscv/zbs-bseti-02.c | 25 +++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 gcc/testsuite/gcc.target/riscv/zbs-bseti-02.c diff --git a/gcc/config/riscv/bitmanip.md b/gcc/config/riscv/bitmanip.md index cbc00455b67..dddd3422c43 100644 --- a/gcc/config/riscv/bitmanip.md +++ b/gcc/config/riscv/bitmanip.md @@ -408,6 +408,18 @@ "bseti\t%0,%1,%S2" [(set_attr "type" "bitmanip")]) +;; 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. +(define_insn "*bsetidisi" + [(set (match_operand:DI 0 "register_operand" "=r") + (ior:DI (sign_extend:DI (match_operand:SI 1 "register_operand" "r")) + (match_operand 2 "single_bit_mask_operand" "i")))] + "TARGET_ZBS && TARGET_64BIT + && !partial_subreg_p (operands[2])" + "bseti\t%0,%1,%S2" + [(set_attr "type" "bitmanip")]) + (define_insn "*bclr" [(set (match_operand:X 0 "register_operand" "=r") (and:X (rotate:X (const_int -2) diff --git a/gcc/testsuite/gcc.target/riscv/zbs-bseti-02.c b/gcc/testsuite/gcc.target/riscv/zbs-bseti-02.c new file mode 100644 index 00000000000..d3629946375 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/zbs-bseti-02.c @@ -0,0 +1,25 @@ +/* { dg-do compile } */ +/* { dg-options "-march=rv64gc_zbs -mabi=lp64" } */ +/* { dg-skip-if "" { *-*-* } { "-O0" "-Og" } } */ + +/* bexti */ +int f(int* a, int b) +{ + return ((*a << b) | (1 << 14)); +} + +int g(int a, int b) +{ + return ((a + b)| (1 << 30)); +} + +int h(int a, int b) +{ + return ((a + b)| (1ULL << 33)); +} + +/* { dg-final { scan-assembler-times "addw\t" 2 } } */ +/* { dg-final { scan-assembler-times "sllw\t" 1 } } */ +/* { dg-final { scan-assembler-times "bseti\t" 2 } } */ +/* { dg-final { scan-assembler-not "sext.w\t" } } */ +