From: wilco Date: Tue, 28 Jun 2016 13:57:47 +0000 (+0000) Subject: This patch fixes a bug in the bswap pass. In big-endian BIT_FIELD_REF uses X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=e5c957b427075452786ddd4fda684fd27cffafc0;p=thirdparty%2Fgcc.git This patch fixes a bug in the bswap pass. In big-endian BIT_FIELD_REF uses big-endian bit numbering so we need to adjust the bit position. The existing version could potentially generate incorrect code however GCC doesn't emit a BIT_FIELD_REF to access the low byte in a register, so the symbolic number never matches in big-endian. gcc/ * tree-ssa-math-opts.c (find_bswap_or_nop_1): Adjust bitnumbering for big-endian BIT_FIELD_REF. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@237822 138bc75d-0d04-0410-961f-82ee72b054a4 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index f88c40470e31..d9d41ad9ec1c 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2016-06-28 Wilco Dijkstra + + * tree-ssa-math-opts.c (find_bswap_or_nop_1): Adjust bitnumbering + for big-endian BIT_FIELD_REF. + 2016-06-28 Pat Haugen * config/rs6000/rs6000.md ('type' attribute): Add htmsimple/dfp types. diff --git a/gcc/tree-ssa-math-opts.c b/gcc/tree-ssa-math-opts.c index 513ef0b3f4eb..d31c12fd818a 100644 --- a/gcc/tree-ssa-math-opts.c +++ b/gcc/tree-ssa-math-opts.c @@ -2307,6 +2307,10 @@ find_bswap_or_nop_1 (gimple *stmt, struct symbolic_number *n, int limit) && bitsize % BITS_PER_UNIT == 0 && init_symbolic_number (n, TREE_OPERAND (rhs1, 0))) { + /* Handle big-endian bit numbering in BIT_FIELD_REF. */ + if (BYTES_BIG_ENDIAN) + bitpos = TYPE_PRECISION (n->type) - bitpos - bitsize; + /* Shift. */ if (!do_shift_rotate (RSHIFT_EXPR, n, bitpos)) return NULL;