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]

Avoid creating duplicating SUBREGs in simplify_rtx


I noticed that simplify_rtx's SUBREG case calls simplify_gen_subreg
rather than simplify_subreg.  Thus if the SUBREG cannot be simplified
(probably the usual case), simpilfy_rtx returns an identical copy of
the original.  This copy is wasteful in its own right, but might also
trick callers into thinking we've done something useful, and cause
them to do unnecessary work too.

For reference, simplify_gen_subreg is:

rtx
simplify_gen_subreg (enum machine_mode outermode, rtx op,
		     enum machine_mode innermode, unsigned int byte)
{
  rtx newx;

  newx = simplify_subreg (outermode, op, innermode, byte);
  if (newx)
    return newx;

  if (GET_CODE (op) == SUBREG
      || GET_CODE (op) == CONCAT
      || GET_MODE (op) == VOIDmode)
    return NULL_RTX;

  if (validate_subreg (outermode, innermode, op, byte))
    return gen_rtx_SUBREG (outermode, op, byte);

  return NULL_RTX;
}

Thus the only case changed by the patch is the one mentioned above:
a SUBREG that is valid but cannot be simplified.

Bootstrapped & regression-tested on x86_64-linux-gnu.  I also compiled
the C testsuite at -O2 and checked that the patch had no effect on
the assembly output.  OK to install?

Richard


gcc/
	* simplify-rtx.c (simplify_rtx): Use simplify_subreg rather than
	simplify_gen_subreg.

Index: gcc/simplify-rtx.c
===================================================================
--- gcc/simplify-rtx.c	(revision 119358)
+++ gcc/simplify-rtx.c	(working copy)
@@ -4853,9 +4853,9 @@ simplify_rtx (rtx x)
 
     case RTX_EXTRA:
       if (code == SUBREG)
-	return simplify_gen_subreg (mode, SUBREG_REG (x),
-				    GET_MODE (SUBREG_REG (x)),
-				    SUBREG_BYTE (x));
+	return simplify_subreg (mode, SUBREG_REG (x),
+				GET_MODE (SUBREG_REG (x)),
+				SUBREG_BYTE (x));
       break;
 
     case RTX_OBJ:


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