aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorFei Gao <gaofei@eswincomputing.com>2023-11-28 02:32:24 +0000
committerFei Gao <gaofei@eswincomputing.com>2023-12-04 06:55:47 +0000
commitfc98a41c8def1cab4f9b8359be84e8623eab88e2 (patch)
tree8eaf60dfa1578c71be3bbf283f1714098f29f043 /gcc
parentba94969bad24d57895b02cc2d4663462f8fb5bc5 (diff)
downloadgcc-fc98a41c8def1cab4f9b8359be84e8623eab88e2.zip
gcc-fc98a41c8def1cab4f9b8359be84e8623eab88e2.tar.gz
gcc-fc98a41c8def1cab4f9b8359be84e8623eab88e2.tar.bz2
prefer Zicond primitive semantics to SFB
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.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/config/riscv/riscv.md19
-rw-r--r--gcc/config/riscv/sfb.md37
-rw-r--r--gcc/testsuite/gcc.target/riscv/zicond-sfb-primitiveSemantics.c50
3 files changed, 88 insertions, 18 deletions
diff --git a/gcc/config/riscv/riscv.md b/gcc/config/riscv/riscv.md
index ff52145..96abdfc 100644
--- a/gcc/config/riscv/riscv.md
+++ b/gcc/config/riscv/riscv.md
@@ -2753,24 +2753,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)
@@ -3790,5 +3772,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 0000000..52af4b1
--- /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 0000000..2c60656
--- /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} } } */