Since 16bit byteswap can be done via an 8 bit rotation (and it is the canonical 
form),
the check for an optab only serves to prevent the bswap optimization for
targets that don't have a 16bit byteswap (but do have a rotation instruction). 
See
PR63259 (comments 6 and onwards) for more details.

ChangeLog entry is as follows:

2014-12-24  Thomas Preud'homme  thomas.preudho...@arm.com

PR tree-optimization/63259
* tree-ssa-math-opts.c (pass_optimize_bswap::execute): Stop checking
if optab exists for 16bit byteswap.


diff --git a/gcc/tree-ssa-math-opts.c b/gcc/tree-ssa-math-opts.c
index 1ed2838..c175e88 100644
--- a/gcc/tree-ssa-math-opts.c
+++ b/gcc/tree-ssa-math-opts.c
@@ -2350,15 +2350,13 @@ unsigned int
 pass_optimize_bswap::execute (function *fun)
 {
   basic_block bb;
-  bool bswap16_p, bswap32_p, bswap64_p;
+  bool bswap32_p, bswap64_p;
   bool changed = false;
-  tree bswap16_type = NULL_TREE, bswap32_type = NULL_TREE, bswap64_type = 
NULL_TREE;
+  tree bswap32_type = NULL_TREE, bswap64_type = NULL_TREE;
 
   if (BITS_PER_UNIT != 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)
@@ -2367,12 +2365,6 @@ pass_optimize_bswap::execute (function *fun)
 
   /* 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);
@@ -2443,11 +2435,6 @@ pass_optimize_bswap::execute (function *fun)
              if (code == LROTATE_EXPR || code == RROTATE_EXPR)
                continue;
              load_type = uint16_type_node;
-             if (bswap16_p)
-               {
-                 fndecl = builtin_decl_explicit (BUILT_IN_BSWAP16);
-                 bswap_type = bswap16_type;
-               }
              break;
            case 32:
              load_type = uint32_type_node;
@@ -2469,7 +2456,7 @@ pass_optimize_bswap::execute (function *fun)
              continue;
            }
 
-         if (bswap && !fndecl)
+         if (bswap && !fndecl && n.range != 16)
            continue;
 
          if (bswap_replace (cur_stmt, src_stmt, fndecl, bswap_type, load_type,

Bootstrapped on x86_64-linux-gnu and aarch64-none-linux-gnu without any
testsuite regression

Is this ok for trunk?

Best regards,

Thomas



Reply via email to