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]

Minor tweaks to RTL CSE


The attached patch makes a couple of minor tweaks to RTL CSE:

 1. cse_insn canonicalizes top-level USEs by means of:

   /* Canonicalize a USE of a pseudo register or memory location.  */
   else if (GET_CODE (x) == USE
 	   && ! (REG_P (XEXP (x, 0))
 		 && REGNO (XEXP (x, 0)) < FIRST_PSEUDO_REGISTER))
     canon_reg (XEXP (x, 0), insn);

There is a thinko: if you want to canonicalize XEXP (x, 0) and it is a pseudo, 
you must do canon_reg (x, insn) and not canon_reg (XEXP (x, 0), insn).  This 
is done correctly a few lines above for embedded USEs:

	  else if (GET_CODE (y) == USE
		   && ! (REG_P (XEXP (y, 0))
			 && REGNO (XEXP (y, 0)) < FIRST_PSEUDO_REGISTER))
	    canon_reg (y, insn);


 2. fold_rtx folds into ASM_OPERANDS_INPUT of ASM_OPERANDS:

    case ASM_OPERANDS:
      if (insn)
	{
	  for (i = ASM_OPERANDS_INPUT_LENGTH (x) - 1; i >= 0; i--)
	    validate_change (insn, &ASM_OPERANDS_INPUT (x, i),
			     fold_rtx (ASM_OPERANDS_INPUT (x, i), insn), 0);
	}
      return x;

but cse_insn doesn't.  This missed optimization is problematic in Ada because 
we implement pragma Inspection_Point by means of a volatile asm and it can 
happen that CSE propagates a pseudo except into an ASM_OPERANDS, which can 
lead to a DEBUG_INSN referencing a dead pseudo and its subsequent resetting 
(although Jakub's patch I just reviewed may fix that up), i.e no debug info.
Now pragma Inspection_Point is precisely about getting correct debug info...

Bootstrapped/regtested on x86_64-suse-linux, applied on the mainline.


2010-10-13  Eric Botcazou  <ebotcazou@adacore.com>

	* cse.c (cse_insn): Fix thinko in the canonicalization of USE insns.
	Canonicalize input operands of ASM_OPERANDS insns.



-- 
Eric Botcazou
Index: cse.c
===================================================================
--- cse.c	(revision 165411)
+++ cse.c	(working copy)
@@ -4338,12 +4338,23 @@ cse_insn (rtx insn)
       if (MEM_P (XEXP (x, 0)))
 	canon_reg (XEXP (x, 0), insn);
     }
-
   /* Canonicalize a USE of a pseudo register or memory location.  */
   else if (GET_CODE (x) == USE
 	   && ! (REG_P (XEXP (x, 0))
 		 && REGNO (XEXP (x, 0)) < FIRST_PSEUDO_REGISTER))
-    canon_reg (XEXP (x, 0), insn);
+    canon_reg (x, insn);
+  else if (GET_CODE (x) == ASM_OPERANDS)
+    {
+      for (i = ASM_OPERANDS_INPUT_LENGTH (x) - 1; i >= 0; i--)
+	{
+	  rtx input = ASM_OPERANDS_INPUT (x, i);
+	  if (!(REG_P (input) && REGNO (input) < FIRST_PSEUDO_REGISTER))
+	    {
+	      input = canon_reg (input, insn);
+	      validate_change (insn, &ASM_OPERANDS_INPUT (x, i), input, 1);
+	    }
+	}
+    }
   else if (GET_CODE (x) == CALL)
     {
       /* The result of apply_change_group can be ignored; see canon_reg.  */

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