* [PATCH, AArch64 4.7] Backport of __builtin_bswap16 optimisation
@ 2012-11-23 18:09 Ian Bolton
0 siblings, 0 replies; 3+ messages in thread
From: Ian Bolton @ 2012-11-23 18:09 UTC (permalink / raw)
To: gcc-patches
I had already committed my testcase for this for aarch64, but
it depends on this patch that doesn't yet exist in 4.7, so I
backported to our ARM/aarch64-4.7-branch.
Cheers,
Ian
From:
http://gcc.gnu.org/git/?p=gcc.git;a=commitdiff;h=f811051bf87b1de7804c19c8192
d0d099d157145
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index be34843..ce08fce 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,8 @@
+2012-09-26 Christophe Lyon <christophe.lyon@linaro.org>
+
+ * tree-ssa-math-opts.c (bswap_stats): Add found_16bit field.
+ (execute_optimize_bswap): Add support for builtin_bswap16.
+
2012-09-26 Richard Guenther <rguenther@suse.de>
* tree.h (DECL_IS_BUILTIN): Compare LOCATION_LOCUS.
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 3aad841..7c96949 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,7 @@
+2012-09-26 Christophe Lyon <christophe.lyon@linaro.org>
+
+ * gcc.target/arm/builtin-bswap16-1.c: New testcase.
+
2012-09-25 Segher Boessenkool <segher@kernel.crashing.org>
PR target/51274
diff --git a/gcc/testsuite/gcc.target/arm/builtin-bswap16-1.c
b/gcc/testsuite/gcc.target/arm/builtin-bswap16-1.c
new file mode 100644
index 0000000..6920f00
--- /dev/null
+++ b/gcc/testsuite/gcc.target/arm/builtin-bswap16-1.c
@@ -0,0 +1,15 @@
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+/* { dg-require-effective-target arm_arch_v6_ok } */
+/* { dg-add-options arm_arch_v6 } */
+/* { dg-final { scan-assembler-not "orr\[ \t\]" } } */
+
+unsigned short swapu16_1 (unsigned short x)
+{
+ return (x << 8) | (x >> 8);
+}
+
+unsigned short swapu16_2 (unsigned short x)
+{
+ return (x >> 8) | (x << 8);
+}
diff --git a/gcc/tree-ssa-math-opts.c b/gcc/tree-ssa-math-opts.c
index 16ff397..d9f4e9e 100644
--- a/gcc/tree-ssa-math-opts.c
+++ b/gcc/tree-ssa-math-opts.c
@@ -154,6 +154,9 @@ static struct
static struct
{
+ /* Number of hand-written 16-bit bswaps found. */
+ int found_16bit;
+
/* Number of hand-written 32-bit bswaps found. */
int found_32bit;
@@ -1803,9 +1806,9 @@ static unsigned int
execute_optimize_bswap (void)
{
basic_block bb;
- bool bswap32_p, bswap64_p;
+ bool bswap16_p, bswap32_p, bswap64_p;
bool changed = false;
- tree bswap32_type = NULL_TREE, bswap64_type = NULL_TREE;
+ tree bswap16_type = NULL_TREE, bswap32_type = NULL_TREE, bswap64_type =
NULL_TREE;
if (BITS_PER_UNIT != 8)
return 0;
@@ -1813,17 +1816,25 @@ execute_optimize_bswap (void)
if (sizeof (HOST_WIDEST_INT) < 8)
return 0;
+ bswap16_p = (builtin_decl_explicit_p (BUILT_IN_BSWAP16)
+ && optab_handler (bswap_optab, HImode) != CODE_FOR_nothing);
bswap32_p = (builtin_decl_explicit_p (BUILT_IN_BSWAP32)
&& optab_handler (bswap_optab, SImode) != CODE_FOR_nothing);
bswap64_p = (builtin_decl_explicit_p (BUILT_IN_BSWAP64)
&& (optab_handler (bswap_optab, DImode) != CODE_FOR_nothing
|| (bswap32_p && word_mode == SImode)));
- if (!bswap32_p && !bswap64_p)
+ if (!bswap16_p && !bswap32_p && !bswap64_p)
return 0;
/* Determine the argument type of the builtins. The code later on
assumes that the return and argument type are the same. */
+ if (bswap16_p)
+ {
+ tree fndecl = builtin_decl_explicit (BUILT_IN_BSWAP16);
+ bswap16_type = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (fndecl)));
+ }
+
if (bswap32_p)
{
tree fndecl = builtin_decl_explicit (BUILT_IN_BSWAP32);
@@ -1863,6 +1874,13 @@ execute_optimize_bswap (void)
switch (type_size)
{
+ case 16:
+ if (bswap16_p)
+ {
+ fndecl = builtin_decl_explicit (BUILT_IN_BSWAP16);
+ bswap_type = bswap16_type;
+ }
+ break;
case 32:
if (bswap32_p)
{
@@ -1890,7 +1908,9 @@ execute_optimize_bswap (void)
continue;
changed = true;
- if (type_size == 32)
+ if (type_size == 16)
+ bswap_stats.found_16bit++;
+ else if (type_size == 32)
bswap_stats.found_32bit++;
else
bswap_stats.found_64bit++;
@@ -1935,6 +1955,8 @@ execute_optimize_bswap (void)
}
}
+ statistics_counter_event (cfun, "16-bit bswap implementations found",
+ bswap_stats.found_16bit);
statistics_counter_event (cfun, "32-bit bswap implementations found",
bswap_stats.found_32bit);
statistics_counter_event (cfun, "64-bit bswap implementations found",
^ permalink raw reply [flat|nested] 3+ messages in thread
* RE: [PATCH, AArch64 4.7] Backport of __builtin_bswap16 optimisation
@ 2012-11-30 19:34 Ian Bolton
0 siblings, 0 replies; 3+ messages in thread
From: Ian Bolton @ 2012-11-30 19:34 UTC (permalink / raw)
To: gcc-patches
It turned out that this patch depended on another one from
earlier, so I have backported that to ARM/aarch64-4.7-branch too.
http://gcc.gnu.org/ml/gcc-patches/2012-04/msg00452.html
Cheers,
Ian
> -----Original Message-----
> From: Ian Bolton [mailto:ian.bolton@arm.com]
> Sent: 23 November 2012 18:09
> To: gcc-patches@gcc.gnu.org
> Subject: [PATCH, AArch64 4.7] Backport of __builtin_bswap16
> optimisation
>
> I had already committed my testcase for this for aarch64, but
> it depends on this patch that doesn't yet exist in 4.7, so I
> backported to our ARM/aarch64-4.7-branch.
>
> Cheers,
> Ian
>
>
>
> From:
> http://gcc.gnu.org/git/?p=gcc.git;a=commitdiff;h=f811051bf87b1de7804c19
> c8192d0d099d157145
>
> diff --git a/gcc/ChangeLog b/gcc/ChangeLog
> index be34843..ce08fce 100644
> --- a/gcc/ChangeLog
> +++ b/gcc/ChangeLog
> @@ -1,3 +1,8 @@
> +2012-09-26 Christophe Lyon <christophe.lyon@linaro.org>
> +
> + * tree-ssa-math-opts.c (bswap_stats): Add found_16bit field.
> + (execute_optimize_bswap): Add support for builtin_bswap16.
> +
> 2012-09-26 Richard Guenther <rguenther@suse.de>
>
> * tree.h (DECL_IS_BUILTIN): Compare LOCATION_LOCUS.
> diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
> index 3aad841..7c96949 100644
> --- a/gcc/testsuite/ChangeLog
> +++ b/gcc/testsuite/ChangeLog
> @@ -1,3 +1,7 @@
> +2012-09-26 Christophe Lyon <christophe.lyon@linaro.org>
> +
> + * gcc.target/arm/builtin-bswap16-1.c: New testcase.
> +
> 2012-09-25 Segher Boessenkool <segher@kernel.crashing.org>
>
> PR target/51274
> diff --git a/gcc/testsuite/gcc.target/arm/builtin-bswap16-1.c
> b/gcc/testsuite/gcc.target/arm/builtin-bswap16-1.c
> new file mode 100644
> index 0000000..6920f00
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/arm/builtin-bswap16-1.c
> @@ -0,0 +1,15 @@
> +/* { dg-do compile } */
> +/* { dg-options "-O2" } */
> +/* { dg-require-effective-target arm_arch_v6_ok } */
> +/* { dg-add-options arm_arch_v6 } */
> +/* { dg-final { scan-assembler-not "orr\[ \t\]" } } */
> +
> +unsigned short swapu16_1 (unsigned short x)
> +{
> + return (x << 8) | (x >> 8);
> +}
> +
> +unsigned short swapu16_2 (unsigned short x)
> +{
> + return (x >> 8) | (x << 8);
> +}
> diff --git a/gcc/tree-ssa-math-opts.c b/gcc/tree-ssa-math-opts.c
> index 16ff397..d9f4e9e 100644
> --- a/gcc/tree-ssa-math-opts.c
> +++ b/gcc/tree-ssa-math-opts.c
> @@ -154,6 +154,9 @@ static struct
>
> static struct
> {
> + /* Number of hand-written 16-bit bswaps found. */
> + int found_16bit;
> +
> /* Number of hand-written 32-bit bswaps found. */
> int found_32bit;
>
> @@ -1803,9 +1806,9 @@ static unsigned int
> execute_optimize_bswap (void)
> {
> basic_block bb;
> - bool bswap32_p, bswap64_p;
> + bool bswap16_p, bswap32_p, bswap64_p;
> bool changed = false;
> - tree bswap32_type = NULL_TREE, bswap64_type = NULL_TREE;
> + tree bswap16_type = NULL_TREE, bswap32_type = NULL_TREE,
> bswap64_type = NULL_TREE;
>
> if (BITS_PER_UNIT != 8)
> return 0;
> @@ -1813,17 +1816,25 @@ execute_optimize_bswap (void)
> if (sizeof (HOST_WIDEST_INT) < 8)
> return 0;
>
> + bswap16_p = (builtin_decl_explicit_p (BUILT_IN_BSWAP16)
> + && optab_handler (bswap_optab, HImode) !=
> CODE_FOR_nothing);
> bswap32_p = (builtin_decl_explicit_p (BUILT_IN_BSWAP32)
> && optab_handler (bswap_optab, SImode) !=
> CODE_FOR_nothing);
> bswap64_p = (builtin_decl_explicit_p (BUILT_IN_BSWAP64)
> && (optab_handler (bswap_optab, DImode) !=
> CODE_FOR_nothing
> || (bswap32_p && word_mode == SImode)));
>
> - if (!bswap32_p && !bswap64_p)
> + if (!bswap16_p && !bswap32_p && !bswap64_p)
> return 0;
>
> /* Determine the argument type of the builtins. The code later on
> assumes that the return and argument type are the same. */
> + if (bswap16_p)
> + {
> + tree fndecl = builtin_decl_explicit (BUILT_IN_BSWAP16);
> + bswap16_type = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (fndecl)));
> + }
> +
> if (bswap32_p)
> {
> tree fndecl = builtin_decl_explicit (BUILT_IN_BSWAP32);
> @@ -1863,6 +1874,13 @@ execute_optimize_bswap (void)
>
> switch (type_size)
> {
> + case 16:
> + if (bswap16_p)
> + {
> + fndecl = builtin_decl_explicit (BUILT_IN_BSWAP16);
> + bswap_type = bswap16_type;
> + }
> + break;
> case 32:
> if (bswap32_p)
> {
> @@ -1890,7 +1908,9 @@ execute_optimize_bswap (void)
> continue;
>
> changed = true;
> - if (type_size == 32)
> + if (type_size == 16)
> + bswap_stats.found_16bit++;
> + else if (type_size == 32)
> bswap_stats.found_32bit++;
> else
> bswap_stats.found_64bit++;
> @@ -1935,6 +1955,8 @@ execute_optimize_bswap (void)
> }
> }
>
> + statistics_counter_event (cfun, "16-bit bswap implementations
> found",
> + bswap_stats.found_16bit);
> statistics_counter_event (cfun, "32-bit bswap implementations
> found",
> bswap_stats.found_32bit);
> statistics_counter_event (cfun, "64-bit bswap implementations
> found",
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH, AArch64 4.7] Backport of __builtin_bswap16 optimisation
[not found] <50afbbe2.81fb440a.0470.5facSMTPIN_ADDED_BROKEN@mx.google.com>
@ 2012-11-23 23:47 ` Marcus Shawcroft
0 siblings, 0 replies; 3+ messages in thread
From: Marcus Shawcroft @ 2012-11-23 23:47 UTC (permalink / raw)
To: Ian Bolton; +Cc: <gcc-patches@gcc.gnu.org>
On 23 Nov 2012, at 18:09, "Ian Bolton" <ian.bolton@arm.com> wrote:
I had already committed my testcase for this for aarch64, but
it depends on this patch that doesn't yet exist in 4.7, so I
backported to our ARM/aarch64-4.7-branch.
Cheers,
Ian
This commit breaks the build, reverted.
/Marcus
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2012-11-30 19:13 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-11-23 18:09 [PATCH, AArch64 4.7] Backport of __builtin_bswap16 optimisation Ian Bolton
[not found] <50afbbe2.81fb440a.0470.5facSMTPIN_ADDED_BROKEN@mx.google.com>
2012-11-23 23:47 ` Marcus Shawcroft
2012-11-30 19:34 Ian Bolton
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).