From: Fei Gao <gaofei@eswincomputing.com>
To: gcc-patches@gcc.gnu.org
Cc: kito.cheng@gmail.com, palmer@dabbelt.com, jeffreyalaw@gmail.com,
zengxiao@eswincomputing.com, Fei Gao <gaofei@eswincomputing.com>
Subject: [PATCH 1/4] [RISC-V] prefer Zicond primitive semantics to SFB
Date: Tue, 28 Nov 2023 02:32:24 +0000 [thread overview]
Message-ID: <20231128023227.36200-1-gaofei@eswincomputing.com> (raw)
Move Zicond md files ahead of SFB to recognize Zicond first.
Take the following case for example.
CFLAGS: -mtune=sifive-7-series -march=rv64gc_zicond -mabi=lp64d
long primitiveSemantics_00(long a, long b) { return a == 0 ? 0 : b; }
before patch:
primitiveSemantics_00:
bne a0,zero,1f # movcc
mv a1,zero
1:
mv a0,a1
ret
after patch:
primitiveSemantics_00:
czero.eqz a0,a1,a0
ret
Co-authored-by: Xiao Zeng<zengxiao@eswincomputing.com>
gcc/ChangeLog:
* config/riscv/riscv.md (*mov<GPR:mode><X:mode>cc):move to sfb.md
* config/riscv/sfb.md: New file.
gcc/testsuite/ChangeLog:
* gcc.target/riscv/zicond-sfb-primitiveSemantics.c: New test.
---
gcc/config/riscv/riscv.md | 19 +------
gcc/config/riscv/sfb.md | 37 ++++++++++++++
.../riscv/zicond-sfb-primitiveSemantics.c | 50 +++++++++++++++++++
3 files changed, 88 insertions(+), 18 deletions(-)
create mode 100644 gcc/config/riscv/sfb.md
create mode 100644 gcc/testsuite/gcc.target/riscv/zicond-sfb-primitiveSemantics.c
diff --git a/gcc/config/riscv/riscv.md b/gcc/config/riscv/riscv.md
index 935eeb7fd8e..d020988446f 100644
--- a/gcc/config/riscv/riscv.md
+++ b/gcc/config/riscv/riscv.md
@@ -2711,24 +2711,6 @@
DONE;
})
-;; Patterns for implementations that optimize short forward branches.
-
-(define_insn "*mov<GPR:mode><X:mode>cc"
- [(set (match_operand:GPR 0 "register_operand" "=r,r")
- (if_then_else:GPR
- (match_operator 5 "ordered_comparison_operator"
- [(match_operand:X 1 "register_operand" "r,r")
- (match_operand:X 2 "reg_or_0_operand" "rJ,rJ")])
- (match_operand:GPR 3 "register_operand" "0,0")
- (match_operand:GPR 4 "sfb_alu_operand" "rJ,IL")))]
- "TARGET_SFB_ALU"
- "@
- b%C5\t%1,%z2,1f\t# movcc\;mv\t%0,%z4\n1:
- b%C5\t%1,%z2,1f\t# movcc\;li\t%0,%4\n1:"
- [(set_attr "length" "8")
- (set_attr "type" "sfb_alu")
- (set_attr "mode" "<GPR:MODE>")])
-
;; Used to implement built-in functions.
(define_expand "condjump"
[(set (pc)
@@ -3748,5 +3730,6 @@
(include "generic-ooo.md")
(include "vector.md")
(include "zicond.md")
+(include "sfb.md")
(include "zc.md")
(include "corev.md")
diff --git a/gcc/config/riscv/sfb.md b/gcc/config/riscv/sfb.md
new file mode 100644
index 00000000000..52af4b17d46
--- /dev/null
+++ b/gcc/config/riscv/sfb.md
@@ -0,0 +1,37 @@
+;; Machine description for short forward branches(SFB).
+;; Copyright (C) 2023 Free Software Foundation, Inc.
+
+;; This file is part of GCC.
+
+;; GCC is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation; either version 3, or (at your option)
+;; any later version.
+
+;; GCC is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GCC; see the file COPYING3. If not see
+;; <http://www.gnu.org/licenses/>.
+
+
+;; Patterns for implementations that optimize short forward branches.
+
+(define_insn "*mov<GPR:mode><X:mode>cc"
+ [(set (match_operand:GPR 0 "register_operand" "=r,r")
+ (if_then_else:GPR
+ (match_operator 5 "ordered_comparison_operator"
+ [(match_operand:X 1 "register_operand" "r,r")
+ (match_operand:X 2 "reg_or_0_operand" "rJ,rJ")])
+ (match_operand:GPR 3 "register_operand" "0,0")
+ (match_operand:GPR 4 "sfb_alu_operand" "rJ,IL")))]
+ "TARGET_SFB_ALU"
+ "@
+ b%C5\t%1,%z2,1f\t# movcc\;mv\t%0,%z4\n1:
+ b%C5\t%1,%z2,1f\t# movcc\;li\t%0,%4\n1:"
+ [(set_attr "length" "8")
+ (set_attr "type" "sfb_alu")
+ (set_attr "mode" "<GPR:MODE>")])
diff --git a/gcc/testsuite/gcc.target/riscv/zicond-sfb-primitiveSemantics.c b/gcc/testsuite/gcc.target/riscv/zicond-sfb-primitiveSemantics.c
new file mode 100644
index 00000000000..2c60656d5eb
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/zicond-sfb-primitiveSemantics.c
@@ -0,0 +1,50 @@
+/* { dg-do compile } */
+/* { dg-options "-mtune=sifive-7-series -march=rv64gc_zicond -mabi=lp64d" { target { rv64 } } } */
+/* { dg-options "-mtune=sifive-7-series -march=rv32gc_zicond -mabi=ilp32f" { target { rv32 } } } */
+/* { dg-skip-if "" { *-*-* } {"-O0" "-Og"} } */
+
+long primitiveSemantics_00(long a, long b) { return a == 0 ? 0 : b; }
+
+long primitiveSemantics_01(long a, long b) { return a != 0 ? 0 : b; }
+
+long primitiveSemantics_02(long a, long b) { return a == 0 ? b : 0; }
+
+long primitiveSemantics_03(long a, long b) { return a != 0 ? b : 0; }
+
+long primitiveSemantics_04(long a, long b) {
+ if (a)
+ b = 0;
+ return b;
+}
+
+long primitiveSemantics_05(long a, long b) {
+ if (!a)
+ b = 0;
+ return b;
+}
+
+int primitiveSemantics_06(int a, int b) { return a == 0 ? 0 : b; }
+
+int primitiveSemantics_07(int a, int b) { return a != 0 ? 0 : b; }
+
+int primitiveSemantics_08(int a, int b) { return a == 0 ? b : 0; }
+
+int primitiveSemantics_09(int a, int b) { return a != 0 ? b : 0; }
+
+int primitiveSemantics_10(int a, int b) {
+ if (a)
+ b = 0;
+ return b;
+}
+
+int primitiveSemantics_11(int a, int b) {
+ if (!a)
+ b = 0;
+ return b;
+}
+
+/* { dg-final { scan-assembler-times {\mczero\.eqz\M} 6 } } */
+/* { dg-final { scan-assembler-times {\mczero\.nez\M} 6 } } */
+/* { dg-final { scan-assembler-not {\mbeq\M} } } */
+/* { dg-final { scan-assembler-not {\mbne\M} } } */
+/* { dg-final { scan-assembler-not {\mmovcc\M} } } */
--
2.17.1
next reply other threads:[~2023-11-28 2:33 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-28 2:32 Fei Gao [this message]
2023-11-28 2:32 ` [PATCH 2/4] [ifcvt] optimize x=c ? (y op z) : y by RISC-V Zicond like insns Fei Gao
2023-11-29 5:26 ` Jeff Law
2023-11-29 11:09 ` Fei Gao
2023-12-05 8:36 ` Fei Gao
2023-11-28 2:32 ` [PATCH 3/4] [ifcvt] optimize x=c ? (y op const_int) " Fei Gao
2023-11-28 2:32 ` [PATCH 4/4] [V2] [ifcvt] prefer SFB to Zicond for x=c ? (y op CONST) : y Fei Gao
2023-11-28 5:00 ` Jeff Law
2023-11-28 3:09 ` [PATCH 1/4] [RISC-V] prefer Zicond primitive semantics to SFB Kito Cheng
2023-11-28 5:03 ` Jeff Law
2023-12-04 7:01 ` Fei Gao
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231128023227.36200-1-gaofei@eswincomputing.com \
--to=gaofei@eswincomputing.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=jeffreyalaw@gmail.com \
--cc=kito.cheng@gmail.com \
--cc=palmer@dabbelt.com \
--cc=zengxiao@eswincomputing.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).