public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Fix condition in ira-color.c and lra-spills.c (PR c/61271)
@ 2014-08-21 18:01 Marek Polacek
  2014-08-21 19:38 ` Vladimir Makarov
  0 siblings, 1 reply; 4+ messages in thread
From: Marek Polacek @ 2014-08-21 18:01 UTC (permalink / raw)
  To: GCC Patches, Vladimir Makarov

Both ira-color.c and lra-spills.c contain this code, where
-Wlogical-not-parentheses would warn:
!FRAME_GROWS_DOWNWARD == STACK_GROWS_DOWNWARD
I think the condition is semantically right, so I just tweaked it
into a more common way with !=, so we don't warn on this anymore.

Bootstrapped/regtested on x86_64-linux, ok for trunk?

2014-08-21  Marek Polacek  <polacek@redhat.com>

	PR c/61271
	* ira-color.c (coalesced_pseudo_reg_slot_compare): Fix condition.
	* lra-spills.c (pseudo_reg_slot_compare): Fix condition.

diff --git gcc/ira-color.c gcc/ira-color.c
index 36c3c87..14958ac 100644
--- gcc/ira-color.c
+++ gcc/ira-color.c
@@ -3850,7 +3850,7 @@ coalesced_pseudo_reg_slot_compare (const void *v1p, const void *v2p)
   slot_num2 = -ALLOCNO_HARD_REGNO (a2);
   if ((diff = slot_num1 - slot_num2) != 0)
     return (frame_pointer_needed
-	    || !FRAME_GROWS_DOWNWARD == STACK_GROWS_DOWNWARD ? diff : -diff);
+	    || (FRAME_GROWS_DOWNWARD != STACK_GROWS_DOWNWARD) ? diff : -diff);
   total_size1 = MAX (PSEUDO_REGNO_BYTES (regno1),
 		     regno_max_ref_width[regno1]);
   total_size2 = MAX (PSEUDO_REGNO_BYTES (regno2),
diff --git gcc/lra-spills.c gcc/lra-spills.c
index 50f63fc..0d14685 100644
--- gcc/lra-spills.c
+++ gcc/lra-spills.c
@@ -237,7 +237,7 @@ pseudo_reg_slot_compare (const void *v1p, const void *v2p)
   slot_num2 = pseudo_slots[regno2].slot_num;
   if ((diff = slot_num1 - slot_num2) != 0)
     return (frame_pointer_needed
-	    || !FRAME_GROWS_DOWNWARD == STACK_GROWS_DOWNWARD ? diff : -diff);
+	    || (FRAME_GROWS_DOWNWARD != STACK_GROWS_DOWNWARD) ? diff : -diff);
   total_size1 = GET_MODE_SIZE (lra_reg_info[regno1].biggest_mode);
   total_size2 = GET_MODE_SIZE (lra_reg_info[regno2].biggest_mode);
   if ((diff = total_size2 - total_size1) != 0)

	Marek

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Fix condition in ira-color.c and lra-spills.c (PR c/61271)
  2014-08-21 18:01 [PATCH] Fix condition in ira-color.c and lra-spills.c (PR c/61271) Marek Polacek
@ 2014-08-21 19:38 ` Vladimir Makarov
  2014-08-22 14:51   ` Marek Polacek
  0 siblings, 1 reply; 4+ messages in thread
From: Vladimir Makarov @ 2014-08-21 19:38 UTC (permalink / raw)
  To: Marek Polacek, GCC Patches

On 08/21/2014 02:01 PM, Marek Polacek wrote:
> Both ira-color.c and lra-spills.c contain this code, where
> -Wlogical-not-parentheses would warn:
> !FRAME_GROWS_DOWNWARD == STACK_GROWS_DOWNWARD
> I think the condition is semantically right, so I just tweaked it
> into a more common way with !=, so we don't warn on this anymore.
>
> Bootstrapped/regtested on x86_64-linux, ok for trunk?
>
> 2014-08-21  Marek Polacek  <polacek@redhat.com>
>
> 	PR c/61271
> 	* ira-color.c (coalesced_pseudo_reg_slot_compare): Fix condition.
> 	* lra-spills.c (pseudo_reg_slot_compare): Fix condition.
>
> diff --git gcc/ira-color.c gcc/ira-color.c
> index 36c3c87..14958ac 100644
> --- gcc/ira-color.c
> +++ gcc/ira-color.c
> @@ -3850,7 +3850,7 @@ coalesced_pseudo_reg_slot_compare (const void *v1p, const void *v2p)
>    slot_num2 = -ALLOCNO_HARD_REGNO (a2);
>    if ((diff = slot_num1 - slot_num2) != 0)
>      return (frame_pointer_needed
> -	    || !FRAME_GROWS_DOWNWARD == STACK_GROWS_DOWNWARD ? diff : -diff);
> +	    || (FRAME_GROWS_DOWNWARD != STACK_GROWS_DOWNWARD) ? diff : -diff);
>    total_size1 = MAX (PSEUDO_REGNO_BYTES (regno1),
>  		     regno_max_ref_width[regno1]);
>    total_size2 = MAX (PSEUDO_REGNO_BYTES (regno2),
> diff --git gcc/lra-spills.c gcc/lra-spills.c
> index 50f63fc..0d14685 100644
> --- gcc/lra-spills.c
> +++ gcc/lra-spills.c
> @@ -237,7 +237,7 @@ pseudo_reg_slot_compare (const void *v1p, const void *v2p)
>    slot_num2 = pseudo_slots[regno2].slot_num;
>    if ((diff = slot_num1 - slot_num2) != 0)
>      return (frame_pointer_needed
> -	    || !FRAME_GROWS_DOWNWARD == STACK_GROWS_DOWNWARD ? diff : -diff);
> +	    || (FRAME_GROWS_DOWNWARD != STACK_GROWS_DOWNWARD) ? diff : -diff);
>    total_size1 = GET_MODE_SIZE (lra_reg_info[regno1].biggest_mode);
>    total_size2 = GET_MODE_SIZE (lra_reg_info[regno2].biggest_mode);
>    if ((diff = total_size2 - total_size1) != 0)
>
>
Sorry, Marek.  I guess it is wrong.  STACK_GROWS_DOWNWARD is only 0 or 1
in these files (it is achieved by redefinition of STACK_GROWS_DOWNWARD
in the files).  FAME_GROWS_DOWNWARD can be 0 or anything non-zero (even
non-constant) as tm.texi contains

@defmac FRAME_GROWS_DOWNWARD
Define this macro to nonzero value if the addresses of local variable slots
are at negative offsets from the frame pointer.
@end defmac

It works now as all machine description files use 1 as non-zero value.

So the documentation should be changed but it is not wise, error prune,
and right now the macro value can be non-constant during compilation
time theoretically.

So you need another way to transform the expressions to get rid of the
warning.

As I remember the code was actually taken from the old RA and not simple
as it looks.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Fix condition in ira-color.c and lra-spills.c (PR c/61271)
  2014-08-21 19:38 ` Vladimir Makarov
@ 2014-08-22 14:51   ` Marek Polacek
  2014-08-22 15:33     ` Vladimir Makarov
  0 siblings, 1 reply; 4+ messages in thread
From: Marek Polacek @ 2014-08-22 14:51 UTC (permalink / raw)
  To: Vladimir Makarov; +Cc: GCC Patches

On Thu, Aug 21, 2014 at 03:38:25PM -0400, Vladimir Makarov wrote:
> Sorry, Marek.  I guess it is wrong.  STACK_GROWS_DOWNWARD is only 0 or 1
> in these files (it is achieved by redefinition of STACK_GROWS_DOWNWARD
> in the files).  FAME_GROWS_DOWNWARD can be 0 or anything non-zero (even
> non-constant) as tm.texi contains
> 
> @defmac FRAME_GROWS_DOWNWARD
> Define this macro to nonzero value if the addresses of local variable slots
> are at negative offsets from the frame pointer.
> @end defmac
> 
> It works now as all machine description files use 1 as non-zero value.
> 
> So the documentation should be changed but it is not wise, error prune,
> and right now the macro value can be non-constant during compilation
> time theoretically.
 
Whoops, that is sneaky, thanks for the exaplanation.

> So you need another way to transform the expressions to get rid of the
> warning.
> 
> As I remember the code was actually taken from the old RA and not simple
> as it looks.
 
So what we can do is to just wrap the LHS of the comparison in parens;
this ought to suppress the warning.

Bootstrapped/regtested on x86_64-linux, ok for trunk?

2014-08-22  Marek Polacek  <polacek@redhat.com>

	PR c/61271
	* ira-color.c (coalesced_pseudo_reg_slot_compare): Wrap LHS of
	a comparison in parens.
	* lra-spills.c (pseudo_reg_slot_compare): Wrap LHS of a comparison
	in parens.

diff --git gcc/ira-color.c gcc/ira-color.c
index 36c3c87..e2ea359 100644
--- gcc/ira-color.c
+++ gcc/ira-color.c
@@ -3850,7 +3850,7 @@ coalesced_pseudo_reg_slot_compare (const void *v1p, const void *v2p)
   slot_num2 = -ALLOCNO_HARD_REGNO (a2);
   if ((diff = slot_num1 - slot_num2) != 0)
     return (frame_pointer_needed
-	    || !FRAME_GROWS_DOWNWARD == STACK_GROWS_DOWNWARD ? diff : -diff);
+	    || (!FRAME_GROWS_DOWNWARD) == STACK_GROWS_DOWNWARD ? diff : -diff);
   total_size1 = MAX (PSEUDO_REGNO_BYTES (regno1),
 		     regno_max_ref_width[regno1]);
   total_size2 = MAX (PSEUDO_REGNO_BYTES (regno2),
diff --git gcc/lra-spills.c gcc/lra-spills.c
index 50f63fc..38a81e6 100644
--- gcc/lra-spills.c
+++ gcc/lra-spills.c
@@ -237,7 +237,7 @@ pseudo_reg_slot_compare (const void *v1p, const void *v2p)
   slot_num2 = pseudo_slots[regno2].slot_num;
   if ((diff = slot_num1 - slot_num2) != 0)
     return (frame_pointer_needed
-	    || !FRAME_GROWS_DOWNWARD == STACK_GROWS_DOWNWARD ? diff : -diff);
+	    || (!FRAME_GROWS_DOWNWARD) == STACK_GROWS_DOWNWARD ? diff : -diff);
   total_size1 = GET_MODE_SIZE (lra_reg_info[regno1].biggest_mode);
   total_size2 = GET_MODE_SIZE (lra_reg_info[regno2].biggest_mode);
   if ((diff = total_size2 - total_size1) != 0)


	Marek

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Fix condition in ira-color.c and lra-spills.c (PR c/61271)
  2014-08-22 14:51   ` Marek Polacek
@ 2014-08-22 15:33     ` Vladimir Makarov
  0 siblings, 0 replies; 4+ messages in thread
From: Vladimir Makarov @ 2014-08-22 15:33 UTC (permalink / raw)
  To: Marek Polacek; +Cc: GCC Patches

On 2014-08-22 10:51 AM, Marek Polacek wrote:
> Bootstrapped/regtested on x86_64-linux, ok for trunk?
>

Ok. Thanks, Marek.

> 2014-08-22  Marek Polacek  <polacek@redhat.com>
>
> 	PR c/61271
> 	* ira-color.c (coalesced_pseudo_reg_slot_compare): Wrap LHS of
> 	a comparison in parens.
> 	* lra-spills.c (pseudo_reg_slot_compare): Wrap LHS of a comparison
> 	in parens.
>
> diff --git gcc/ira-color.c gcc/ira-color.c
> index 36c3c87..e2ea359 100644
> --- gcc/ira-color.c
> +++ gcc/ira-color.c
> @@ -3850,7 +3850,7 @@ coalesced_pseudo_reg_slot_compare (const void *v1p, const void *v2p)
>     slot_num2 = -ALLOCNO_HARD_REGNO (a2);
>     if ((diff = slot_num1 - slot_num2) != 0)
>       return (frame_pointer_needed
> -	    || !FRAME_GROWS_DOWNWARD == STACK_GROWS_DOWNWARD ? diff : -diff);
> +	    || (!FRAME_GROWS_DOWNWARD) == STACK_GROWS_DOWNWARD ? diff : -diff);
>     total_size1 = MAX (PSEUDO_REGNO_BYTES (regno1),
>   		     regno_max_ref_width[regno1]);
>     total_size2 = MAX (PSEUDO_REGNO_BYTES (regno2),
> diff --git gcc/lra-spills.c gcc/lra-spills.c
> index 50f63fc..38a81e6 100644
> --- gcc/lra-spills.c
> +++ gcc/lra-spills.c
> @@ -237,7 +237,7 @@ pseudo_reg_slot_compare (const void *v1p, const void *v2p)
>     slot_num2 = pseudo_slots[regno2].slot_num;
>     if ((diff = slot_num1 - slot_num2) != 0)
>       return (frame_pointer_needed
> -	    || !FRAME_GROWS_DOWNWARD == STACK_GROWS_DOWNWARD ? diff : -diff);
> +	    || (!FRAME_GROWS_DOWNWARD) == STACK_GROWS_DOWNWARD ? diff : -diff);
>     total_size1 = GET_MODE_SIZE (lra_reg_info[regno1].biggest_mode);
>     total_size2 = GET_MODE_SIZE (lra_reg_info[regno2].biggest_mode);
>     if ((diff = total_size2 - total_size1) != 0)
>
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-08-22 15:33 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-08-21 18:01 [PATCH] Fix condition in ira-color.c and lra-spills.c (PR c/61271) Marek Polacek
2014-08-21 19:38 ` Vladimir Makarov
2014-08-22 14:51   ` Marek Polacek
2014-08-22 15:33     ` Vladimir Makarov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).