public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-6483] RISC-V: Allow const0_rtx operand in max/min
@ 2023-03-05  9:17 Kito Cheng
  0 siblings, 0 replies; only message in thread
From: Kito Cheng @ 2023-03-05  9:17 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:602cfc746e9e0447221896a3d93608c6db3a89e5

commit r13-6483-g602cfc746e9e0447221896a3d93608c6db3a89e5
Author: Lin Sinan <sinan.lin@linux.alibaba.com>
Date:   Sun Mar 5 16:09:50 2023 +0800

    RISC-V: Allow const0_rtx operand in max/min
    
    Optimize cases that use max[u]/min[u] against a zero constant.
    
    E.g., the case int f(int x) { return x >= 0 ? x : 0; }
    the current asm output in rv64gc_zba_zbb
    
     li rtmp,0
     max a0,a0,rtmp
    
    could be optimized into
    
     max a0,a0,zero
    
    gcc/ChangeLog:
            * config/riscv/bitmanip.md: allow 0 constant in max/min
            pattern.
    
    gcc/testsuite/ChangeLog:
            * gcc.target/riscv/zbb-min-max-03.c: New test.

Diff:
---
 gcc/config/riscv/bitmanip.md                    |  4 ++--
 gcc/testsuite/gcc.target/riscv/zbb-min-max-03.c | 10 ++++++++++
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/gcc/config/riscv/bitmanip.md b/gcc/config/riscv/bitmanip.md
index 58a86bd929f..cfdb9eb4689 100644
--- a/gcc/config/riscv/bitmanip.md
+++ b/gcc/config/riscv/bitmanip.md
@@ -363,9 +363,9 @@
 (define_insn "<bitmanip_optab><mode>3"
   [(set (match_operand:X 0 "register_operand" "=r")
         (bitmanip_minmax:X (match_operand:X 1 "register_operand" "r")
-			   (match_operand:X 2 "register_operand" "r")))]
+			   (match_operand:X 2 "reg_or_0_operand" "rJ")))]
   "TARGET_ZBB"
-  "<bitmanip_insn>\t%0,%1,%2"
+  "<bitmanip_insn>\t%0,%1,%z2"
   [(set_attr "type" "bitmanip")])
 
 ;; Optimize the common case of a SImode min/max against a constant
diff --git a/gcc/testsuite/gcc.target/riscv/zbb-min-max-03.c b/gcc/testsuite/gcc.target/riscv/zbb-min-max-03.c
new file mode 100644
index 00000000000..c7de1004048
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/zbb-min-max-03.c
@@ -0,0 +1,10 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv64gc_zba_zbb -mabi=lp64d" } */
+/* { dg-skip-if "" { *-*-* } { "-O0" } } */
+
+int f(int x) {
+ return x >= 0 ? x : 0;
+}
+
+/* { dg-final { scan-assembler-times "max\t" 1 } } */
+/* { dg-final { scan-assembler-not "li\t" } } */

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-03-05  9:17 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-05  9:17 [gcc r13-6483] RISC-V: Allow const0_rtx operand in max/min Kito Cheng

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).