From: Jakub Jelinek Date: Fri, 8 Oct 2010 20:49:19 +0000 (+0200) Subject: re PR rtl-optimization/45903 (unnecessary load of 32/64bit variable when only 8 bits... X-Git-Tag: releases/gcc-4.6.0~3720 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=509dd3804c49658b31dbdae676979e95e7ecd8cb;p=thirdparty%2Fgcc.git re PR rtl-optimization/45903 (unnecessary load of 32/64bit variable when only 8 bits are needed) PR tree-optimization/45903 * simplify-rtx.c (simplify_subreg): Optimize lowpart SUBREG of *SHIFTRT of MEM. * gcc.target/i386/pr45903.c: New test. From-SVN: r165200 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index be4f9f795cf6..182337f101b3 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2010-10-08 Jakub Jelinek + + PR tree-optimization/45903 + * simplify-rtx.c (simplify_subreg): Optimize lowpart SUBREG + of *SHIFTRT of MEM. + 2010-10-08 Richard Guenther * lto-streamer-in.c (lto_input_ts_decl_minimal_tree_pointers): diff --git a/gcc/simplify-rtx.c b/gcc/simplify-rtx.c index 122c45fdf647..ff1437be41bd 100644 --- a/gcc/simplify-rtx.c +++ b/gcc/simplify-rtx.c @@ -5482,6 +5482,31 @@ simplify_subreg (enum machine_mode outermode, rtx op, : byte + shifted_bytes)); } + /* If we have a lowpart SUBREG of a right shift of MEM, make a new MEM + and try replacing the SUBREG and shift with it. Don't do this if + the MEM has a mode-dependent address or if we would be widening it. */ + + if ((GET_CODE (op) == LSHIFTRT + || GET_CODE (op) == ASHIFTRT) + && MEM_P (XEXP (op, 0)) + && CONST_INT_P (XEXP (op, 1)) + && GET_MODE_SIZE (outermode) < GET_MODE_SIZE (GET_MODE (op)) + && (INTVAL (XEXP (op, 1)) % GET_MODE_BITSIZE (outermode)) == 0 + && INTVAL (XEXP (op, 1)) > 0 + && INTVAL (XEXP (op, 1)) < GET_MODE_BITSIZE (innermode) + && ! mode_dependent_address_p (XEXP (XEXP (op, 0), 0)) + && ! MEM_VOLATILE_P (XEXP (op, 0)) + && byte == subreg_lowpart_offset (outermode, innermode) + && (GET_MODE_SIZE (outermode) >= UNITS_PER_WORD + || WORDS_BIG_ENDIAN == BYTES_BIG_ENDIAN)) + { + int shifted_bytes = INTVAL (XEXP (op, 1)) / BITS_PER_UNIT; + return adjust_address_nv (XEXP (op, 0), outermode, + (WORDS_BIG_ENDIAN + ? byte - shifted_bytes + : byte + shifted_bytes)); + } + return NULL_RTX; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 0c4fb410ea85..dd23413753da 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2010-10-08 Jakub Jelinek + + PR tree-optimization/45903 + * gcc.target/i386/pr45903.c: New test. + 2010-10-08 Arnaud Charlet * gnat.dg/interface5.adb: Compile with warnings disabled.