public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] RISC-V: Fix the illegal operands for the XTheadMemidx extension.
@ 2023-11-09  7:40 Jin Ma
  2023-11-09  8:00 ` Kito Cheng
  2023-11-09  8:08 ` Christoph Müllner
  0 siblings, 2 replies; 3+ messages in thread
From: Jin Ma @ 2023-11-09  7:40 UTC (permalink / raw)
  To: gcc-patches; +Cc: christoph.muellner, jinma.contrib, Jin Ma

The pattern "*extend<SHORT:mode><SUPERQI:mode>2_bitmanip" and
"*zero_extendhi<GPR:mode>2_bitmanip" in bitmanip.md are similar
to the pattern "*th_memidx_bb_extendqi<SUPERQI:mode>2" and
"*th_memidx_bb_zero_extendhi<GPR:mode>2" in thead.md, which will
cause the wrong instruction to be generated and report the
following error in binutils:
Assembler messages:
Error: illegal operands `lb a5,(a0),1,0'

In fact, the correct instruction is "th.lbia a5,(a0),1,0".

gcc/ChangeLog:

	* config/riscv/bitmanip.md: Avoid the conflict between
	zbb and xtheadmemidx in patterns.

gcc/testsuite/ChangeLog:

	* gcc.target/riscv/xtheadfmemidx-uindex-zbb.c: New test.
---
 gcc/config/riscv/bitmanip.md                  |  4 +--
 .../riscv/xtheadfmemidx-uindex-zbb.c          | 30 +++++++++++++++++++
 2 files changed, 32 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/riscv/xtheadfmemidx-uindex-zbb.c

diff --git a/gcc/config/riscv/bitmanip.md b/gcc/config/riscv/bitmanip.md
index a9c8275fca7..878395c3ffa 100644
--- a/gcc/config/riscv/bitmanip.md
+++ b/gcc/config/riscv/bitmanip.md
@@ -290,7 +290,7 @@ (define_insn "*<bitmanip_optab>di2"
 (define_insn "*zero_extendhi<GPR:mode>2_bitmanip"
   [(set (match_operand:GPR 0 "register_operand" "=r,r")
         (zero_extend:GPR (match_operand:HI 1 "nonimmediate_operand" "r,m")))]
-  "TARGET_ZBB"
+  "TARGET_ZBB  && !TARGET_XTHEADMEMIDX"
   "@
    zext.h\t%0,%1
    lhu\t%0,%1"
@@ -301,7 +301,7 @@ (define_insn "*extend<SHORT:mode><SUPERQI:mode>2_bitmanip"
   [(set (match_operand:SUPERQI   0 "register_operand"     "=r,r")
 	(sign_extend:SUPERQI
 	    (match_operand:SHORT 1 "nonimmediate_operand" " r,m")))]
-  "TARGET_ZBB"
+  "TARGET_ZBB && !TARGET_XTHEADMEMIDX"
   "@
    sext.<SHORT:size>\t%0,%1
    l<SHORT:size>\t%0,%1"
diff --git a/gcc/testsuite/gcc.target/riscv/xtheadfmemidx-uindex-zbb.c b/gcc/testsuite/gcc.target/riscv/xtheadfmemidx-uindex-zbb.c
new file mode 100644
index 00000000000..a05bc220cba
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/xtheadfmemidx-uindex-zbb.c
@@ -0,0 +1,30 @@
+/* { dg-do compile } */
+/* { dg-skip-if "" { *-*-* } { "-O0" "-O1" "-Og" } } */
+/* { dg-options "-march=rv64gc_zbb_xtheadmemidx -mabi=lp64d" { target { rv64 } } } */
+/* { dg-options "-march=rv32imafc_zbb_xtheadmemidx -mabi=ilp32f" { target { rv32 } } } */
+
+const unsigned char *
+read_uleb128(const unsigned char *p, unsigned long *val)
+{
+  unsigned int shift = 0;
+  unsigned char byte;
+  unsigned long result;
+
+  result = 0;
+  do
+  {
+    byte = *p++;
+    result |= ((unsigned long)byte & 0x7f) << shift;
+    shift += 7;
+  } while (byte & 0x80);
+
+  *val = result;
+  return p;
+}
+
+void test(const unsigned char *p, unsigned long utmp)
+{
+  p = read_uleb128(p, &utmp);
+}
+
+/* { dg-final { scan-assembler-not {\mlb\ta[0-9],\(a[0-9]\),1,0\M} } } */

base-commit: 04d8a47608dcae7f61805e3566e3a1571b574405
-- 
2.17.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] RISC-V: Fix the illegal operands for the XTheadMemidx extension.
  2023-11-09  7:40 [PATCH] RISC-V: Fix the illegal operands for the XTheadMemidx extension Jin Ma
@ 2023-11-09  8:00 ` Kito Cheng
  2023-11-09  8:08 ` Christoph Müllner
  1 sibling, 0 replies; 3+ messages in thread
From: Kito Cheng @ 2023-11-09  8:00 UTC (permalink / raw)
  To: Jin Ma; +Cc: gcc-patches, christoph.muellner, jinma.contrib

Thanks, pushed :)

On Thu, Nov 9, 2023 at 3:40 PM Jin Ma <jinma@linux.alibaba.com> wrote:
>
> The pattern "*extend<SHORT:mode><SUPERQI:mode>2_bitmanip" and
> "*zero_extendhi<GPR:mode>2_bitmanip" in bitmanip.md are similar
> to the pattern "*th_memidx_bb_extendqi<SUPERQI:mode>2" and
> "*th_memidx_bb_zero_extendhi<GPR:mode>2" in thead.md, which will
> cause the wrong instruction to be generated and report the
> following error in binutils:
> Assembler messages:
> Error: illegal operands `lb a5,(a0),1,0'
>
> In fact, the correct instruction is "th.lbia a5,(a0),1,0".
>
> gcc/ChangeLog:
>
>         * config/riscv/bitmanip.md: Avoid the conflict between
>         zbb and xtheadmemidx in patterns.
>
> gcc/testsuite/ChangeLog:
>
>         * gcc.target/riscv/xtheadfmemidx-uindex-zbb.c: New test.
> ---
>  gcc/config/riscv/bitmanip.md                  |  4 +--
>  .../riscv/xtheadfmemidx-uindex-zbb.c          | 30 +++++++++++++++++++
>  2 files changed, 32 insertions(+), 2 deletions(-)
>  create mode 100644 gcc/testsuite/gcc.target/riscv/xtheadfmemidx-uindex-zbb.c
>
> diff --git a/gcc/config/riscv/bitmanip.md b/gcc/config/riscv/bitmanip.md
> index a9c8275fca7..878395c3ffa 100644
> --- a/gcc/config/riscv/bitmanip.md
> +++ b/gcc/config/riscv/bitmanip.md
> @@ -290,7 +290,7 @@ (define_insn "*<bitmanip_optab>di2"
>  (define_insn "*zero_extendhi<GPR:mode>2_bitmanip"
>    [(set (match_operand:GPR 0 "register_operand" "=r,r")
>          (zero_extend:GPR (match_operand:HI 1 "nonimmediate_operand" "r,m")))]
> -  "TARGET_ZBB"
> +  "TARGET_ZBB  && !TARGET_XTHEADMEMIDX"
>    "@
>     zext.h\t%0,%1
>     lhu\t%0,%1"
> @@ -301,7 +301,7 @@ (define_insn "*extend<SHORT:mode><SUPERQI:mode>2_bitmanip"
>    [(set (match_operand:SUPERQI   0 "register_operand"     "=r,r")
>         (sign_extend:SUPERQI
>             (match_operand:SHORT 1 "nonimmediate_operand" " r,m")))]
> -  "TARGET_ZBB"
> +  "TARGET_ZBB && !TARGET_XTHEADMEMIDX"
>    "@
>     sext.<SHORT:size>\t%0,%1
>     l<SHORT:size>\t%0,%1"
> diff --git a/gcc/testsuite/gcc.target/riscv/xtheadfmemidx-uindex-zbb.c b/gcc/testsuite/gcc.target/riscv/xtheadfmemidx-uindex-zbb.c
> new file mode 100644
> index 00000000000..a05bc220cba
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/riscv/xtheadfmemidx-uindex-zbb.c
> @@ -0,0 +1,30 @@
> +/* { dg-do compile } */
> +/* { dg-skip-if "" { *-*-* } { "-O0" "-O1" "-Og" } } */
> +/* { dg-options "-march=rv64gc_zbb_xtheadmemidx -mabi=lp64d" { target { rv64 } } } */
> +/* { dg-options "-march=rv32imafc_zbb_xtheadmemidx -mabi=ilp32f" { target { rv32 } } } */
> +
> +const unsigned char *
> +read_uleb128(const unsigned char *p, unsigned long *val)
> +{
> +  unsigned int shift = 0;
> +  unsigned char byte;
> +  unsigned long result;
> +
> +  result = 0;
> +  do
> +  {
> +    byte = *p++;
> +    result |= ((unsigned long)byte & 0x7f) << shift;
> +    shift += 7;
> +  } while (byte & 0x80);
> +
> +  *val = result;
> +  return p;
> +}
> +
> +void test(const unsigned char *p, unsigned long utmp)
> +{
> +  p = read_uleb128(p, &utmp);
> +}
> +
> +/* { dg-final { scan-assembler-not {\mlb\ta[0-9],\(a[0-9]\),1,0\M} } } */
>
> base-commit: 04d8a47608dcae7f61805e3566e3a1571b574405
> --
> 2.17.1
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] RISC-V: Fix the illegal operands for the XTheadMemidx extension.
  2023-11-09  7:40 [PATCH] RISC-V: Fix the illegal operands for the XTheadMemidx extension Jin Ma
  2023-11-09  8:00 ` Kito Cheng
@ 2023-11-09  8:08 ` Christoph Müllner
  1 sibling, 0 replies; 3+ messages in thread
From: Christoph Müllner @ 2023-11-09  8:08 UTC (permalink / raw)
  To: Jin Ma; +Cc: gcc-patches, jinma.contrib

On Thu, Nov 9, 2023 at 8:40 AM Jin Ma <jinma@linux.alibaba.com> wrote:
>
> The pattern "*extend<SHORT:mode><SUPERQI:mode>2_bitmanip" and
> "*zero_extendhi<GPR:mode>2_bitmanip" in bitmanip.md are similar
> to the pattern "*th_memidx_bb_extendqi<SUPERQI:mode>2" and
> "*th_memidx_bb_zero_extendhi<GPR:mode>2" in thead.md, which will
> cause the wrong instruction to be generated and report the
> following error in binutils:
> Assembler messages:
> Error: illegal operands `lb a5,(a0),1,0'
>
> In fact, the correct instruction is "th.lbia a5,(a0),1,0".

LGTM.
This zbb_xtheadmemidx was not part of the test matrix.
We only had xtheadbb_xtheadmemidx there.

Thanks!

>
> gcc/ChangeLog:
>
>         * config/riscv/bitmanip.md: Avoid the conflict between
>         zbb and xtheadmemidx in patterns.
>
> gcc/testsuite/ChangeLog:
>
>         * gcc.target/riscv/xtheadfmemidx-uindex-zbb.c: New test.
> ---
>  gcc/config/riscv/bitmanip.md                  |  4 +--
>  .../riscv/xtheadfmemidx-uindex-zbb.c          | 30 +++++++++++++++++++
>  2 files changed, 32 insertions(+), 2 deletions(-)
>  create mode 100644 gcc/testsuite/gcc.target/riscv/xtheadfmemidx-uindex-zbb.c
>
> diff --git a/gcc/config/riscv/bitmanip.md b/gcc/config/riscv/bitmanip.md
> index a9c8275fca7..878395c3ffa 100644
> --- a/gcc/config/riscv/bitmanip.md
> +++ b/gcc/config/riscv/bitmanip.md
> @@ -290,7 +290,7 @@ (define_insn "*<bitmanip_optab>di2"
>  (define_insn "*zero_extendhi<GPR:mode>2_bitmanip"
>    [(set (match_operand:GPR 0 "register_operand" "=r,r")
>          (zero_extend:GPR (match_operand:HI 1 "nonimmediate_operand" "r,m")))]
> -  "TARGET_ZBB"
> +  "TARGET_ZBB  && !TARGET_XTHEADMEMIDX"
>    "@
>     zext.h\t%0,%1
>     lhu\t%0,%1"
> @@ -301,7 +301,7 @@ (define_insn "*extend<SHORT:mode><SUPERQI:mode>2_bitmanip"
>    [(set (match_operand:SUPERQI   0 "register_operand"     "=r,r")
>         (sign_extend:SUPERQI
>             (match_operand:SHORT 1 "nonimmediate_operand" " r,m")))]
> -  "TARGET_ZBB"
> +  "TARGET_ZBB && !TARGET_XTHEADMEMIDX"
>    "@
>     sext.<SHORT:size>\t%0,%1
>     l<SHORT:size>\t%0,%1"
> diff --git a/gcc/testsuite/gcc.target/riscv/xtheadfmemidx-uindex-zbb.c b/gcc/testsuite/gcc.target/riscv/xtheadfmemidx-uindex-zbb.c
> new file mode 100644
> index 00000000000..a05bc220cba
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/riscv/xtheadfmemidx-uindex-zbb.c
> @@ -0,0 +1,30 @@
> +/* { dg-do compile } */
> +/* { dg-skip-if "" { *-*-* } { "-O0" "-O1" "-Og" } } */
> +/* { dg-options "-march=rv64gc_zbb_xtheadmemidx -mabi=lp64d" { target { rv64 } } } */
> +/* { dg-options "-march=rv32imafc_zbb_xtheadmemidx -mabi=ilp32f" { target { rv32 } } } */
> +
> +const unsigned char *
> +read_uleb128(const unsigned char *p, unsigned long *val)
> +{
> +  unsigned int shift = 0;
> +  unsigned char byte;
> +  unsigned long result;
> +
> +  result = 0;
> +  do
> +  {
> +    byte = *p++;
> +    result |= ((unsigned long)byte & 0x7f) << shift;
> +    shift += 7;
> +  } while (byte & 0x80);
> +
> +  *val = result;
> +  return p;
> +}
> +
> +void test(const unsigned char *p, unsigned long utmp)
> +{
> +  p = read_uleb128(p, &utmp);
> +}
> +
> +/* { dg-final { scan-assembler-not {\mlb\ta[0-9],\(a[0-9]\),1,0\M} } } */
>
> base-commit: 04d8a47608dcae7f61805e3566e3a1571b574405
> --
> 2.17.1
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-11-09  8:08 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-09  7:40 [PATCH] RISC-V: Fix the illegal operands for the XTheadMemidx extension Jin Ma
2023-11-09  8:00 ` Kito Cheng
2023-11-09  8:08 ` Christoph Müllner

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).