This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Fix PR63259: bswap not recognized when finishing with rotation


On Wed, Oct 08, 2014 at 09:56:51AM +0800, Thomas Preud'homme wrote:
> --- a/gcc/tree-ssa-math-opts.c
> +++ b/gcc/tree-ssa-math-opts.c
> @@ -2377,11 +2377,16 @@ pass_optimize_bswap::execute (function *fun)
>          {
>  	  gimple src_stmt, cur_stmt = gsi_stmt (gsi);
>  	  tree fndecl = NULL_TREE, bswap_type = NULL_TREE, load_type;
> +	  enum tree_code code;
>  	  struct symbolic_number n;
>  	  bool bswap;
>  
> -	  if (!is_gimple_assign (cur_stmt)
> -	      || gimple_assign_rhs_code (cur_stmt) != BIT_IOR_EXPR)
> +	  if (!is_gimple_assign (cur_stmt))
> +	    continue;
> +
> +	  code = gimple_assign_rhs_code (cur_stmt);
> +	  if (code != BIT_IOR_EXPR && code != LROTATE_EXPR
> +	      && code != RROTATE_EXPR)
>  	    continue;
>  
>  	  src_stmt = find_bswap_or_nop (cur_stmt, &n, &bswap);

Doesn't it turn 16-bit {L,R}ROTATE_EXPR used alone into __builtin_bswap16?
For those the question is if the canonical GIMPLE should be the rotation or
byteswap, I'd think rotation would be perhaps better.  Or depending on if
the backend has bswaphi2 or rotate pattern?

Also, perhaps you could short-circuit this if the rotation isn't by constant
or not a multiple of BITS_PER_UNIT.  So
	  switch (code)
	    {
	    case BIT_IOR_EXPR:
	      break;
	    case LROTATE_EXPR:
	    case RROTATE_EXPR:
	      if (!tree_fits_uhwi_p (gimple_assign_rhs2 (cur_stmt))
		  || (tree_to_uhwi (gimple_assign_rhs2 (cur_stmt))
		      % BITS_PER_UNIT))
		continue;
	      break;
	    default:
	      continue;
	    }
?    

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]