public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] bpf: correct pseudo-C template for add3 and sub3
@ 2023-07-27 18:11 David Faust
  2023-07-27 18:50 ` Jose E. Marchesi
  0 siblings, 1 reply; 2+ messages in thread
From: David Faust @ 2023-07-27 18:11 UTC (permalink / raw)
  To: gcc-patches; +Cc: jose.marchesi, cupertino.miranda

The pseudo-C output templates for these instructions were incorrectly
using operand 1 rather than operand 2 on the RHS, which led to some
very incorrect assembly generation with -masm=pseudoc.

Tested on bpf-unknown-none.
OK?

gcc/

	* config/bpf/bpf.md (add<AM:mode>3): Use %w2 instead of %w1
	in pseudo-C dialect output template.
	(sub<AM:mode>3): Likewise.

gcc/testsuite/

	* gcc.target/bpf/alu-2.c: New test.
	* gcc.target/bpf/alu-pseudoc-2.c: Likewise.
---
 gcc/config/bpf/bpf.md                        |  4 ++--
 gcc/testsuite/gcc.target/bpf/alu-2.c         | 12 ++++++++++++
 gcc/testsuite/gcc.target/bpf/alu-pseudoc-2.c | 13 +++++++++++++
 3 files changed, 27 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/bpf/alu-2.c
 create mode 100644 gcc/testsuite/gcc.target/bpf/alu-pseudoc-2.c

diff --git a/gcc/config/bpf/bpf.md b/gcc/config/bpf/bpf.md
index 2ffc4ebd17e..66436397bb7 100644
--- a/gcc/config/bpf/bpf.md
+++ b/gcc/config/bpf/bpf.md
@@ -131,7 +131,7 @@ (define_insn "add<AM:mode>3"
         (plus:AM (match_operand:AM 1 "register_operand"   " 0,0")
                  (match_operand:AM 2 "reg_or_imm_operand" " r,I")))]
   "1"
-  "{add<msuffix>\t%0,%2|%w0 += %w1}"
+  "{add<msuffix>\t%0,%2|%w0 += %w2}"
   [(set_attr "type" "<mtype>")])
 
 ;;; Subtraction
@@ -144,7 +144,7 @@ (define_insn "sub<AM:mode>3"
         (minus:AM (match_operand:AM 1 "register_operand" " 0")
                   (match_operand:AM 2 "register_operand" " r")))]
   ""
-  "{sub<msuffix>\t%0,%2|%w0 -= %w1}"
+  "{sub<msuffix>\t%0,%2|%w0 -= %w2}"
   [(set_attr "type" "<mtype>")])
 
 ;;; Negation
diff --git a/gcc/testsuite/gcc.target/bpf/alu-2.c b/gcc/testsuite/gcc.target/bpf/alu-2.c
new file mode 100644
index 00000000000..0444a9bc68a
--- /dev/null
+++ b/gcc/testsuite/gcc.target/bpf/alu-2.c
@@ -0,0 +1,12 @@
+/* Check add and sub instructions.  */
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+long foo (long x, long y)
+{
+  return y - x + 4;
+}
+
+/* { dg-final { scan-assembler-not {sub\t(%r.),\1\n} } } */
+/* { dg-final { scan-assembler {sub\t(\%r.),(\%r.)\n} } } */
+/* { dg-final { scan-assembler {add\t(\%r.),4\n} } } */
diff --git a/gcc/testsuite/gcc.target/bpf/alu-pseudoc-2.c b/gcc/testsuite/gcc.target/bpf/alu-pseudoc-2.c
new file mode 100644
index 00000000000..751db2477c0
--- /dev/null
+++ b/gcc/testsuite/gcc.target/bpf/alu-pseudoc-2.c
@@ -0,0 +1,13 @@
+/* Check add and sub instructions (pseudoc asm dialect).  */
+/* { dg-do compile } */
+/* { dg-options "-masm=pseudoc" } */
+
+long foo (long x, long y)
+{
+  return y - x + 4;
+}
+
+/* { dg-final { scan-assembler-not {\t(r.) -= \1\n} } } */
+/* { dg-final { scan-assembler {\t(r.) -= (r.)\n} } } */
+/* { dg-final { scan-assembler {\t(r.) \+= 4\n} } } */
+
-- 
2.40.1


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

* Re: [PATCH] bpf: correct pseudo-C template for add3 and sub3
  2023-07-27 18:11 [PATCH] bpf: correct pseudo-C template for add3 and sub3 David Faust
@ 2023-07-27 18:50 ` Jose E. Marchesi
  0 siblings, 0 replies; 2+ messages in thread
From: Jose E. Marchesi @ 2023-07-27 18:50 UTC (permalink / raw)
  To: David Faust; +Cc: gcc-patches, cupertino.miranda


> The pseudo-C output templates for these instructions were incorrectly
> using operand 1 rather than operand 2 on the RHS, which led to some
> very incorrect assembly generation with -masm=pseudoc.
>
> Tested on bpf-unknown-none.
> OK?

OK.  Thanks for spotting and fixing this!

>
> gcc/
>
> 	* config/bpf/bpf.md (add<AM:mode>3): Use %w2 instead of %w1
> 	in pseudo-C dialect output template.
> 	(sub<AM:mode>3): Likewise.
>
> gcc/testsuite/
>
> 	* gcc.target/bpf/alu-2.c: New test.
> 	* gcc.target/bpf/alu-pseudoc-2.c: Likewise.
> ---
>  gcc/config/bpf/bpf.md                        |  4 ++--
>  gcc/testsuite/gcc.target/bpf/alu-2.c         | 12 ++++++++++++
>  gcc/testsuite/gcc.target/bpf/alu-pseudoc-2.c | 13 +++++++++++++
>  3 files changed, 27 insertions(+), 2 deletions(-)
>  create mode 100644 gcc/testsuite/gcc.target/bpf/alu-2.c
>  create mode 100644 gcc/testsuite/gcc.target/bpf/alu-pseudoc-2.c
>
> diff --git a/gcc/config/bpf/bpf.md b/gcc/config/bpf/bpf.md
> index 2ffc4ebd17e..66436397bb7 100644
> --- a/gcc/config/bpf/bpf.md
> +++ b/gcc/config/bpf/bpf.md
> @@ -131,7 +131,7 @@ (define_insn "add<AM:mode>3"
>          (plus:AM (match_operand:AM 1 "register_operand"   " 0,0")
>                   (match_operand:AM 2 "reg_or_imm_operand" " r,I")))]
>    "1"
> -  "{add<msuffix>\t%0,%2|%w0 += %w1}"
> +  "{add<msuffix>\t%0,%2|%w0 += %w2}"
>    [(set_attr "type" "<mtype>")])
>  
>  ;;; Subtraction
> @@ -144,7 +144,7 @@ (define_insn "sub<AM:mode>3"
>          (minus:AM (match_operand:AM 1 "register_operand" " 0")
>                    (match_operand:AM 2 "register_operand" " r")))]
>    ""
> -  "{sub<msuffix>\t%0,%2|%w0 -= %w1}"
> +  "{sub<msuffix>\t%0,%2|%w0 -= %w2}"
>    [(set_attr "type" "<mtype>")])
>  
>  ;;; Negation
> diff --git a/gcc/testsuite/gcc.target/bpf/alu-2.c b/gcc/testsuite/gcc.target/bpf/alu-2.c
> new file mode 100644
> index 00000000000..0444a9bc68a
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/bpf/alu-2.c
> @@ -0,0 +1,12 @@
> +/* Check add and sub instructions.  */
> +/* { dg-do compile } */
> +/* { dg-options "" } */
> +
> +long foo (long x, long y)
> +{
> +  return y - x + 4;
> +}
> +
> +/* { dg-final { scan-assembler-not {sub\t(%r.),\1\n} } } */
> +/* { dg-final { scan-assembler {sub\t(\%r.),(\%r.)\n} } } */
> +/* { dg-final { scan-assembler {add\t(\%r.),4\n} } } */
> diff --git a/gcc/testsuite/gcc.target/bpf/alu-pseudoc-2.c b/gcc/testsuite/gcc.target/bpf/alu-pseudoc-2.c
> new file mode 100644
> index 00000000000..751db2477c0
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/bpf/alu-pseudoc-2.c
> @@ -0,0 +1,13 @@
> +/* Check add and sub instructions (pseudoc asm dialect).  */
> +/* { dg-do compile } */
> +/* { dg-options "-masm=pseudoc" } */
> +
> +long foo (long x, long y)
> +{
> +  return y - x + 4;
> +}
> +
> +/* { dg-final { scan-assembler-not {\t(r.) -= \1\n} } } */
> +/* { dg-final { scan-assembler {\t(r.) -= (r.)\n} } } */
> +/* { dg-final { scan-assembler {\t(r.) \+= 4\n} } } */
> +

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

end of thread, other threads:[~2023-07-27 18:50 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-27 18:11 [PATCH] bpf: correct pseudo-C template for add3 and sub3 David Faust
2023-07-27 18:50 ` Jose E. Marchesi

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