From: David Faust <david.faust@oracle.com>
To: gcc-patches@gcc.gnu.org
Subject: [PATCH 2/3] bpf testsuite: add tests for new feature options
Date: Thu, 9 Sep 2021 14:36:44 -0700 [thread overview]
Message-ID: <20210909213645.11605-3-david.faust@oracle.com> (raw)
In-Reply-To: <20210909213645.11605-1-david.faust@oracle.com>
This commit adds tests for the new -mjmpext, -mjmp32 and -malu32 feature
options in the BPF backend.
gcc/testsuite/ChangeLog:
* gcc.target/bpf/alu-1.c: New test.
* gcc.target/bpf/jmp-1.c: New test.
---
gcc/testsuite/gcc.target/bpf/alu-1.c | 56 +++++++++++++++++++++++++++
gcc/testsuite/gcc.target/bpf/jmp-1.c | 57 ++++++++++++++++++++++++++++
2 files changed, 113 insertions(+)
create mode 100644 gcc/testsuite/gcc.target/bpf/alu-1.c
create mode 100644 gcc/testsuite/gcc.target/bpf/jmp-1.c
diff --git a/gcc/testsuite/gcc.target/bpf/alu-1.c b/gcc/testsuite/gcc.target/bpf/alu-1.c
new file mode 100644
index 00000000000..98149305e82
--- /dev/null
+++ b/gcc/testsuite/gcc.target/bpf/alu-1.c
@@ -0,0 +1,56 @@
+/* Ensure 32-bit ALU instructions are not generated if -malu32 is
+ not enabled. */
+
+/* { dg-do compile } */
+/* { dg-options "-mno-alu32" } */
+
+int foo (int a, int b)
+{
+ a += 1;
+ b += a;
+ b -= 5;
+ a -= a;
+
+ a *= 2;
+ b *= a;
+
+ a |= 0xfafa;
+ b |= a;
+ b &= 0x00ffff00;
+ b &= a;
+
+ a <<= 2;
+ b <<= a;
+ b >>= 5;
+ a >>= b;
+
+ int c = a;
+ int d = 5;
+
+ d ^= a;
+ c ^= 0xe5e5e5e5;
+ c = -c;
+
+ unsigned int x = a;
+ unsigned int y = b;
+ x /= 3;
+ y /= x;
+ x %= 4;
+ y %= x;
+
+ return a + b - c + d - x + y;
+}
+
+/* { dg-final { scan-assembler-times "mov32\t0" 0 } } */
+/* { dg-final { scan-assembler-times "add32\t0" 0 } } */
+/* { dg-final { scan-assembler-times "sub32\t0" 0 } } */
+/* { dg-final { scan-assembler-times "mul32\t0" 0 } } */
+/* { dg-final { scan-assembler-times "div32\t0" 0 } } */
+/* { dg-final { scan-assembler-times "mod32\t0" 0 } } */
+/* { dg-final { scan-assembler-times "neg32\t0" 0 } } */
+/* { dg-final { scan-assembler-times "and32\t0" 0 } } */
+/* { dg-final { scan-assembler-times "or32\t0" 0 } } */
+/* { dg-final { scan-assembler-times "xor32\t0" 0 } } */
+/* { dg-final { scan-assembler-times "rsh32\t0" 0 } } */
+/* { dg-final { scan-assembler-times "lsh32\t0" 0 } } */
+/* { dg-final { scan-assembler-times "arsh32\t0" 0 } } */
diff --git a/gcc/testsuite/gcc.target/bpf/jmp-1.c b/gcc/testsuite/gcc.target/bpf/jmp-1.c
new file mode 100644
index 00000000000..eaf825395ef
--- /dev/null
+++ b/gcc/testsuite/gcc.target/bpf/jmp-1.c
@@ -0,0 +1,57 @@
+/* Ensure jlt, jslt, jle and jsle instructions are not generated if
+ -mjmpext is not enabled, and no 32-bit jump instructions are generated
+ if -mjmp32 is not enabled. */
+
+/* { dg-do compile } */
+/* { dg-options "-mno-jmpext -mno-jmp32" } */
+
+int foo (int a, int b)
+{
+ if (a == 1)
+ b += 1;
+ if (a != 3)
+ b += 2;
+ if (a > 5)
+ b += 3;
+ if (a >= 7)
+ b += 4;
+ if (a < 9)
+ b += 5;
+ if (a <= 10)
+ b += 6;
+
+ return a + b;
+}
+
+unsigned int bar (unsigned int a, unsigned int b)
+{
+ if (a == 1)
+ b += 1;
+ if (a != 3)
+ b += 2;
+ if (a > 5)
+ b += 3;
+ if (a >= 7)
+ b += 4;
+ if (a < 9)
+ b += 5;
+ if (a <= 10)
+ b += 6;
+
+ return a + b;
+}
+
+/* { dg-final { scan-assembler-times "jlt\t0" 0 } } */
+/* { dg-final { scan-assembler-times "jslt\t0" 0 } } */
+/* { dg-final { scan-assembler-times "jle\t0" 0 } } */
+/* { dg-final { scan-assembler-times "jsle\t0" 0 } } */
+/* { dg-final { scan-assembler-times "jeq32\t0" 0 } } */
+/* { dg-final { scan-assembler-times "jne32\t0" 0 } } */
+/* { dg-final { scan-assembler-times "jlt32\t0" 0 } } */
+/* { dg-final { scan-assembler-times "jgt32\t0" 0 } } */
+/* { dg-final { scan-assembler-times "jle32\t0" 0 } } */
+/* { dg-final { scan-assembler-times "jge32\t0" 0 } } */
+/* { dg-final { scan-assembler-times "jslt32\t0" 0 } } */
+/* { dg-final { scan-assembler-times "jsgt32\t0" 0 } } */
+/* { dg-final { scan-assembler-times "jsle32\t0" 0 } } */
+/* { dg-final { scan-assembler-times "jsge32\t0" 0 } } */
--
2.33.0
next prev parent reply other threads:[~2021-09-09 21:37 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-09 21:36 [PATCH 0/3] bpf: add -mcpu and related " David Faust
2021-09-09 21:36 ` [PATCH 1/3] " David Faust
2021-09-09 21:36 ` David Faust [this message]
2021-09-09 21:36 ` [PATCH 3/3] doc: document BPF -mcpu and related options David Faust
2021-09-10 14:11 ` [PATCH 0/3] bpf: add -mcpu and related feature options Jose E. Marchesi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210909213645.11605-3-david.faust@oracle.com \
--to=david.faust@oracle.com \
--cc=gcc-patches@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).