diff mbox series

Prevent invalid register mode changes in combine

Message ID 87bmm8grsj.fsf@linaro.org
State New
Headers show
Series Prevent invalid register mode changes in combine | expand

Commit Message

Richard Sandiford Sept. 18, 2017, 11:38 a.m. UTC
This patch stops combine from changing the mode of an existing register
in-place if doing so would change the size of the underlying register
allocation size, as given by REGMODE_NATURAL_SIZE.  Without this,
many tests fail in adjust_reg_mode after SVE is added.  One example
is gcc.c-torture/compile/20090401-1.c.

Tested on aarch64-linux-gnu, x86_64-linux-gnu and powerpc64le-linux-gnu.
Also tested by comparing the testsuite assembly output on at least one
target per CPU directory.  OK to install?

Richard


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

gcc/
	* combine.c (can_change_dest_mode): Reject changes in
	REGMODE_NATURAL_SIZE.

Comments

Jeff Law Oct. 12, 2017, 6:36 p.m. UTC | #1
On 09/18/2017 05:38 AM, Richard Sandiford wrote:
> This patch stops combine from changing the mode of an existing register
> in-place if doing so would change the size of the underlying register
> allocation size, as given by REGMODE_NATURAL_SIZE.  Without this,
> many tests fail in adjust_reg_mode after SVE is added.  One example
> is gcc.c-torture/compile/20090401-1.c.
> 
> Tested on aarch64-linux-gnu, x86_64-linux-gnu and powerpc64le-linux-gnu.
> Also tested by comparing the testsuite assembly output on at least one
> target per CPU directory.  OK to install?
> 
> Richard
> 
> 
> 2017-09-18  Richard Sandiford  <richard.sandiford@linaro.org>
> 	    Alan Hayward  <alan.hayward@arm.com>
> 	    David Sherwood  <david.sherwood@arm.com>
> 
> gcc/
> 	* combine.c (can_change_dest_mode): Reject changes in
> 	REGMODE_NATURAL_SIZE.
OK.
jeff
diff mbox series

Patch

Index: gcc/combine.c
===================================================================
--- gcc/combine.c	2017-09-18 12:31:05.459555526 +0100
+++ gcc/combine.c	2017-09-18 12:31:05.604645232 +0100
@@ -2451,6 +2451,12 @@  can_change_dest_mode (rtx x, int added_s
   if (!REG_P (x))
     return false;
 
+  /* Don't change between modes with different underlying register sizes,
+     since this could lead to invalid subregs.  */
+  if (REGMODE_NATURAL_SIZE (mode)
+      != REGMODE_NATURAL_SIZE (GET_MODE (x)))
+    return false;
+
   regno = REGNO (x);
   /* Allow hard registers if the new mode is legal, and occupies no more
      registers than the old mode.  */