Re: [PATCH 1/1] riscv: thead: Fix ICE when enable XTheadMemPair ISA extension.

2023-07-12 Thread Xianmiao Qu via Gcc-patches
On Tue, Jul 11, 2023 at 06:02:18PM +0200, Christoph Müllner wrote:
> Hi Kito,
> 
> I take some of the blame because I have sent a series
> that consisted of fixes followed by new features.
> 
> You have ack'ed patches 1-9 from the series.
> The last two patches (for XTheadMemIdx and XTheadFMemIdx) were
> later reviewed by Jeff and need a bit rework and more testing.
> 
> If it helps, you can find patches 1-9 rebased and retested here:
>   https://github.com/cmuellner/gcc/tree/riscv-thead-improvements
> 
> I have also sent out a fix for two failing T-Head tests earlier today:
>   https://gcc.gnu.org/pipermail/gcc-patches/2023-July/624049.html
> It would be great if you could look at that and push that as well, if it is 
> ok.
> 
> Thanks,
> Christoph
> 
> 
> 
> On Tue, Jul 11, 2023 at 5:51 PM Kito Cheng  wrote:
> >
> > Hi Christoph:
> >
> > Ooops, I thought Philipp will push those patches, does here any other
> > patches got approved but not committed? I can help to push those
> > patches tomorrow.
> >
> > On Tue, Jul 11, 2023 at 11:42 PM Christoph Müllner
> >  wrote:
> > >
> > > Hi Cooper,
> > >
> > > I addressed this in April this year.
> > > It even got an "ok", but nobody pushed it:
> > >   https://gcc.gnu.org/pipermail/gcc-patches/2023-April/616972.html
> > >
> > > BR
> > > Christoph
> > >

Hi Christoph and Kito,

That's great that this bug has been resolved. If you merge this patch,
it would be best to also merge it to the gcc-13 branch.


Thanks,
Cooper


[PATCH 1/1] riscv: thead: Fix ICE when enable XTheadMemPair ISA extension.

2023-07-11 Thread Xianmiao Qu via Gcc-patches
The frame related load/store instructions should not been
scheduled bewteen echo other, and the REG_FRAME_RELATED_EXPR
expression note should should be added to those instructions
to prevent this.
This bug cause ICE during GCC bootstap, and it will also ICE
in the simplified case mempair-4.c, compilation fails with:
during RTL pass: dwarf2
theadmempair-4.c:20:1: internal compiler error: in 
dwarf2out_frame_debug_cfa_offset, at dwarf2cfi.cc:1376
0xa8c017 dwarf2out_frame_debug_cfa_offset
../../../gcc/gcc/dwarf2cfi.cc:1376
0xa8c017 dwarf2out_frame_debug
../../../gcc/gcc/dwarf2cfi.cc:2285
0xa8c017 scan_insn_after
../../../gcc/gcc/dwarf2cfi.cc:2726
0xa8cc97 scan_trace
../../../gcc/gcc/dwarf2cfi.cc:2893
0xa8d84d create_cfi_notes
../../../gcc/gcc/dwarf2cfi.cc:2933
0xa8d84d execute_dwarf2_frame
../../../gcc/gcc/dwarf2cfi.cc:3309
0xa8d84d execute
../../../gcc/gcc/dwarf2cfi.cc:3799

gcc/ChangeLog:

* config/riscv/thead.cc (th_mempair_save_regs): Add
REG_FRAME_RELATED_EXPR note for mempair instuctions.

gcc/testsuite/ChangeLog:
* gcc.target/riscv/xtheadmempair-4.c: New test.
---
 gcc/config/riscv/thead.cc |  6 +++--
 .../gcc.target/riscv/xtheadmempair-4.c| 26 +++
 2 files changed, 30 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/riscv/xtheadmempair-4.c

diff --git a/gcc/config/riscv/thead.cc b/gcc/config/riscv/thead.cc
index 75203805310..2df709226f9 100644
--- a/gcc/config/riscv/thead.cc
+++ b/gcc/config/riscv/thead.cc
@@ -366,10 +366,12 @@ th_mempair_save_regs (rtx operands[4])
 {
   rtx set1 = gen_rtx_SET (operands[0], operands[1]);
   rtx set2 = gen_rtx_SET (operands[2], operands[3]);
+  rtx dwarf = gen_rtx_SEQUENCE (VOIDmode, rtvec_alloc (2));
   rtx insn = emit_insn (gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, set1, 
set2)));
   RTX_FRAME_RELATED_P (insn) = 1;
-  add_reg_note (insn, REG_CFA_OFFSET, copy_rtx (set1));
-  add_reg_note (insn, REG_CFA_OFFSET, copy_rtx (set2));
+  XVECEXP (dwarf, 0, 0) = copy_rtx (set1);
+  XVECEXP (dwarf, 0, 1) = copy_rtx (set2);
+  add_reg_note (insn, REG_FRAME_RELATED_EXPR, dwarf);
 }
 
 /* Similar like riscv_restore_reg, but restores two registers from memory
diff --git a/gcc/testsuite/gcc.target/riscv/xtheadmempair-4.c 
b/gcc/testsuite/gcc.target/riscv/xtheadmempair-4.c
new file mode 100644
index 000..d653f056ef4
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/xtheadmempair-4.c
@@ -0,0 +1,26 @@
+/* { dg-do compile } */
+/* { dg-skip-if "" { *-*-* } { "-O0" "-O1" "-g" "-Oz" "-Os" "-flto" } } */
+/* { dg-options "-march=rv64gc_xtheadmempair -O2 -g -mtune=thead-c906" { 
target { rv64 } } } */
+/* { dg-options "-march=rv32gc_xtheadmempair -O2 -g -mtune=thead-c906" { 
target { rv32 } } } */
+
+void a();
+void b(char *);
+void m_fn1(int);
+int e;
+
+int foo(int ee, int f, int g) {
+  char *h = (char *)__builtin_alloca(1);
+  b(h);
+  b("");
+  int i = ee;
+  e = g;
+  m_fn1(f);
+  a();
+  e = i;
+}
+
+/* { dg-final { scan-assembler-times "th.ldd\t" 3 { target { rv64 } } } } */
+/* { dg-final { scan-assembler-times "th.sdd\t" 3 { target { rv64 } } } } */
+
+/* { dg-final { scan-assembler-times "th.lwd\t" 3 { target { rv32 } } } } */
+/* { dg-final { scan-assembler-times "th.swd\t" 3 { target { rv32 } } } } */
-- 
2.17.1



[PATCH] testsuite: Fix pr108574-3.c failed in arch where sign defaults to unsigned.

2023-01-30 Thread Xianmiao Qu via Gcc-patches
In the architecture where sign defaults to unsigned, the 'f' will be zero
extended to int type in the expression 'd = ~(f & ~2880764155)', then the
'd' will become -1 wich cause the case to fail.
So it's ok for the architectures where sign defaults to signed like x86,
but failed for the architectures where sign defaults to unsigned like arm
and csky. Change char to signed char to avoid this problem.

gcc/testsuite:
* gcc.dg/torture/pr108574-3.c (b, f): Change type from char to
signed char.
---
 gcc/testsuite/gcc.dg/torture/pr108574-3.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/testsuite/gcc.dg/torture/pr108574-3.c 
b/gcc/testsuite/gcc.dg/torture/pr108574-3.c
index 3c9146e31ac..b4d5dae9f80 100644
--- a/gcc/testsuite/gcc.dg/torture/pr108574-3.c
+++ b/gcc/testsuite/gcc.dg/torture/pr108574-3.c
@@ -1,7 +1,7 @@
 /* { dg-do run } */
 
 int a = 3557301289, d;
-char b, f;
+signed char b, f;
 unsigned short c = 241;
 short e, g;
 static void h() {
-- 
2.32.1 (Apple Git-133)



[COMMITTED] C-SKY: Fix wrong sysroot suffix when disable multilib.

2023-01-24 Thread Xianmiao Qu via Gcc-patches
The SYSROOT_SUFFIX_SPEC works even when multilib is disabled.
So when build no-multilib glibc toolchain and the options are
not same as MULTILIB_DEFAULTS, the sysroot will specify wrong
because the libc will not be installed as such.
This bug causes glibc regression test error:
  https://sourceware.org/pipermail/libc-testresults/2023q1/010706.html
The error is:
  
/scratch/jmyers/glibc-bot/install/compilers/csky-linux-gnuabiv2/csky-glibc-linux-gnuabiv2/bin/ld:
 cannot find -lc: No such file or directory

gcc/
* config.gcc(csky-*-linux*): Define CSKY_ENABLE_MULTILIB
and only include 'csky/t-csky-linux' when enable multilib.
* config/csky/csky-linux-elf.h(SYSROOT_SUFFIX_SPEC): Don't
define it when disable multilib.
---
 gcc/config.gcc   | 7 ++-
 gcc/config/csky/csky-linux-elf.h | 3 +++
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/gcc/config.gcc b/gcc/config.gcc
index d828223c16d..89f56047cfe 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -1642,7 +1642,12 @@ csky-*-*)
;;
csky-*-linux*)
tm_file="elfos.h gnu-user.h linux.h glibc-stdint.h ${tm_file} 
csky/csky-linux-elf.h"
-   tmake_file="${tmake_file} csky/t-csky csky/t-csky-linux"
+   tmake_file="${tmake_file} csky/t-csky"
+
+   if test "x${enable_multilib}" = xyes ; then
+   tm_defines="$tm_defines CSKY_ENABLE_MULTILIB"
+   tmake_file="${tmake_file} csky/t-csky-linux"
+   fi
 
case ${target} in
csky-*-linux-gnu*)
diff --git a/gcc/config/csky/csky-linux-elf.h b/gcc/config/csky/csky-linux-elf.h
index 3f67af64c15..117c2a12c74 100644
--- a/gcc/config/csky/csky-linux-elf.h
+++ b/gcc/config/csky/csky-linux-elf.h
@@ -65,6 +65,8 @@
 
 #define GLIBC_DYNAMIC_LINKER 
"/lib/ld-linux-cskyv2%{mfloat-abi=hard:-hf}%{mbig-endian:-be}.so.1"
 
+#ifdef CSKY_ENABLE_MULTILIB
+#undef SYSROOT_SUFFIX_SPEC
 #define SYSROOT_SUFFIX_SPEC\
   "%{mbig-endian:/big}"\
   "%{mcpu=ck807*:/ck807}"  \
@@ -72,6 +74,7 @@
   "%{mcpu=ck800*:/ck800}"  \
   "%{mfloat-abi=softfp:/soft-fp}"  \
   "%{mfloat-abi=hard:/hard-fp}"
+#endif
 
 #define LINUX_TARGET_LINK_SPEC "%{h*} %{version:-v}\
%{b}\
-- 
2.32.1 (Apple Git-133)



[COMMITTED] C-SKY: Support --with-float=softfp in configuration.

2023-01-14 Thread Xianmiao Qu via Gcc-patches
Missed it before, it needs to be used when compiling non-multilib.

gcc/
* config.gcc (csky-*-*): Support --with-float=softfp.
---
 gcc/config.gcc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/config.gcc b/gcc/config.gcc
index c4633e869ac..f89a071b495 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -1616,7 +1616,7 @@ csky-*-*)
fi
if test x${with_float} != x; then
case ${with_float} in
-   soft | hard) ;;
+   soft | hard | softfp) ;;
*) echo
"Unknown floating point type used in 
--with-float=$with_float"
exit 1
-- 
2.32.1 (Apple Git-133)



[committed] C-SKY: Fix skip codition for testcase ldbs.c

2023-01-13 Thread Xianmiao Qu via Gcc-patches
gcc/testsuite/
* gcc.target/csky/ldbs.c : Fix exclude-opts, should not
be "*".
---
 gcc/testsuite/gcc.target/csky/ldbs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/testsuite/gcc.target/csky/ldbs.c 
b/gcc/testsuite/gcc.target/csky/ldbs.c
index 27a02543413..7fce1aa3736 100644
--- a/gcc/testsuite/gcc.target/csky/ldbs.c
+++ b/gcc/testsuite/gcc.target/csky/ldbs.c
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-skip-if "" { *-*-* } { "-mcpu=ck801" "-march=ck801" } { "*" } } */
+/* { dg-skip-if "ck801 does not support ld.bs" { csky-*-* } { "-mcpu=ck801" 
"-march=ck801" } { "" } } */
 /* { dg-csky-options "-O1" } */
 
 int foo (signed char *pb)
-- 
2.32.1 (Apple Git-133)



[committed] C-SKY: Add missing builtin defines for soft float abi.

2023-01-13 Thread Xianmiao Qu via Gcc-patches
The builtin defines for soft float abi are:
'__csky_soft_float_abi__' and '__CSKY_SOFT_FLOAT_ABI__'.

gcc/
* config/csky/csky.cc (csky_cpu_cpp_builtins): Add builtin
defines for soft float abi.
---
 gcc/config/csky/csky.cc | 5 +
 1 file changed, 5 insertions(+)

diff --git a/gcc/config/csky/csky.cc b/gcc/config/csky/csky.cc
index b0e50cfef3e..ddc6954dad1 100644
--- a/gcc/config/csky/csky.cc
+++ b/gcc/config/csky/csky.cc
@@ -396,6 +396,11 @@ csky_cpu_cpp_builtins (cpp_reader *pfile)
  builtin_define ("__csky_hard_float_abi__");
  builtin_define ("__CSKY_HARD_FLOAT_ABI__");
}
+  else
+   {
+ builtin_define ("__csky_soft_float_abi__");
+ builtin_define ("__CSKY_SOFT_FLOAT_ABI__");
+   }
   if (TARGET_SINGLE_FPU)
{
  builtin_define ("__csky_hard_float_fpu_sf__");
-- 
2.32.1 (Apple Git-133)



[committed] C-SKY: Fix float abi option in MULTILIB_DEFAULTS.

2023-01-13 Thread Xianmiao Qu via Gcc-patches
The msoft-float is alias of mfloat-abi=soft, use mfloat-abi=soft
in MULTILIB_DEFAULTS to correspond to the option in MULTILIB_OPTIONS,
otherwise it will find the wrong path.

gcc/
* config/csky/csky.h (MULTILIB_DEFAULTS): Fix float abi option.
---
 gcc/config/csky/csky.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/config/csky/csky.h b/gcc/config/csky/csky.h
index d21a57a8bb2..a9dc60cecc5 100644
--- a/gcc/config/csky/csky.h
+++ b/gcc/config/csky/csky.h
@@ -952,7 +952,7 @@ while (0)
specially when using MULTILIB_OPTIONS.  */
 #undef MULTILIB_DEFAULTS
 #define MULTILIB_DEFAULTS\
-{"mlittle-endian", "mcpu=ck810f", "msoft-float"}
+{"mlittle-endian", "mcpu=ck810f", "mfloat-abi=soft"}
 
 /* Support for a compile-time default CPU, et cetera.  The rules are:
--with-arch is ignored if -march or -mcpu are specified.
-- 
2.32.1 (Apple Git-133)



[committed] C-SKY: Define SYSROOT_SUFFIX_SPEC.

2023-01-13 Thread Xianmiao Qu via Gcc-patches
The earlier patch
  https://gcc.gnu.org/pipermail/gcc-patches/2021-July/575418.html
refine the way to generate sysroot suffix, but it can't find the
right path for all CPUs. The SYSROOT_SUFFIX_SPEC should be defined
to fix it.

gcc/
* config/csky/csky-linux-elf.h (SYSROOT_SUFFIX_SPEC): New.
---
 gcc/config/csky/csky-linux-elf.h | 8 
 1 file changed, 8 insertions(+)

diff --git a/gcc/config/csky/csky-linux-elf.h b/gcc/config/csky/csky-linux-elf.h
index 677c201b218..3f67af64c15 100644
--- a/gcc/config/csky/csky-linux-elf.h
+++ b/gcc/config/csky/csky-linux-elf.h
@@ -65,6 +65,14 @@
 
 #define GLIBC_DYNAMIC_LINKER 
"/lib/ld-linux-cskyv2%{mfloat-abi=hard:-hf}%{mbig-endian:-be}.so.1"
 
+#define SYSROOT_SUFFIX_SPEC\
+  "%{mbig-endian:/big}"\
+  "%{mcpu=ck807*:/ck807}"  \
+  "%{mcpu=ck860*:/ck860}"  \
+  "%{mcpu=ck800*:/ck800}"  \
+  "%{mfloat-abi=softfp:/soft-fp}"  \
+  "%{mfloat-abi=hard:/hard-fp}"
+
 #define LINUX_TARGET_LINK_SPEC "%{h*} %{version:-v}\
%{b}\
%{static:-Bstatic}  \
-- 
2.32.1 (Apple Git-133)



[committed] C-SKY: Fix patterns' condition for ck802 smart mode.

2023-01-13 Thread Xianmiao Qu via Gcc-patches
Ck802 smart mode should not be treated as ck801.
It do only allocate r0-r8 registers like ck801,
but support 32-bits intructions.
This bug will cause ICE when compiler pr43164.c for ck802 big-endian,
/src/gcc/gcc/testsuite/gcc.c-torture/compile/pr43164.c:16:1: error: insn does 
not satisfy its constraints:
(insn 48 28 30 2 (set (reg:SI 0 a0 [230])
(ior:SI (reg:SI 2 a2 [222])
(ashift:SI (const_int 1 [0x1])
(const_int 24 [0x18] 
"/src/gcc/gcc/testsuite/gcc.c-torture/compile/pr43164.c":15:10 224 {smart_bseti}
 (expr_list:REG_DEAD (reg:SI 2 a2 [222])
(nil)))

gcc/
* config/csky/csky.md (smart_bseti): Change condition to 
CSKY_ISA_FEATURE (E1).
(smart_bclri): Likewise.
(fast_bseti): Change condition to CSKY_ISA_FEATURE (E2).
(fast_bclri): Likewise.
(fast_cmpnesi_i): Likewise.
(*fast_cmpltsi_i): Likewise.
(*fast_cmpgeusi_i): Likewise.
---
 gcc/config/csky/csky.md | 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/gcc/config/csky/csky.md b/gcc/config/csky/csky.md
index d7bafdbebb9..8fb832f9e75 100644
--- a/gcc/config/csky/csky.md
+++ b/gcc/config/csky/csky.md
@@ -573,7 +573,7 @@
(ior:SI (match_operand:SI 1 "register_operand"  "0")
(ashift:SI (const_int 1)
   (match_operand:SI 2 "csky_literal_K_operand" "K"]
-  "TARGET_MINI_REGISTERS"
+  "CSKY_ISA_FEATURE (E1)"
   "bseti\t%0, %2"
   [(set_attr "length" "2")])
 
@@ -582,7 +582,7 @@
(ior:SI (match_operand:SI 1 "register_operand"  "0,r")
(ashift:SI (const_int 1)
   (match_operand:SI 2 "csky_literal_K_operand" 
"K,K"]
-  "!TARGET_MINI_REGISTERS"
+  "CSKY_ISA_FEATURE (E2)"
   "bseti\t%0, %1, %2"
   [(set_attr "length" "2,4")])
 
@@ -599,7 +599,7 @@
(and:SI (match_operand:SI 1 "register_operand"  "0")
(not:SI (ashift:SI (const_int 1)
   (match_operand:SI 2 "csky_literal_K_operand" 
"K")]
-  "TARGET_MINI_REGISTERS"
+  "CSKY_ISA_FEATURE (E1)"
   "bclri\t%0, %2"
   [(set_attr "length" "2")])
 
@@ -608,7 +608,7 @@
(and:SI (match_operand:SI 1 "register_operand"  "0,r")
(not:SI (ashift:SI (const_int 1)
   (match_operand:SI 2 "csky_literal_K_operand" 
"K,K")]
-  "!TARGET_MINI_REGISTERS"
+  "CSKY_ISA_FEATURE (E2)"
   "bclri\t%0, %1, %2"
   [(set_attr "length" "2,4")])
 
@@ -3014,7 +3014,7 @@
   [(set (reg:CC CSKY_CC_REGNUM)
(ne:CC (match_operand:SI 0 "register_operand"   "r")
   (match_operand:SI 1 "csky_literal_I_operand" "I")))]
-  "!TARGET_MINI_REGISTERS && CSKY_ISA_FEATURE (E2)"
+  "CSKY_ISA_FEATURE (E2)"
   "cmpnei\t%0, %1"
   [(set_attr "type" "cmp")]
 )
@@ -3056,7 +3056,7 @@
   [(set (reg:CC CSKY_CC_REGNUM)
(lt:CC (match_operand:SI 0 "register_operand""a,r")
   (match_operand:SI 1 "csky_literal_Uk_operand" "J,Uk")))]
-  "!TARGET_MINI_REGISTERS && CSKY_ISA_FEATURE (E2)"
+  "CSKY_ISA_FEATURE (E2)"
   "cmplti\t%0, %1"
   [(set_attr "length" "2,4")
(set_attr "type" "cmp")]
@@ -3149,7 +3149,7 @@
   [(set (reg:CC CSKY_CC_REGNUM)
(geu:CC (match_operand:SI 0 "register_operand""a,r")
(match_operand:SI 1 "csky_literal_Uk_operand" "J,Uk")))]
-  "!TARGET_MINI_REGISTERS && CSKY_ISA_FEATURE (E2)"
+  "CSKY_ISA_FEATURE (E2)"
   "cmphsi\t%0, %1"
   [(set_attr "length" "2,4")
(set_attr "type" "cmp")]
-- 
2.32.1 (Apple Git-133)



[committed] C-SKY: Skip other CPUs if the testcases are only for ck801.

2023-01-13 Thread Xianmiao Qu via Gcc-patches
Refine some testcases for ck801, if the testcase is only for
ck801, add the filename prefix "ck801-", and add dg-skip-if
to skip other CPUs.

gcc/testsuite/
* gcc.target/csky/and3a.c: Rename to ...
* gcc.target/csky/ck801-and.c: ... this.
* gcc.target/csky/constpool-3.c: Rename to ...
* gcc.target/csky/constpool-2.c: ... this, Rename to ...
* gcc.target/csky/constpool-1.c: ... this, Rename to ...
* gcc.target/csky/ck801-constpool.c: ... this, and skip
if the CPU is not ck801.
* gcc.target/csky/ck801-branch.c: Skip if the CPU is not ck801.
---
 .../gcc.target/csky/{and3a.c => ck801-and.c}|  3 ++-
 gcc/testsuite/gcc.target/csky/ck801-branch.c|  3 ++-
 gcc/testsuite/gcc.target/csky/ck801-constpool.c | 17 +
 gcc/testsuite/gcc.target/csky/constpool-1.c |  7 +++
 gcc/testsuite/gcc.target/csky/constpool-2.c |  8 
 gcc/testsuite/gcc.target/csky/constpool-3.c | 15 ---
 6 files changed, 28 insertions(+), 25 deletions(-)
 rename gcc/testsuite/gcc.target/csky/{and3a.c => ck801-and.c} (64%)
 create mode 100644 gcc/testsuite/gcc.target/csky/ck801-constpool.c
 delete mode 100644 gcc/testsuite/gcc.target/csky/constpool-3.c

diff --git a/gcc/testsuite/gcc.target/csky/and3a.c 
b/gcc/testsuite/gcc.target/csky/ck801-and.c
similarity index 64%
rename from gcc/testsuite/gcc.target/csky/and3a.c
rename to gcc/testsuite/gcc.target/csky/ck801-and.c
index 3d706f6eb58..7c79879278d 100644
--- a/gcc/testsuite/gcc.target/csky/and3a.c
+++ b/gcc/testsuite/gcc.target/csky/ck801-and.c
@@ -1,5 +1,6 @@
 /* { dg-do compile } */
-/* { dg-csky-options "-mcpu=ck801 -O1" } */
+/* { dg-skip-if  "test is specific to ck801"  { csky-*-* }  { "*" }  { 
"-mcpu=ck801" }  }  */
+/* { dg-csky-options "-O1" } */
 
 /* Test special code generation patterns for bit operators.  */
 
diff --git a/gcc/testsuite/gcc.target/csky/ck801-branch.c 
b/gcc/testsuite/gcc.target/csky/ck801-branch.c
index 95e69624475..e4dafb37e89 100644
--- a/gcc/testsuite/gcc.target/csky/ck801-branch.c
+++ b/gcc/testsuite/gcc.target/csky/ck801-branch.c
@@ -1,5 +1,6 @@
 /* { dg-do compile } */
-/* { dg-csky-options "-mcpu=ck801 -O1 -fno-reorder-blocks" } */
+/* { dg-skip-if  "test is specific to ck801"  { csky-*-* }  { "*" }  { 
"-mcpu=ck801" }  }  */
+/* { dg-csky-options "-O1 -fno-reorder-blocks" } */
 
 /* Test branch generation on CK801, which cannot rely on assembler
branch relaxation because long branches clobber lr.  */
diff --git a/gcc/testsuite/gcc.target/csky/ck801-constpool.c 
b/gcc/testsuite/gcc.target/csky/ck801-constpool.c
new file mode 100644
index 000..5c92f39d0ab
--- /dev/null
+++ b/gcc/testsuite/gcc.target/csky/ck801-constpool.c
@@ -0,0 +1,17 @@
+/* { dg-do compile } */
+/* { dg-skip-if  "test is specific to ck801"  { csky-*-* }  { "*" }  { 
"-mcpu=ck801" }  }  */
+/* { dg-csky-options "-O1" } */
+
+/* Make sure that constant pools are emitted by the compiler for ck801.
+   If this is deferred to the assembler, the compiler will compute
+   incorrect branch offsets.  */
+
+void f (unsigned int *u, long long int *l, float *f, double *d)
+{
+  *u = 0xdeadbeef;
+  *l = 0xcafef00dc0ffeeULL;
+  *f = 3.14159F;
+  *d = 2.718281828459;
+}
+
+/* { dg-final { scan-assembler-times "\\.long" 6 } } */
diff --git a/gcc/testsuite/gcc.target/csky/constpool-1.c 
b/gcc/testsuite/gcc.target/csky/constpool-1.c
index 5c7cfdc73bd..d654420bc3f 100644
--- a/gcc/testsuite/gcc.target/csky/constpool-1.c
+++ b/gcc/testsuite/gcc.target/csky/constpool-1.c
@@ -1,9 +1,8 @@
 /* { dg-do compile } */
-/* { dg-csky-options "-mcpu=ck801 -O1" } */
+/* { dg-csky-options "-mcpu=ck810f -O1 -mconstpool" } */
 
-/* Make sure that constant pools are emitted by the compiler for ck801.
-   If this is deferred to the assembler, the compiler will compute
-   incorrect branch offsets.  */
+/* Make sure that constant pools are emitted by the compiler when
+   -mconstpool is provided.  */
 
 void f (unsigned int *u, long long int *l, float *f, double *d)
 {
diff --git a/gcc/testsuite/gcc.target/csky/constpool-2.c 
b/gcc/testsuite/gcc.target/csky/constpool-2.c
index d654420bc3f..e3a6e095f5b 100644
--- a/gcc/testsuite/gcc.target/csky/constpool-2.c
+++ b/gcc/testsuite/gcc.target/csky/constpool-2.c
@@ -1,8 +1,8 @@
 /* { dg-do compile } */
-/* { dg-csky-options "-mcpu=ck810f -O1 -mconstpool" } */
+/* { dg-csky-options "-mcpu=ck810f -O1 -mno-constpool" } */
 
-/* Make sure that constant pools are emitted by the compiler when
-   -mconstpool is provided.  */
+/* Make sure that constant pools are not emitted by the compiler when
+   -mno-constpool is provided.  */
 
 void f (unsigned int *u, long long int *l, float *f, double *d)
 {
@@ -12,4 +12,4 @@ void f (unsigned int *u, long long int *l, float *f, double 
*d)
   *d = 2.718281828459;
 }
 
-/* { dg-final { scan-assembler-times "\\.long" 6 } } */
+/* { dg-final { scan-assembler-not "\\.long" } } */
diff --git 

[committed] C-SKY: Add conditions for ceil etc patterns.

2023-01-13 Thread Xianmiao Qu via Gcc-patches
The ceil etc functions can be only inlined as instruction when
they can raise the "inexact" exception. Without the adding
conditions, it will cause the "gcc.dg/torture/builtin-fp-int-inexact-c2x.c"
etc cases fails.

gcc/
* config/csky/csky_insn_fpuv3.md (lsi2): 
Test
flag_fp_int_builtin_inexact || !flag_trapping_math.
(2): Likewise.
---
 gcc/config/csky/csky_insn_fpuv3.md | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/gcc/config/csky/csky_insn_fpuv3.md 
b/gcc/config/csky/csky_insn_fpuv3.md
index 628bae597ba..7f8f459621e 100644
--- a/gcc/config/csky/csky_insn_fpuv3.md
+++ b/gcc/config/csky/csky_insn_fpuv3.md
@@ -476,14 +476,16 @@
   [(set (match_operand:SI 0 "register_operand" "=v")
(FIX_SU:SI (unspec:F3ANY [(match_operand:F3ANY 1 "register_operand" 
"0")]
   FRM)))]
-  "CSKY_ISA_FEATURE(fpv3_)"
+  "CSKY_ISA_FEATURE(fpv3_)
+   && (flag_fp_int_builtin_inexact || !flag_trapping_math)"
   "fftoi.f.32\t%0, %1"
 )
 
 (define_insn "2"
   [(set (match_operand:F3ANY 0 "register_operand" "=v")
(unspec:F3ANY [(match_operand:F3ANY 1 "register_operand" "0")] FRMF))]
-  "CSKY_ISA_FEATURE(fpv3_)"
+  "CSKY_ISA_FEATURE(fpv3_)
+   && (flag_fp_int_builtin_inexact || !flag_trapping_math)"
   "fftofi.f\t%0, %1"
 )
 
-- 
2.32.1 (Apple Git-133)



[COMMITTED] C-SKY: Fix expanding of float LE comparing with zero for fpuv3.

2022-09-07 Thread Xianmiao Qu via Gcc-patches
The original code will cause the warning:
/usr/lib/gcc-snapshot/bin/g++  -fno-PIE -c   -g -O2   -DIN_GCC  
-DCROSS_DIRECTORY_STRUCTURE   -fno-exceptions -fno-rtti 
-fasynchronous-unwind-tables -W -Wall -Wno-narrowing -Wwrite-strings 
-Wcast-qual -Wmissing-format-attribute -Woverloaded-virtual -pedantic 
-Wno-long-long -Wno-variadic-macros -Wno-overlength-strings -Werror -fno-common 
 -DHAVE_CONFIG_H -I. -I. -I../../gcc/gcc -I../../gcc/gcc/. 
-I../../gcc/gcc/../include -I../../gcc/gcc/../libcpp/include 
-I../../gcc/gcc/../libcody  -I../../gcc/gcc/../libdecnumber 
-I../../gcc/gcc/../libdecnumber/dpd -I../libdecnumber 
-I../../gcc/gcc/../libbacktrace   -o csky.o -MT csky.o -MMD -MP -MF 
./.deps/csky.TPo ../../gcc/gcc/config/csky/csky.cc
In file included from ../../gcc/gcc/config/csky/csky.h:183,
from ./tm.h:20,
from ../../gcc/gcc/backend.h:28,
from ../../gcc/gcc/config/csky/csky.cc:27:
../../gcc/gcc/config/csky/csky.cc: In function 'bool 
csky_emit_compare_float(rtx_code, rtx, rtx)':
../../gcc/gcc/config/csky/csky_isa.h:29:37: error: enum constant in boolean 
context [-Werror=int-in-bool-context]
  29 | #define CSKY_ISA_FEATURE_DEFINE(x)  isa_bit_ ## x
  | ^~~~
../../gcc/gcc/config/csky/csky_isa.h:30:37: note: in expansion of macro 
'CSKY_ISA_FEATURE_DEFINE'
  30 | #define CSKY_ISA_FEATURE_GET(x) CSKY_ISA_FEATURE_DEFINE (x)
  | ^~~
../../gcc/gcc/config/csky/csky.cc:6346:43: note: in expansion of macro 
'CSKY_ISA_FEATURE_GET'
6346 ||| CSKY_ISA_FEATURE_GET(fpv2_df)
  |   ^~~~
../../gcc/gcc/config/csky/csky_isa.h:29:37: error: enum constant in boolean 
context [-Werror=int-in-bool-context]
  29 | #define CSKY_ISA_FEATURE_DEFINE(x)  isa_bit_ ## x
  | ^~~~
../../gcc/gcc/config/csky/csky_isa.h:30:37: note: in expansion of macro 
'CSKY_ISA_FEATURE_DEFINE'
  30 | #define CSKY_ISA_FEATURE_GET(x) CSKY_ISA_FEATURE_DEFINE (x)
  | ^~~
../../gcc/gcc/config/csky/csky.cc:6346:43: note: in expansion of macro 
'CSKY_ISA_FEATURE_GET'
6346 ||| CSKY_ISA_FEATURE_GET(fpv2_df)
  |   ^~~~
../../gcc/gcc/config/csky/csky_isa.h:29:37: error: enum constant in boolean 
context [-Werror=int-in-bool-context]
  29 | #define CSKY_ISA_FEATURE_DEFINE(x)  isa_bit_ ## x
  | ^~~~
../../gcc/gcc/config/csky/csky_isa.h:30:37: note: in expansion of macro 
'CSKY_ISA_FEATURE_DEFINE'
  30 | #define CSKY_ISA_FEATURE_GET(x) CSKY_ISA_FEATURE_DEFINE (x)
  | ^~~
../../gcc/gcc/config/csky/csky.cc:6347:43: note: in expansion of macro 
'CSKY_ISA_FEATURE_GET'
6347 ||| 
CSKY_ISA_FEATURE_GET(fpv2_divd)))
  |   ^~~~

The 'CSKY_ISA_FEATURE_DEFINE (x)' is an enum contant, it will cause the 
condition always being true.
In addition to warning, it will let FPUV3 to generate a move instruction, which 
is unnecessary.
In a simple test case, the move instruction can be combined, so it was not 
found in the testsuite.
But in some complex scenarios, this may generate some redundant instructions.
The correct way is to use 'CSKY_ISA_FEATURE' instead of 
'CSKY_ISA_FEATURE_DEFINE'.

gcc/
* config/csky/csky.cc (csky_emit_compare_float): Fix the expanding of
float LE comparing with zero for fpuv3.
* config/csky/csky.h (TARGET_SUPPORT_FPV2): New, true if any fpuv2
features are enabled.
---
 gcc/config/csky/csky.cc | 4 +---
 gcc/config/csky/csky.h  | 4 
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/gcc/config/csky/csky.cc b/gcc/config/csky/csky.cc
index a7dc6cefead..4dc74d8924f 100644
--- a/gcc/config/csky/csky.cc
+++ b/gcc/config/csky/csky.cc
@@ -6342,9 +6342,7 @@ csky_emit_compare_float (enum rtx_code code, rtx op0, rtx 
op1)
 case GT:
 case LT:
 case LE:
-  if (op1 == CONST0_RTX (mode) && (CSKY_ISA_FEATURE_GET(fpv2_sf)
-  || CSKY_ISA_FEATURE_GET(fpv2_df)
-  || CSKY_ISA_FEATURE_GET(fpv2_divd)))
+  if (op1 == CONST0_RTX (mode) && TARGET_SUPPORT_FPV2)
op1 = force_reg (mode, op1);
   break;
 case ORDERED:
diff --git a/gcc/config/csky/csky.h b/gcc/config/csky/csky.h
index 37410f0cda4..f786ad55d43 100644
--- a/gcc/config/csky/csky.h
+++ b/gcc/config/csky/csky.h
@@ -165,6 +165,10 @@
 || CSKY_ISA_FEATURE (fpv3_sf) \
 || CSKY_ISA_FEATURE (fpv3_df))
 
+#define TARGET_SUPPORT_FPV2 (CSKY_ISA_FEATURE(fpv2_sf)\
+

[COMMITTED] C-SKY: Fix missing operand when do spilt for cskyv2_addcc and cskyv2_addcc_invert.

2022-09-06 Thread Xianmiao Qu via Gcc-patches
It will cause ICE when compiling the case:
gcc/testsuite/gcc.dg/params/blocksort-part.c

gcc/
* config/csky/csky.md (cskyv2_addcc): Fix missing operand.
(cskyv2_addcc_invert): Likewise.
---
 gcc/config/csky/csky.md | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/gcc/config/csky/csky.md b/gcc/config/csky/csky.md
index 6b05930a9fb..6a6592902ef 100644
--- a/gcc/config/csky/csky.md
+++ b/gcc/config/csky/csky.md
@@ -1279,7 +1279,8 @@
   "reload_completed && !rtx_equal_p (operands[0], operands[1])"
   [(set (match_dup 0)
(if_then_else:SI (ne (reg:CC CSKY_CC_REGNUM) (const_int 0))
-(plus:SI (match_dup 0) (match_dup 2]
+(plus:SI (match_dup 0) (match_dup 2))
+(match_dup 0)))]
   {
 emit_insn (gen_movf (copy_rtx (operands[0]),
 copy_rtx (operands[1]),
@@ -1305,7 +1306,8 @@
   "reload_completed && !rtx_equal_p (operands[0], operands[1])"
   [(set (match_dup 0)
(if_then_else:SI (eq (reg:CC CSKY_CC_REGNUM) (const_int 0))
-(plus:SI (match_dup 0) (match_dup 2]
+(plus:SI (match_dup 0) (match_dup 2))
+(match_dup 0)))]
   {
 emit_insn (gen_movt (copy_rtx (operands[0]),
 copy_rtx (operands[1]),
-- 
2.17.1



[committed] Update c-sky port maintainers' emails.

2022-09-06 Thread Xianmiao Qu via Gcc-patches
/
* MAINTAINERS: Update c-sky port maintainers' emails.
---
 MAINTAINERS | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/MAINTAINERS b/MAINTAINERS
index 02ced0c43aa..5e483e3cbe1 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -67,8 +67,8 @@ bfin port Jie Zhang   

 bpf port   Jose E. Marchesi
 c6x port   Bernd Schmidt   
 cris port  Hans-Peter Nilsson  
-c-sky port Xianmiao Qu 
-c-sky port Yunhai Shang
+c-sky port Xianmiao Qu 
+c-sky port Yunhai Shang
 epiphany port  Joern Rennecke  
 fr30 port  Nick Clifton
 frv port   Nick Clifton
-- 
2.24.0.windows.2