From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1923) id 8244D3896C1C; Tue, 15 Nov 2022 14:00:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8244D3896C1C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1668520837; bh=UUqtIORvPzLB5QzxZ2i7Sy5S89oejAQeWyRSdNq4P4w=; h=From:To:Subject:Date:From; b=KKJ6Tbmj+ga3Pg0+iwjTsO5SUcWLL7LNUS+zzvsIu2Ww//fPglhwYMsUSU2ysyL4Q EL6yxnRnS/hqBC/H9kzP1KsgVmmo8K2kQsFbpRp3XlEaXlmRXf6k4Xhzbuo7NNz3Ik 9Ns4ENMmZrOPn7D1F8ZAR1FVaVecjzjrTwGuCouY= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Philipp Tomsich To: gcc-cvs@gcc.gnu.org Subject: [gcc(refs/vendors/vrull/heads/for-upstream)] RISC-V: allow bseti on SImode without sign-extension X-Act-Checkin: gcc X-Git-Author: Philipp Tomsich X-Git-Refname: refs/vendors/vrull/heads/for-upstream X-Git-Oldrev: 7debc3f1b5d5567d4adb6eb8a2c3f96f909c5fd8 X-Git-Newrev: 46a2a5493892b041a45acd47a19f41d947bc0e87 Message-Id: <20221115140037.8244D3896C1C@sourceware.org> Date: Tue, 15 Nov 2022 14:00:37 +0000 (GMT) List-Id: https://gcc.gnu.org/g:46a2a5493892b041a45acd47a19f41d947bc0e87 commit 46a2a5493892b041a45acd47a19f41d947bc0e87 Author: Philipp Tomsich Date: Mon Oct 10 22:24:02 2022 +0200 RISC-V: allow bseti on SImode without sign-extension 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. Series-to: gcc-patches@gcc.gnu.org Series-cc: Palmer Dabbelt Series-cc: Vineet Gupta Series-cc: Christoph Muellner Series-cc: Kito Cheng Series-cc: Jeff Law Diff: --- gcc/config/riscv/bitmanip.md | 12 ++++++++++++ gcc/testsuite/gcc.target/riscv/zbs-bseti-02.c | 25 +++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/gcc/config/riscv/bitmanip.md b/gcc/config/riscv/bitmanip.md index d9e6dd5eb3f..a545cd3f82b 100644 --- a/gcc/config/riscv/bitmanip.md +++ b/gcc/config/riscv/bitmanip.md @@ -416,6 +416,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" } } */ +