diff mbox series

[11/nn] Add narrower_subreg_mode helper function

Message ID 87lgk2w1in.fsf@linaro.org
State New
Headers show
Series [11/nn] Add narrower_subreg_mode helper function | expand

Commit Message

Richard Sandiford Oct. 23, 2017, 11:24 a.m. UTC
This patch adds a narrowing equivalent of wider_subreg_mode.  At present
there is only one user.


2017-10-23  Richard Sandiford  <richard.sandiford@linaro.org>
	    Alan Hayward  <alan.hayward@arm.com>
	    David Sherwood  <david.sherwood@arm.com>

gcc/
	* rtl.h (narrower_subreg_mode): New function.
	* ira-color.c (update_costs_from_allocno): Use it.

Comments

Jeff Law Oct. 30, 2017, 3:03 p.m. UTC | #1
On 10/23/2017 05:24 AM, Richard Sandiford wrote:
> This patch adds a narrowing equivalent of wider_subreg_mode.  At present

> there is only one user.

> 

> 

> 2017-10-23  Richard Sandiford  <richard.sandiford@linaro.org>

> 	    Alan Hayward  <alan.hayward@arm.com>

> 	    David Sherwood  <david.sherwood@arm.com>

> 

> gcc/

> 	* rtl.h (narrower_subreg_mode): New function.

> 	* ira-color.c (update_costs_from_allocno): Use it.

OK.  I'm going to assume further uses will show up :-)

jeff
diff mbox series

Patch

Index: gcc/rtl.h
===================================================================
--- gcc/rtl.h	2017-10-23 11:44:06.562686090 +0100
+++ gcc/rtl.h	2017-10-23 11:44:15.916785881 +0100
@@ -2972,6 +2972,16 @@  subreg_lowpart_offset (machine_mode oute
 }
 
 /* Given that a subreg has outer mode OUTERMODE and inner mode INNERMODE,
+   return the smaller of the two modes if they are different sizes,
+   otherwise return the outer mode.  */
+
+inline machine_mode
+narrower_subreg_mode (machine_mode outermode, machine_mode innermode)
+{
+  return paradoxical_subreg_p (outermode, innermode) ? innermode : outermode;
+}
+
+/* Given that a subreg has outer mode OUTERMODE and inner mode INNERMODE,
    return the mode that is big enough to hold both the outer and inner
    values.  Prefer the outer mode in the event of a tie.  */
 
Index: gcc/ira-color.c
===================================================================
--- gcc/ira-color.c	2017-10-23 11:44:11.500538024 +0100
+++ gcc/ira-color.c	2017-10-23 11:44:15.915819948 +0100
@@ -1367,15 +1367,14 @@  update_costs_from_allocno (ira_allocno_t
 	      || ALLOCNO_ASSIGNED_P (another_allocno))
 	    continue;
 
-	  if (GET_MODE_SIZE (ALLOCNO_MODE (cp->second)) < GET_MODE_SIZE (mode))
-	    /* If we have different modes use the smallest one.  It is
-	       a sub-register move.  It is hard to predict what LRA
-	       will reload (the pseudo or its sub-register) but LRA
-	       will try to minimize the data movement.  Also for some
-	       register classes bigger modes might be invalid,
-	       e.g. DImode for AREG on x86.  For such cases the
-	       register move cost will be maximal. */
-	    mode = ALLOCNO_MODE (cp->second);
+	  /* If we have different modes use the smallest one.  It is
+	     a sub-register move.  It is hard to predict what LRA
+	     will reload (the pseudo or its sub-register) but LRA
+	     will try to minimize the data movement.  Also for some
+	     register classes bigger modes might be invalid,
+	     e.g. DImode for AREG on x86.  For such cases the
+	     register move cost will be maximal.  */
+	  mode = narrower_subreg_mode (mode, ALLOCNO_MODE (cp->second));
 	  
 	  cost = (cp->second == allocno
 		  ? ira_register_move_cost[mode][rclass][aclass]