From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28265 invoked by alias); 23 Nov 2012 18:09:34 -0000 Received: (qmail 28254 invoked by uid 22791); 23 Nov 2012 18:09:31 -0000 X-SWARE-Spam-Status: No, hits=-1.1 required=5.0 tests=AWL,BAYES_00,KHOP_RCVD_UNTRUST,MSGID_MULTIPLE_AT,RCVD_IN_DNSWL_LOW,TW_FN X-Spam-Check-By: sourceware.org Received: from service87.mimecast.com (HELO service87.mimecast.com) (91.220.42.44) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 23 Nov 2012 18:09:25 +0000 Received: from cam-owa1.Emea.Arm.com (fw-tnat.cambridge.arm.com [217.140.96.21]) by service87.mimecast.com; Fri, 23 Nov 2012 18:09:22 +0000 Received: from E102352xp ([10.1.255.212]) by cam-owa1.Emea.Arm.com with Microsoft SMTPSVC(6.0.3790.0); Fri, 23 Nov 2012 18:09:20 +0000 From: "Ian Bolton" To: Subject: [PATCH, AArch64 4.7] Backport of __builtin_bswap16 optimisation Date: Fri, 23 Nov 2012 18:09:00 -0000 Message-ID: <000001cdc9a5$a2c775a0$e85660e0$@bolton@arm.com> MIME-Version: 1.0 X-MC-Unique: 112112318092206101 Content-Type: text/plain; charset=WINDOWS-1252 Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org X-SW-Source: 2012-11/txt/msg01964.txt.bz2 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=3Dgcc.git;a=3Dcommitdiff;h=3Df811051bf87b1de7804c= 19c8192 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 + + * tree-ssa-math-opts.c (bswap_stats): Add found_16bit field. + (execute_optimize_bswap): Add support for builtin_bswap16. + 2012-09-26 Richard Guenther =20 * 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 + + * gcc.target/arm/builtin-bswap16-1.c: New testcase. + 2012-09-25 Segher Boessenkool =20 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 =20 static struct { + /* Number of hand-written 16-bit bswaps found. */ + int found_16bit; + /* Number of hand-written 32-bit bswaps found. */ int found_32bit; =20 @@ -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 =3D false; - tree bswap32_type =3D NULL_TREE, bswap64_type =3D NULL_TREE; + tree bswap16_type =3D NULL_TREE, bswap32_type =3D NULL_TREE, bswap64_typ= e =3D NULL_TREE; =20 if (BITS_PER_UNIT !=3D 8) return 0; @@ -1813,17 +1816,25 @@ execute_optimize_bswap (void) if (sizeof (HOST_WIDEST_INT) < 8) return 0; =20 + bswap16_p =3D (builtin_decl_explicit_p (BUILT_IN_BSWAP16) + && optab_handler (bswap_optab, HImode) !=3D CODE_FOR_nothing); bswap32_p =3D (builtin_decl_explicit_p (BUILT_IN_BSWAP32) && optab_handler (bswap_optab, SImode) !=3D CODE_FOR_nothing); bswap64_p =3D (builtin_decl_explicit_p (BUILT_IN_BSWAP64) && (optab_handler (bswap_optab, DImode) !=3D CODE_FOR_nothing || (bswap32_p && word_mode =3D=3D SImode))); =20 - if (!bswap32_p && !bswap64_p) + if (!bswap16_p && !bswap32_p && !bswap64_p) return 0; =20 /* 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 =3D builtin_decl_explicit (BUILT_IN_BSWAP16); + bswap16_type =3D TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (fndecl))); + } + if (bswap32_p) { tree fndecl =3D builtin_decl_explicit (BUILT_IN_BSWAP32); @@ -1863,6 +1874,13 @@ execute_optimize_bswap (void) =20 switch (type_size) { + case 16: + if (bswap16_p) + { + fndecl =3D builtin_decl_explicit (BUILT_IN_BSWAP16); + bswap_type =3D bswap16_type; + } + break; case 32: if (bswap32_p) { @@ -1890,7 +1908,9 @@ execute_optimize_bswap (void) continue; =20 changed =3D true; - if (type_size =3D=3D 32) + if (type_size =3D=3D 16) + bswap_stats.found_16bit++; + else if (type_size =3D=3D 32) bswap_stats.found_32bit++; else bswap_stats.found_64bit++; @@ -1935,6 +1955,8 @@ execute_optimize_bswap (void) } } =20 + 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",