aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorKyrylo Tkachov <kyrylo.tkachov@arm.com>2016-11-08 16:04:20 +0000
committerKyrylo Tkachov <ktkachov@gcc.gnu.org>2016-11-08 16:04:20 +0000
commitc22d8787165e1d8f835bfc3a5e5802c286ace31a (patch)
treef87abbe64a4b0d2286f097cc546392dda1375be9 /gcc
parentfad3660129f9fc5563eb2f877598a3cd5269b72a (diff)
downloadgcc-c22d8787165e1d8f835bfc3a5e5802c286ace31a.zip
gcc-c22d8787165e1d8f835bfc3a5e5802c286ace31a.tar.gz
gcc-c22d8787165e1d8f835bfc3a5e5802c286ace31a.tar.bz2
[2/2] Add store merging unit tests
* gimple-ssa-store-merging.c: Include selftest.h (verify_array_eq): New function. (verify_shift_bytes_in_array): Likewise. (verify_shift_bytes_in_array_right): Likewise. (verify_clear_bit_region): Likewise. (verify_clear_bit_region_be): Likewise. (store_merging_c_tests): Likewise. * selftest.h (store_merging_c_tests): Declare prototype. * selftest-run-tests.c (selftest::run_tests): Run store_merging_c_tests. From-SVN: r241971
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog13
-rw-r--r--gcc/gimple-ssa-store-merging.c139
-rw-r--r--gcc/selftest-run-tests.c2
-rw-r--r--gcc/selftest.h1
4 files changed, 155 insertions, 0 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 926197e..09889f9 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,5 +1,18 @@
2016-11-08 Kyrylo Tkachov <kyrylo.tkachov@arm.com>
+ * gimple-ssa-store-merging.c: Include selftest.h
+ (verify_array_eq): New function.
+ (verify_shift_bytes_in_array): Likewise.
+ (verify_shift_bytes_in_array_right): Likewise.
+ (verify_clear_bit_region): Likewise.
+ (verify_clear_bit_region_be): Likewise.
+ (store_merging_c_tests): Likewise.
+ * selftest.h (store_merging_c_tests): Declare prototype.
+ * selftest-run-tests.c (selftest::run_tests): Run
+ store_merging_c_tests.
+
+2016-11-08 Kyrylo Tkachov <kyrylo.tkachov@arm.com>
+
* config/arm/arm.opt (mold-rtx-costs): Delete.
(mnew-generic-costs): Delete.
* config/arm/arm-protos.h (struct tune_params): Delete rtx_costs field.
diff --git a/gcc/gimple-ssa-store-merging.c b/gcc/gimple-ssa-store-merging.c
index 727ed9f..bd9ba28 100644
--- a/gcc/gimple-ssa-store-merging.c
+++ b/gcc/gimple-ssa-store-merging.c
@@ -126,6 +126,7 @@
#include "tree-eh.h"
#include "target.h"
#include "gimplify-me.h"
+#include "selftest.h"
/* The maximum size (in bits) of the stores this pass should generate. */
#define MAX_STORE_BITSIZE (BITS_PER_WORD)
@@ -1501,3 +1502,141 @@ make_pass_store_merging (gcc::context *ctxt)
{
return new pass_store_merging (ctxt);
}
+
+#if CHECKING_P
+
+namespace selftest {
+
+/* Selftests for store merging helpers. */
+
+/* Assert that all elements of the byte arrays X and Y, both of length N
+ are equal. */
+
+static void
+verify_array_eq (unsigned char *x, unsigned char *y, unsigned int n)
+{
+ for (unsigned int i = 0; i < n; i++)
+ {
+ if (x[i] != y[i])
+ {
+ fprintf (stderr, "Arrays do not match. X:\n");
+ dump_char_array (stderr, x, n);
+ fprintf (stderr, "Y:\n");
+ dump_char_array (stderr, y, n);
+ }
+ ASSERT_EQ (x[i], y[i]);
+ }
+}
+
+/* Test shift_bytes_in_array and that it carries bits across between
+ bytes correctly. */
+
+static void
+verify_shift_bytes_in_array (void)
+{
+ /* byte 1 | byte 0
+ 00011111 | 11100000. */
+ unsigned char orig[2] = { 0xe0, 0x1f };
+ unsigned char in[2];
+ memcpy (in, orig, sizeof orig);
+
+ unsigned char expected[2] = { 0x80, 0x7f };
+ shift_bytes_in_array (in, sizeof (in), 2);
+ verify_array_eq (in, expected, sizeof (in));
+
+ memcpy (in, orig, sizeof orig);
+ memcpy (expected, orig, sizeof orig);
+ /* Check that shifting by zero doesn't change anything. */
+ shift_bytes_in_array (in, sizeof (in), 0);
+ verify_array_eq (in, expected, sizeof (in));
+
+}
+
+/* Test shift_bytes_in_array_right and that it carries bits across between
+ bytes correctly. */
+
+static void
+verify_shift_bytes_in_array_right (void)
+{
+ /* byte 1 | byte 0
+ 00011111 | 11100000. */
+ unsigned char orig[2] = { 0x1f, 0xe0};
+ unsigned char in[2];
+ memcpy (in, orig, sizeof orig);
+ unsigned char expected[2] = { 0x07, 0xf8};
+ shift_bytes_in_array_right (in, sizeof (in), 2);
+ verify_array_eq (in, expected, sizeof (in));
+
+ memcpy (in, orig, sizeof orig);
+ memcpy (expected, orig, sizeof orig);
+ /* Check that shifting by zero doesn't change anything. */
+ shift_bytes_in_array_right (in, sizeof (in), 0);
+ verify_array_eq (in, expected, sizeof (in));
+}
+
+/* Test clear_bit_region that it clears exactly the bits asked and
+ nothing more. */
+
+static void
+verify_clear_bit_region (void)
+{
+ /* Start with all bits set and test clearing various patterns in them. */
+ unsigned char orig[3] = { 0xff, 0xff, 0xff};
+ unsigned char in[3];
+ unsigned char expected[3];
+ memcpy (in, orig, sizeof in);
+
+ /* Check zeroing out all the bits. */
+ clear_bit_region (in, 0, 3 * BITS_PER_UNIT);
+ expected[0] = expected[1] = expected[2] = 0;
+ verify_array_eq (in, expected, sizeof in);
+
+ memcpy (in, orig, sizeof in);
+ /* Leave the first and last bits intact. */
+ clear_bit_region (in, 1, 3 * BITS_PER_UNIT - 2);
+ expected[0] = 0x1;
+ expected[1] = 0;
+ expected[2] = 0x80;
+ verify_array_eq (in, expected, sizeof in);
+}
+
+/* Test verify_clear_bit_region_be that it clears exactly the bits asked and
+ nothing more. */
+
+static void
+verify_clear_bit_region_be (void)
+{
+ /* Start with all bits set and test clearing various patterns in them. */
+ unsigned char orig[3] = { 0xff, 0xff, 0xff};
+ unsigned char in[3];
+ unsigned char expected[3];
+ memcpy (in, orig, sizeof in);
+
+ /* Check zeroing out all the bits. */
+ clear_bit_region_be (in, BITS_PER_UNIT - 1, 3 * BITS_PER_UNIT);
+ expected[0] = expected[1] = expected[2] = 0;
+ verify_array_eq (in, expected, sizeof in);
+
+ memcpy (in, orig, sizeof in);
+ /* Leave the first and last bits intact. */
+ clear_bit_region_be (in, BITS_PER_UNIT - 2, 3 * BITS_PER_UNIT - 2);
+ expected[0] = 0x80;
+ expected[1] = 0;
+ expected[2] = 0x1;
+ verify_array_eq (in, expected, sizeof in);
+}
+
+
+/* Run all of the selftests within this file. */
+
+void
+store_merging_c_tests (void)
+{
+ verify_shift_bytes_in_array ();
+ verify_shift_bytes_in_array_right ();
+ verify_clear_bit_region ();
+ verify_clear_bit_region_be ();
+}
+
+} // namespace selftest
+#endif /* CHECKING_P. */
diff --git a/gcc/selftest-run-tests.c b/gcc/selftest-run-tests.c
index 76532af..a4cdb55 100644
--- a/gcc/selftest-run-tests.c
+++ b/gcc/selftest-run-tests.c
@@ -82,6 +82,8 @@ selftest::run_tests ()
if (targetm.run_target_selftests)
targetm.run_target_selftests ();
+ store_merging_c_tests ();
+
/* Run any lang-specific selftests. */
lang_hooks.run_lang_selftests ();
diff --git a/gcc/selftest.h b/gcc/selftest.h
index 845eb01..dcce474 100644
--- a/gcc/selftest.h
+++ b/gcc/selftest.h
@@ -179,6 +179,7 @@ extern void selftest_c_tests ();
extern void spellcheck_c_tests ();
extern void spellcheck_tree_c_tests ();
extern void sreal_c_tests ();
+extern void store_merging_c_tests ();
extern void typed_splay_tree_c_tests ();
extern void tree_c_tests ();
extern void tree_cfg_c_tests ();