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