simplify-rtx.c (simplify_subreg): Remove useless shifts from word-extractions out...
authorPaolo Bonzini <bonzini@gnu.org>
Thu, 6 Mar 2008 13:30:10 +0000 (13:30 +0000)
committerPaolo Bonzini <bonzini@gcc.gnu.org>
Thu, 6 Mar 2008 13:30:10 +0000 (13:30 +0000)
2008-03-06  Paolo Bonzini  <bonzini@gnu.org>

* simplify-rtx.c (simplify_subreg): Remove useless shifts from
word-extractions out of a multi-word object.

From-SVN: r132971

gcc/ChangeLog
gcc/simplify-rtx.c

index 62d7822121499795cee198f21cd032265049f423..f2d65ad415f04870ae2a377937ae3e0b263897e1 100644 (file)
@@ -1,3 +1,8 @@
+2008-03-06  Paolo Bonzini  <bonzini@gnu.org>
+
+       * simplify-rtx.c (simplify_subreg): Remove useless shifts from
+       word-extractions out of a multi-word object.
+
 2008-03-06  Richard Guenther  <rguenther@suse.de>
 
        * tree.def (BIT_FIELD_REF): Constrain result type and its precision.
index 34392dce48a92cc305e0e2b5dacbefa2043b31c6..44f3ef574731cf4e9fc703f6c8d4400148cabb54 100644 (file)
@@ -5239,6 +5239,22 @@ simplify_subreg (enum machine_mode outermode, rtx op,
     return simplify_gen_binary (ASHIFT, outermode,
                                XEXP (XEXP (op, 0), 0), XEXP (op, 1));
 
+  /* Recognize a word extraction from a multi-word subreg.  */
+  if ((GET_CODE (op) == LSHIFTRT
+       || GET_CODE (op) == ASHIFTRT)
+      && SCALAR_INT_MODE_P (outermode)
+      && GET_MODE_BITSIZE (outermode) >= BITS_PER_WORD
+      && GET_MODE_BITSIZE (innermode) >= (2 * GET_MODE_BITSIZE (outermode))
+      && GET_CODE (XEXP (op, 1)) == CONST_INT
+      && (INTVAL (XEXP (op, 1)) & (GET_MODE_BITSIZE (outermode) - 1)) == 0
+      && byte == subreg_lowpart_offset (outermode, innermode))
+    {
+      int shifted_bytes = INTVAL (XEXP (op, 1)) / BITS_PER_UNIT;
+      return simplify_gen_subreg (outermode, XEXP (op, 0), innermode,
+                                 (WORDS_BIG_ENDIAN
+                                  ? byte - shifted_bytes : byte + shifted_bytes));
+    }
+
   return NULL_RTX;
 }