Hi! The case ASHIFTRT: which is meant for this optimization is preceeded by /* FALLTHRU */ from ROTATE cases, which can't be optimized this way. Thus, this patch limits this optimization to ASHIFTRT.
Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2014-11-18 Jakub Jelinek <ja...@redhat.com> PR rtl-optimization/63843 * simplify-rtx.c (simplify_binary_operation_1) <case ASHIFTRT>: For optimization of ashiftrt of subreg of lshiftrt, check that code is ASHIFTRT. * gcc.c-torture/execute/pr63843.c: New test. --- gcc/simplify-rtx.c.jj 2014-11-18 10:17:01.000000000 +0100 +++ gcc/simplify-rtx.c 2014-11-18 13:44:26.727792683 +0100 @@ -3118,10 +3118,11 @@ simplify_binary_operation_1 (enum rtx_co (subreg:M1 (ashiftrt:M2 (reg:M2) (const_int <c1 + c2>)) <low_part>). */ - if (!VECTOR_MODE_P (mode) + if (code == ASHIFTRT + && !VECTOR_MODE_P (mode) && SUBREG_P (op0) && CONST_INT_P (op1) - && (GET_CODE (SUBREG_REG (op0)) == LSHIFTRT) + && GET_CODE (SUBREG_REG (op0)) == LSHIFTRT && !VECTOR_MODE_P (GET_MODE (SUBREG_REG (op0))) && CONST_INT_P (XEXP (SUBREG_REG (op0), 1)) && (GET_MODE_BITSIZE (GET_MODE (SUBREG_REG (op0))) --- gcc/testsuite/gcc.c-torture/execute/pr63843.c.jj 2014-11-18 13:43:45.417544096 +0100 +++ gcc/testsuite/gcc.c-torture/execute/pr63843.c 2014-11-18 13:43:32.000000000 +0100 @@ -0,0 +1,31 @@ +/* PR rtl-optimization/63843 */ + +static inline __attribute__ ((always_inline)) +unsigned short foo (unsigned short v) +{ + return (v << 8) | (v >> 8); +} + +unsigned short __attribute__ ((noinline, noclone, hot)) +bar (unsigned char *x) +{ + unsigned int a; + unsigned short b; + __builtin_memcpy (&a, &x[0], sizeof (a)); + a ^= 0x80808080U; + __builtin_memcpy (&x[0], &a, sizeof (a)); + __builtin_memcpy (&b, &x[2], sizeof (b)); + return foo (b); +} + +int +main () +{ + unsigned char x[8] = { 0x01, 0x01, 0x01, 0x01 }; + if (__CHAR_BIT__ == 8 + && sizeof (short) == 2 + && sizeof (int) == 4 + && bar (x) != 0x8181U) + __builtin_abort (); + return 0; +} Jakub