This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch] reload1.c: Replace sext_for_mode with trunc_int_for_mode.


Hi,

Attached is a patch to replace sext_for_mode with trunc_int_for_mode.

move2add uses sext_for_mode, which sign-extends a given integer to a
specified mode.  This function achieves more widely used
trunc_int_for_mode.  The patch replaces all uses of sext_for_mode with
trunc_int_for_mode.

There is one note, though.  move2add_note_store currently processes
integer sets as well as floating point sets.  Giving SFmode to
trunc_int_for_mode causes an abort, whereas sext_for_mode does not
care.  Since move2add is an optimization for the integer world, the
second hunk from the last causes a register information to be reset if
we see a non-integer set.

Tested on h8300 port.  Testing with newlib and several hundred large
testcases saw no difference in generated code.  OK to apply?

Kazu Hirata

2003-02-27  Kazu Hirata  <kazu at cs dot umass dot edu>

	* reload1.c (sext_for_mode): Remove.
	(reload_cse_move2add): Use trunc_int_for_mode instead of
	sext_for_mode.
	(move2add_note_store): Likewise.
	Reset a register information if we see a set in non-integer
	mode.

Index: reload1.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/reload1.c,v
retrieving revision 1.380
diff -u -r1.380 reload1.c
--- reload1.c	25 Feb 2003 23:19:12 -0000	1.380
+++ reload1.c	27 Feb 2003 06:06:51 -0000
@@ -455,8 +455,6 @@
 static void add_auto_inc_notes		PARAMS ((rtx, rtx));
 #endif
 static void copy_eh_notes		PARAMS ((rtx, rtx));
-static HOST_WIDE_INT sext_for_mode	PARAMS ((enum machine_mode,
-						 HOST_WIDE_INT));
 static void failed_reload		PARAMS ((rtx, int));
 static int set_reload_reg		PARAMS ((int, int));
 static void reload_cse_simplify		PARAMS ((rtx, rtx));
@@ -9084,25 +9082,6 @@
    invalidate all previously collected reg_offset data.  */
 static int move2add_last_label_luid;
 
-/* Generate a CONST_INT and force it in the range of MODE.  */
-
-static HOST_WIDE_INT
-sext_for_mode (mode, value)
-     enum machine_mode mode;
-     HOST_WIDE_INT value;
-{
-  HOST_WIDE_INT cval = value & GET_MODE_MASK (mode);
-  int width = GET_MODE_BITSIZE (mode);
-
-  /* If MODE is narrower than HOST_WIDE_INT and CVAL is a negative number,
-     sign extend it.  */
-  if (width > 0 && width < HOST_BITS_PER_WIDE_INT
-      && (cval & ((HOST_WIDE_INT) 1 << (width - 1))) != 0)
-    cval |= (HOST_WIDE_INT) -1 << width;
-
-  return cval;
-}
-
 /* ??? We don't know how zero / sign extension is handled, hence we
    can't go from a narrower to a wider mode.  */
 #define MODES_OK_FOR_MOVE2ADD(OUTMODE, INMODE) \
@@ -9169,9 +9148,10 @@
 	      if (GET_CODE (src) == CONST_INT && reg_base_reg[regno] < 0)
 		{
 		  int success = 0;
-		  rtx new_src = GEN_INT (sext_for_mode (GET_MODE (reg),
-							INTVAL (src)
-							- reg_offset[regno]));
+		  rtx new_src =
+		    GEN_INT (trunc_int_for_mode (INTVAL (src)
+						 - reg_offset[regno],
+						 GET_MODE (reg)));
 		  /* (set (reg) (plus (reg) (const_int 0))) is not canonical;
 		     use (set (reg) (reg)) instead.
 		     We don't delete this insn, nor do we convert it into a
@@ -9250,10 +9230,11 @@
 		      HOST_WIDE_INT added_offset = INTVAL (src3);
 		      HOST_WIDE_INT base_offset = reg_offset[REGNO (src)];
 		      HOST_WIDE_INT regno_offset = reg_offset[regno];
-		      rtx new_src = GEN_INT (sext_for_mode (GET_MODE (reg),
-							    added_offset
-							    + base_offset
-							    - regno_offset));
+		      rtx new_src =
+			GEN_INT (trunc_int_for_mode (added_offset
+						     + base_offset
+						     - regno_offset,
+						     GET_MODE (reg)));
 		      int success = 0;
 
 		      if (new_src == const0_rtx)
@@ -9270,9 +9251,9 @@
 			delete_insn (insn);
 		      insn = next;
 		      reg_mode[regno] = GET_MODE (reg);
-		      reg_offset[regno] = sext_for_mode (GET_MODE (reg),
-							 added_offset
-							 + base_offset);
+		      reg_offset[regno] =
+			trunc_int_for_mode (added_offset + base_offset,
+					    GET_MODE (reg));
 		      continue;
 		    }
 		}
@@ -9342,7 +9323,8 @@
 
   regno += REGNO (dst);
 
-  if (HARD_REGNO_NREGS (regno, mode) == 1 && GET_CODE (set) == SET
+  if (SCALAR_INT_MODE_P (mode)
+      && HARD_REGNO_NREGS (regno, mode) == 1 && GET_CODE (set) == SET
       && GET_CODE (SET_DEST (set)) != ZERO_EXTRACT
       && GET_CODE (SET_DEST (set)) != SIGN_EXTRACT
       && GET_CODE (SET_DEST (set)) != STRICT_LOW_PART)
@@ -9437,9 +9419,9 @@
       reg_base_reg[regno] = reg_base_reg[base_regno];
 
       /* Compute the sum of the offsets or constants.  */
-      reg_offset[regno] = sext_for_mode (dst_mode,
-					 offset
-					 + reg_offset[base_regno]);
+      reg_offset[regno] = trunc_int_for_mode (offset
+					      + reg_offset[base_regno],
+					      dst_mode);
     }
   else
     {


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]