aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorSandra Loosemore <sandra@codesourcery.com>2014-12-08 21:53:00 -0500
committerSandra Loosemore <sandra@gcc.gnu.org>2014-12-08 21:53:00 -0500
commit10828a0194f2cc16f345e392ae968f9582e01952 (patch)
treecd75cdabae8e92253d9371bd0dae743d7c9e863d /gcc
parent58dddbd21adef585e9f049e83bd58a1a08da074d (diff)
downloadgcc-10828a0194f2cc16f345e392ae968f9582e01952.zip
gcc-10828a0194f2cc16f345e392ae968f9582e01952.tar.gz
gcc-10828a0194f2cc16f345e392ae968f9582e01952.tar.bz2
simplify-rtx.c (simplify_relational_operation_1): Handle simplification identities for BICS patterns.
2014-12-08 Sandra Loosemore <sandra@codesourcery.com> gcc/ * simplify-rtx.c (simplify_relational_operation_1): Handle simplification identities for BICS patterns. gcc/testsuite/ * gcc.target/aarch64/bics_4.c: New. From-SVN: r218503
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog5
-rw-r--r--gcc/simplify-rtx.c26
-rw-r--r--gcc/testsuite/ChangeLog4
-rw-r--r--gcc/testsuite/gcc.target/aarch64/bics_4.c87
4 files changed, 122 insertions, 0 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 5c70950..9ec2979 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,8 @@
+2014-12-08 Sandra Loosemore <sandra@codesourcery.com>
+
+ * simplify-rtx.c (simplify_relational_operation_1): Handle
+ simplification identities for BICS patterns.
+
2014-12-08 Trevor Saunders <tsaunders@mozilla.com>
* config/nvptx/nvptx.c: Convert htabs to hash_table.
diff --git a/gcc/simplify-rtx.c b/gcc/simplify-rtx.c
index 055ba78..1cbb157 100644
--- a/gcc/simplify-rtx.c
+++ b/gcc/simplify-rtx.c
@@ -4550,6 +4550,32 @@ simplify_relational_operation_1 (enum rtx_code code, machine_mode mode,
simplify_gen_binary (XOR, cmp_mode,
XEXP (op0, 1), op1));
+ /* (eq/ne (and x y) x) simplifies to (eq/ne (and (not y) x) 0), which
+ can be implemented with a BICS instruction on some targets, or
+ constant-folded if y is a constant. */
+ if ((code == EQ || code == NE)
+ && op0code == AND
+ && rtx_equal_p (XEXP (op0, 0), op1)
+ && !side_effects_p (op1))
+ {
+ rtx not_y = simplify_gen_unary (NOT, cmp_mode, XEXP (op0, 1), cmp_mode);
+ rtx lhs = simplify_gen_binary (AND, cmp_mode, not_y, XEXP (op0, 0));
+
+ return simplify_gen_relational (code, mode, cmp_mode, lhs, const0_rtx);
+ }
+
+ /* Likewise for (eq/ne (and x y) y). */
+ if ((code == EQ || code == NE)
+ && op0code == AND
+ && rtx_equal_p (XEXP (op0, 1), op1)
+ && !side_effects_p (op1))
+ {
+ rtx not_x = simplify_gen_unary (NOT, cmp_mode, XEXP (op0, 0), cmp_mode);
+ rtx lhs = simplify_gen_binary (AND, cmp_mode, not_x, XEXP (op0, 1));
+
+ return simplify_gen_relational (code, mode, cmp_mode, lhs, const0_rtx);
+ }
+
/* (eq/ne (bswap x) C1) simplifies to (eq/ne x C2) with C2 swapped. */
if ((code == EQ || code == NE)
&& GET_CODE (op0) == BSWAP
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 08ddd7b..b5ddcca 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,7 @@
+2014-12-08 Sandra Loosemore <sandra@codesourcery.com>
+
+ * gcc.target/aarch64/bics_4.c: New.
+
2014-12-08 Mark Wielaard <mjw@redhat.com>
PR debug/60782
diff --git a/gcc/testsuite/gcc.target/aarch64/bics_4.c b/gcc/testsuite/gcc.target/aarch64/bics_4.c
new file mode 100644
index 0000000..ee82c4f
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/bics_4.c
@@ -0,0 +1,87 @@
+/* { dg-do run } */
+/* { dg-options "-O2 --save-temps -fno-inline" } */
+
+extern void abort (void);
+
+int
+bics_si_test1 (int a, int b, int c)
+{
+ if ((a & b) == a)
+ return a;
+ else
+ return c;
+}
+
+int
+bics_si_test2 (int a, int b, int c)
+{
+ if ((a & b) == b)
+ return b;
+ else
+ return c;
+}
+
+typedef long long s64;
+
+s64
+bics_di_test1 (s64 a, s64 b, s64 c)
+{
+ if ((a & b) == a)
+ return a;
+ else
+ return c;
+}
+
+s64
+bics_di_test2 (s64 a, s64 b, s64 c)
+{
+ if ((a & b) == b)
+ return b;
+ else
+ return c;
+}
+
+int
+main ()
+{
+ int x;
+ s64 y;
+
+ x = bics_si_test1 (0xf00d, 0xf11f, 0);
+ if (x != 0xf00d)
+ abort ();
+
+ x = bics_si_test1 (0xf11f, 0xf00d, 0);
+ if (x != 0)
+ abort ();
+
+ x = bics_si_test2 (0xf00d, 0xf11f, 0);
+ if (x != 0)
+ abort ();
+
+ x = bics_si_test2 (0xf11f, 0xf00d, 0);
+ if (x != 0xf00d)
+ abort ();
+
+ y = bics_di_test1 (0x10001000f00dll, 0x12341000f00dll, 0ll);
+ if (y != 0x10001000f00dll)
+ abort ();
+
+ y = bics_di_test1 (0x12341000f00dll, 0x10001000f00dll, 0ll);
+ if (y != 0)
+ abort ();
+
+ y = bics_di_test2 (0x10001000f00dll, 0x12341000f00dll, 0ll);
+ if (y != 0)
+ abort ();
+
+ y = bics_di_test2 (0x12341000f00dll, 0x10001000f00dll, 0ll);
+ if (y != 0x10001000f00dll)
+ abort ();
+
+ return 0;
+}
+
+/* { dg-final { scan-assembler-times "bics\twzr, w\[0-9\]+, w\[0-9\]+" 2 } } */
+/* { dg-final { scan-assembler-times "bics\txzr, x\[0-9\]+, x\[0-9\]+" 2 } } */
+/* { dg-final { cleanup-saved-temps } } */