]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
bpf: fix generation of neg and neg32 BPF instructions
authorJose E. Marchesi <jose.marchesi@oracle.com>
Wed, 26 Jul 2023 10:07:30 +0000 (12:07 +0200)
committerJose E. Marchesi <jose.marchesi@oracle.com>
Wed, 26 Jul 2023 10:09:41 +0000 (12:09 +0200)
This patch fixes GCC to generate correct neg and neg32 instructions,
which do not take a source register operand.  A couple of new tests
are added.

Tested in bpf-unknown-none.

gcc/ChangeLog

2023-07-26  Jose E. Marchesi  <jose.marchesi@oracle.com>

* config/bpf/bpf.md: Fix neg{SI,DI}2 insn.

gcc/testsuite/ChangeLog

2023-07-26  Jose E. Marchesi  <jose.marchesi@oracle.com>

* gcc.target/bpf/neg-1.c: New test.
* gcc.target/bpf/neg-pseudoc-1.c: Likewise.

gcc/config/bpf/bpf.md
gcc/testsuite/gcc.target/bpf/neg-1.c [new file with mode: 0644]
gcc/testsuite/gcc.target/bpf/neg-pseudoc-1.c [new file with mode: 0644]

index 579a8213b095fad6cbdcb7de45aba3d36c164d67..1b5e1900d4fae234a152a92d0691c37ed53f0457 100644 (file)
 ;;; Negation
 (define_insn "neg<AM:mode>2"
   [(set (match_operand:AM         0 "register_operand"   "=r,r")
-        (neg:AM (match_operand:AM 1 "reg_or_imm_operand" " r,I")))]
+        (neg:AM (match_operand:AM 1 "reg_or_imm_operand" " 0,I")))]
   ""
-  "{neg<msuffix>\t%0,%1|%w0 = -%w1}"
+  "{neg<msuffix>\t%0|%w0 = -%w1}"
   [(set_attr "type" "<mtype>")])
 
 ;;; Multiplication
diff --git a/gcc/testsuite/gcc.target/bpf/neg-1.c b/gcc/testsuite/gcc.target/bpf/neg-1.c
new file mode 100644 (file)
index 0000000..9ffb956
--- /dev/null
@@ -0,0 +1,14 @@
+/* Check negr and negr32 instructions.  */
+
+/* { dg-do compile } */
+/* { dg-options "-malu32" } */
+
+long foo (long a, long b, int x, int y)
+{
+  a = -b;
+  x = -y;
+  return a + x;
+}
+
+/* { dg-final { scan-assembler "neg\t%r.\n" } } */
+/* { dg-final { scan-assembler "neg32\t%r.\n" } } */
diff --git a/gcc/testsuite/gcc.target/bpf/neg-pseudoc-1.c b/gcc/testsuite/gcc.target/bpf/neg-pseudoc-1.c
new file mode 100644 (file)
index 0000000..a4fb687
--- /dev/null
@@ -0,0 +1,14 @@
+/* Check negr and negr32 instructions (pseudoc asm dialect.)  */
+
+/* { dg-do compile } */
+/* { dg-options "-malu32 -masm=pseudoc" } */
+
+long foo (long a, long b, int x, int y)
+{
+  a = -b;
+  x = -y;
+  return a + x;
+}
+
+/* { dg-final { scan-assembler {\t(r.) = -\1\n} } } */
+/* { dg-final { scan-assembler {\t(w.) = -\1\n} } } */