diff options
author | Jakub Jelinek <jakub@redhat.com> | 2010-10-08 22:49:19 +0200 |
---|---|---|
committer | Jakub Jelinek <jakub@gcc.gnu.org> | 2010-10-08 22:49:19 +0200 |
commit | 509dd3804c49658b31dbdae676979e95e7ecd8cb (patch) | |
tree | 132af12e172f41cd9faf29bd32999c04ed39e7ec /gcc/simplify-rtx.c | |
parent | 0fd76d8e4c34b647eec8fcd7c8b797b8559301e0 (diff) | |
download | gcc-509dd3804c49658b31dbdae676979e95e7ecd8cb.tar.gz |
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
Diffstat (limited to 'gcc/simplify-rtx.c')
-rw-r--r-- | gcc/simplify-rtx.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/gcc/simplify-rtx.c b/gcc/simplify-rtx.c index 122c45fdf64..ff1437be41b 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; } |