diff mbox

[01/12] reduce conditional compilation for HARD_FRAME_POINTER_IS_ARG_POINTER

Message ID 1447087669-14039-2-git-send-email-tbsaunde+gcc@tbsaunde.org
State New
Headers show

Commit Message

tbsaunde+gcc@tbsaunde.org Nov. 9, 2015, 4:47 p.m. UTC
From: Trevor Saunders <tbsaunde+gcc@tbsaunde.org>

gcc/ChangeLog:

2015-11-09  Trevor Saunders  <tbsaunde+gcc@tbsaunde.org>

	* dbxout.c (dbxout_symbol_location): Remove #if for
	HARD_FRAME_POINTER_IS_ARG_POINTER.
	(dbxout_parms): Likewise.
	* dwarf2out.c (rtl_for_decl_location): Likewise.
	* emit-rtl.c (gen_rtx_REG): Likewise.
---
 gcc/dbxout.c    | 13 +++++--------
 gcc/dwarf2out.c |  6 ++----
 gcc/emit-rtl.c  |  7 ++++---
 3 files changed, 11 insertions(+), 15 deletions(-)

Comments

Bernd Schmidt Nov. 9, 2015, 7:01 p.m. UTC | #1
On 11/09/2015 05:47 PM, tbsaunde+gcc@tbsaunde.org wrote:
> +++ b/gcc/dbxout.c
> @@ -3076,10 +3076,8 @@ dbxout_symbol_location (tree decl, tree type, const char *suffix, rtx home)
>   	       || (REG_P (XEXP (home, 0))
>   		   && REGNO (XEXP (home, 0)) != HARD_FRAME_POINTER_REGNUM
>   		   && REGNO (XEXP (home, 0)) != STACK_POINTER_REGNUM
> -#if !HARD_FRAME_POINTER_IS_ARG_POINTER
> -		   && REGNO (XEXP (home, 0)) != ARG_POINTER_REGNUM
> -#endif
> -		   )))
> +		   && (HARD_FRAME_POINTER_IS_ARG_POINTER
> +		       || REGNO (XEXP (home, 0)) != ARG_POINTER_REGNUM))))

This used to be

#if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM

and the whole macro seems kind of pointless - why not just make the 
ARG_POINTER_REGNUM test unconditional? I think the conditional 
compilation was originally just a "performance optimization", avoiding 
unnecessary tests - which means the reason to have the tests goes away 
if we move away from the conditional compilation.


Bernd
Trevor Saunders Nov. 9, 2015, 8:58 p.m. UTC | #2
On Mon, Nov 09, 2015 at 08:01:28PM +0100, Bernd Schmidt wrote:
> On 11/09/2015 05:47 PM, tbsaunde+gcc@tbsaunde.org wrote:
> >+++ b/gcc/dbxout.c
> >@@ -3076,10 +3076,8 @@ dbxout_symbol_location (tree decl, tree type, const char *suffix, rtx home)
> >  	       || (REG_P (XEXP (home, 0))
> >  		   && REGNO (XEXP (home, 0)) != HARD_FRAME_POINTER_REGNUM
> >  		   && REGNO (XEXP (home, 0)) != STACK_POINTER_REGNUM
> >-#if !HARD_FRAME_POINTER_IS_ARG_POINTER
> >-		   && REGNO (XEXP (home, 0)) != ARG_POINTER_REGNUM
> >-#endif
> >-		   )))
> >+		   && (HARD_FRAME_POINTER_IS_ARG_POINTER
> >+		       || REGNO (XEXP (home, 0)) != ARG_POINTER_REGNUM))))
> 
> This used to be
> 
> #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
> 
> and the whole macro seems kind of pointless - why not just make the
> ARG_POINTER_REGNUM test unconditional? I think the conditional compilation

With the exception of the emit-rtl.c hunk I think I've correctly
convinced myself this macro is just an optimization.

> was originally just a "performance optimization", avoiding unnecessary tests
> - which means the reason to have the tests goes away if we move away from
> the conditional compilation.

Well, with this patch the test should still get optimized away when
appropriate, but if you want to go to supporting multiple targets then
yeah it might as well go away.

Trev

> 
> 
> Bernd
Bernd Schmidt Nov. 9, 2015, 9:09 p.m. UTC | #3
On 11/09/2015 09:58 PM, Trevor Saunders wrote:
> With the exception of the emit-rtl.c hunk I think I've correctly
> convinced myself this macro is just an optimization.

I also looked at that one and initially thought that it can simply go 
away, but the earlier test for FRAME_POINTER_REGNUM also has some extra 
reload_completed etc. conditions.

So I think this:

!      if (!HARD_FRAME_POINTER_IS_FRAME_POINTER
           && regno == HARD_FRAME_POINTER_REGNUM
           && (!reload_completed || frame_pointer_needed))
         return hard_frame_pointer_rtx;
-#if !HARD_FRAME_POINTER_IS_ARG_POINTER
       if (FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
           && regno == ARG_POINTER_REGNUM)
         return arg_pointer_rtx;
-#endif

should become

!     if (HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM
           && regno == HARD_FRAME_POINTER_REGNUM
           && (!reload_completed || frame_pointer_needed))
         return hard_frame_pointer_rtx;
       if (FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
+         && HARD_FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
	  && regno == ARG_POINTER_REGNUM)
         return arg_pointer_rtx;
#endif

and then it should be possible to eliminate the two X_IS_Y macros.


Bernd
diff mbox

Patch

diff --git a/gcc/dbxout.c b/gcc/dbxout.c
index 1b4a5ea..5f4ea77 100644
--- a/gcc/dbxout.c
+++ b/gcc/dbxout.c
@@ -3076,10 +3076,8 @@  dbxout_symbol_location (tree decl, tree type, const char *suffix, rtx home)
 	       || (REG_P (XEXP (home, 0))
 		   && REGNO (XEXP (home, 0)) != HARD_FRAME_POINTER_REGNUM
 		   && REGNO (XEXP (home, 0)) != STACK_POINTER_REGNUM
-#if !HARD_FRAME_POINTER_IS_ARG_POINTER
-		   && REGNO (XEXP (home, 0)) != ARG_POINTER_REGNUM
-#endif
-		   )))
+		   && (HARD_FRAME_POINTER_IS_ARG_POINTER
+		       || REGNO (XEXP (home, 0)) != ARG_POINTER_REGNUM))))
     /* If the value is indirect by memory or by a register
        that isn't the frame pointer
        then it means the object is variable-sized and address through
@@ -3490,10 +3488,9 @@  dbxout_parms (tree parms)
 		 && REG_P (XEXP (DECL_RTL (parms), 0))
 		 && REGNO (XEXP (DECL_RTL (parms), 0)) != HARD_FRAME_POINTER_REGNUM
 		 && REGNO (XEXP (DECL_RTL (parms), 0)) != STACK_POINTER_REGNUM
-#if !HARD_FRAME_POINTER_IS_ARG_POINTER
-		 && REGNO (XEXP (DECL_RTL (parms), 0)) != ARG_POINTER_REGNUM
-#endif
-		 )
+		 && (HARD_FRAME_POINTER_IS_ARG_POINTER
+		     || REGNO (XEXP (DECL_RTL (parms), 0))
+		       != ARG_POINTER_REGNUM))
 	  {
 	    /* Parm was passed via invisible reference.
 	       That is, its address was passed in a register.
diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
index f184750..c42da7e 100644
--- a/gcc/dwarf2out.c
+++ b/gcc/dwarf2out.c
@@ -16026,10 +16026,8 @@  rtl_for_decl_location (tree decl)
 	       && (!REG_P (XEXP (rtl, 0))
 		   || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
 		   || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
-#if !HARD_FRAME_POINTER_IS_ARG_POINTER
-		   || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
-#endif
-		     )
+		   || (!HARD_FRAME_POINTER_IS_ARG_POINTER
+		       && REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM))
 	       /* Big endian correction check.  */
 	       && BYTES_BIG_ENDIAN
 	       && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
diff --git a/gcc/emit-rtl.c b/gcc/emit-rtl.c
index c6a37e1..3d2c6d9 100644
--- a/gcc/emit-rtl.c
+++ b/gcc/emit-rtl.c
@@ -716,11 +716,12 @@  gen_rtx_REG (machine_mode mode, unsigned int regno)
 	  && regno == HARD_FRAME_POINTER_REGNUM
 	  && (!reload_completed || frame_pointer_needed))
 	return hard_frame_pointer_rtx;
-#if !HARD_FRAME_POINTER_IS_ARG_POINTER
-      if (FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
+
+      if (!HARD_FRAME_POINTER_IS_ARG_POINTER
+	  && FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
 	  && regno == ARG_POINTER_REGNUM)
 	return arg_pointer_rtx;
-#endif
+
 #ifdef RETURN_ADDRESS_POINTER_REGNUM
       if (regno == RETURN_ADDRESS_POINTER_REGNUM)
 	return return_address_pointer_rtx;