public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* patch to fix PR70703
@ 2017-04-05 15:11 Vladimir Makarov
  2017-04-05 15:25 ` Jakub Jelinek
  0 siblings, 1 reply; 6+ messages in thread
From: Vladimir Makarov @ 2017-04-05 15:11 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 172 bytes --]

The following patch fixes

   https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70703

The patch was successfully bootstrapped and tested on x86-64.

Committed as rev. 246707



[-- Attachment #2: pr70703.patch --]
[-- Type: text/x-patch, Size: 2739 bytes --]

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 246706)
+++ ChangeLog	(working copy)
@@ -1,3 +1,10 @@
+2017-04-05  Vladimir Makarov  <vmakarov@redhat.com>
+
+	PR rtl-optimization/70703
+	* ira-color.c (update_costs_from_allocno): Use the smallest mode.
+	(update_conflict_hard_regno_costs): Use long instead of unsigned
+	arithmetic for cost calculation.
+
 2017-04-05  Jakub Jelinek  <jakub@redhat.com>
 	    Bernd Edlinger  <bernd.edlinger@hotmail.de>
 
Index: testsuite/ChangeLog
===================================================================
--- testsuite/ChangeLog	(revision 246706)
+++ testsuite/ChangeLog	(working copy)
@@ -1,3 +1,8 @@
+2017-04-05  Vladimir Makarov  <vmakarov@redhat.com>
+
+	PR rtl-optimization/70703
+	* gcc.target/i386/pr70703.c: New.
+
 2017-04-05  Jakub Jelinek  <jakub@redhat.com>
 
 	PR sanitizer/80308
Index: ira-color.c
===================================================================
--- ira-color.c	(revision 246536)
+++ ira-color.c	(working copy)
@@ -1367,6 +1367,16 @@ update_costs_from_allocno (ira_allocno_t
 	      || ALLOCNO_ASSIGNED_P (another_allocno))
 	    continue;
 
+	  if (GET_MODE_SIZE (ALLOCNO_MODE (cp->second)) < GET_MODE_SIZE (mode))
+	    /* If we have different modes use the smallest one.  It is
+	       a sub-register move.  It is hard to predict what LRA
+	       will reload (the pseudo or its sub-register) but LRA
+	       will try to minimize the data movement.  Also for some
+	       register classes bigger modes might be invalid,
+	       e.g. DImode for AREG on x86.  For such cases the
+	       register move cost will be maximal. */
+	    mode = ALLOCNO_MODE (cp->second);
+	  
 	  cost = (cp->second == allocno
 		  ? ira_register_move_cost[mode][rclass][aclass]
 		  : ira_register_move_cost[mode][aclass][rclass]);
@@ -1512,7 +1522,7 @@ update_conflict_hard_regno_costs (int *c
 		index = ira_class_hard_reg_index[aclass][hard_regno];
 		if (index < 0)
 		  continue;
-		cost = (int) ((unsigned) conflict_costs [i] * mult) / div;
+		cost = (int) (((long) conflict_costs [i] * mult) / div);
 		if (cost == 0)
 		  continue;
 		cont_p = true;
Index: testsuite/gcc.target/i386/pr70703.c
===================================================================
--- testsuite/gcc.target/i386/pr70703.c	(nonexistent)
+++ testsuite/gcc.target/i386/pr70703.c	(working copy)
@@ -0,0 +1,9 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fomit-frame-pointer" } */
+/* { dg-require-effective-target ia32 } */
+/* { dg-final { scan-assembler "movl\t\\\$6700417, %eax" } } */
+
+unsigned ud_x_641_mul(unsigned x) {
+    /* optimized version of x / 641 */
+    return ((unsigned long long)x * 0x663d81) >> 32;
+}

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

* Re: patch to fix PR70703
  2017-04-05 15:11 patch to fix PR70703 Vladimir Makarov
@ 2017-04-05 15:25 ` Jakub Jelinek
  2017-04-05 16:07   ` Vladimir Makarov
  0 siblings, 1 reply; 6+ messages in thread
From: Jakub Jelinek @ 2017-04-05 15:25 UTC (permalink / raw)
  To: Vladimir Makarov; +Cc: gcc-patches

On Wed, Apr 05, 2017 at 11:11:54AM -0400, Vladimir Makarov wrote:
> --- ira-color.c	(revision 246536)
> +++ ira-color.c	(working copy)
> @@ -1367,6 +1367,16 @@ update_costs_from_allocno (ira_allocno_t
>  	      || ALLOCNO_ASSIGNED_P (another_allocno))
>  	    continue;
>  
> +	  if (GET_MODE_SIZE (ALLOCNO_MODE (cp->second)) < GET_MODE_SIZE (mode))
> +	    /* If we have different modes use the smallest one.  It is
> +	       a sub-register move.  It is hard to predict what LRA
> +	       will reload (the pseudo or its sub-register) but LRA
> +	       will try to minimize the data movement.  Also for some
> +	       register classes bigger modes might be invalid,
> +	       e.g. DImode for AREG on x86.  For such cases the
> +	       register move cost will be maximal. */
> +	    mode = ALLOCNO_MODE (cp->second);
> +	  
>  	  cost = (cp->second == allocno
>  		  ? ira_register_move_cost[mode][rclass][aclass]
>  		  : ira_register_move_cost[mode][aclass][rclass]);
> @@ -1512,7 +1522,7 @@ update_conflict_hard_regno_costs (int *c
>  		index = ira_class_hard_reg_index[aclass][hard_regno];
>  		if (index < 0)
>  		  continue;
> -		cost = (int) ((unsigned) conflict_costs [i] * mult) / div;
> +		cost = (int) (((long) conflict_costs [i] * mult) / div);

If you want something wider than unsigned, wouldn't it be better to
use HOST_WIDE_INT then?  Otherwise it will work differently between
32-bit and 64-bit hosts.
Can any of those 3 values be negative?  If not, perhaps
unsigned HOST_WIDE_INT?

	Jakub

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

* Re: patch to fix PR70703
  2017-04-05 15:25 ` Jakub Jelinek
@ 2017-04-05 16:07   ` Vladimir Makarov
  2017-04-05 16:18     ` Vladimir Makarov
  0 siblings, 1 reply; 6+ messages in thread
From: Vladimir Makarov @ 2017-04-05 16:07 UTC (permalink / raw)
  To: gcc-patches



On 04/05/2017 11:25 AM, Jakub Jelinek wrote:
> On Wed, Apr 05, 2017 at 11:11:54AM -0400, Vladimir Makarov wrote:
>> --- ira-color.c	(revision 246536)
>> +++ ira-color.c	(working copy)
>> @@ -1367,6 +1367,16 @@ update_costs_from_allocno (ira_allocno_t
>>   	      || ALLOCNO_ASSIGNED_P (another_allocno))
>>   	    continue;
>>   
>> +	  if (GET_MODE_SIZE (ALLOCNO_MODE (cp->second)) < GET_MODE_SIZE (mode))
>> +	    /* If we have different modes use the smallest one.  It is
>> +	       a sub-register move.  It is hard to predict what LRA
>> +	       will reload (the pseudo or its sub-register) but LRA
>> +	       will try to minimize the data movement.  Also for some
>> +	       register classes bigger modes might be invalid,
>> +	       e.g. DImode for AREG on x86.  For such cases the
>> +	       register move cost will be maximal. */
>> +	    mode = ALLOCNO_MODE (cp->second);
>> +	
>>   	  cost = (cp->second == allocno
>>   		  ? ira_register_move_cost[mode][rclass][aclass]
>>   		  : ira_register_move_cost[mode][aclass][rclass]);
>> @@ -1512,7 +1522,7 @@ update_conflict_hard_regno_costs (int *c
>>   		index = ira_class_hard_reg_index[aclass][hard_regno];
>>   		if (index < 0)
>>   		  continue;
>> -		cost = (int) ((unsigned) conflict_costs [i] * mult) / div;
>> +		cost = (int) (((long) conflict_costs [i] * mult) / div);
> If you want something wider than unsigned, wouldn't it be better to
> use HOST_WIDE_INT then?  Otherwise it will work differently between
> 32-bit and 64-bit hosts.
> Can any of those 3 values be negative?  If not, perhaps
> unsigned HOST_WIDE_INT?
>
Thank you for finding this, Jakub.  The overflow might happen only when 
65K is used for ira_register_move_cost which means an impossible move in 
most cases.  Still if it happens in rare cases, the behavior might be 
different for the native and a cross.

I'll correct the patch.

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

* Re: patch to fix PR70703
  2017-04-05 16:07   ` Vladimir Makarov
@ 2017-04-05 16:18     ` Vladimir Makarov
  2017-04-06 10:24       ` Richard Biener
  0 siblings, 1 reply; 6+ messages in thread
From: Vladimir Makarov @ 2017-04-05 16:18 UTC (permalink / raw)
  To: gcc-patches



On 04/05/2017 12:07 PM, Vladimir Makarov wrote:
>
>
> I'll correct the patch.
>
Here is the patch I've committed.

2017-04-05  Vladimir Makarov  <vmakarov@redhat.com>

         PR rtl-optimization/70703
         * ira-color.c (update_conflict_hard_regno_costs): Use
         HOST_WIDE_INT instead of long.

Index: ira-color.c
===================================================================
--- ira-color.c (revision 246707)
+++ ira-color.c (working copy)
@@ -1522,7 +1522,7 @@
                 index = ira_class_hard_reg_index[aclass][hard_regno];
                 if (index < 0)
                   continue;
-               cost = (int) (((long) conflict_costs [i] * mult) / div);
+               cost = (int) (((HOST_WIDE_INT) conflict_costs [i] * 
mult) / div);
                 if (cost == 0)
                   continue;
                 cont_p = true;

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

* Re: patch to fix PR70703
  2017-04-05 16:18     ` Vladimir Makarov
@ 2017-04-06 10:24       ` Richard Biener
  2017-04-07 16:07         ` Vladimir Makarov
  0 siblings, 1 reply; 6+ messages in thread
From: Richard Biener @ 2017-04-06 10:24 UTC (permalink / raw)
  To: Vladimir Makarov; +Cc: GCC Patches

On Wed, Apr 5, 2017 at 6:18 PM, Vladimir Makarov <vmakarov@redhat.com> wrote:
>
>
> On 04/05/2017 12:07 PM, Vladimir Makarov wrote:
>>
>>
>>
>> I'll correct the patch.
>>
> Here is the patch I've committed.

Note that in such contexts it's better to just use [u]int64_t.

Richard.

> 2017-04-05  Vladimir Makarov  <vmakarov@redhat.com>
>
>         PR rtl-optimization/70703
>         * ira-color.c (update_conflict_hard_regno_costs): Use
>         HOST_WIDE_INT instead of long.
>
> Index: ira-color.c
> ===================================================================
> --- ira-color.c (revision 246707)
> +++ ira-color.c (working copy)
> @@ -1522,7 +1522,7 @@
>                 index = ira_class_hard_reg_index[aclass][hard_regno];
>                 if (index < 0)
>                   continue;
> -               cost = (int) (((long) conflict_costs [i] * mult) / div);
> +               cost = (int) (((HOST_WIDE_INT) conflict_costs [i] * mult) /
> div);
>                 if (cost == 0)
>                   continue;
>                 cont_p = true;
>

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

* Re: patch to fix PR70703
  2017-04-06 10:24       ` Richard Biener
@ 2017-04-07 16:07         ` Vladimir Makarov
  0 siblings, 0 replies; 6+ messages in thread
From: Vladimir Makarov @ 2017-04-07 16:07 UTC (permalink / raw)
  To: Richard Biener; +Cc: GCC Patches



On 04/06/2017 06:24 AM, Richard Biener wrote:
> On Wed, Apr 5, 2017 at 6:18 PM, Vladimir Makarov <vmakarov@redhat.com> wrote:
>>
>> On 04/05/2017 12:07 PM, Vladimir Makarov wrote:
>>>
>>>
>>> I'll correct the patch.
>>>
>> Here is the patch I've committed.
> Note that in such contexts it's better to just use [u]int64_t.
>
>
You are right, Richard.  I've committed the following patch:

Index: ChangeLog
===================================================================
--- ChangeLog   (revision 246764)
+++ ChangeLog   (working copy)
@@ -1,5 +1,11 @@
  2017-04-07  Vladimir Makarov  <vmakarov@redhat.com>

+       PR rtl-optimization/70703
+       * ira-color.c (update_conflict_hard_regno_costs): Use
+       int64_t instead of HOST_WIDE_INT.
+
+2017-04-07  Vladimir Makarov  <vmakarov@redhat.com>
+
         PR rtl-optimization/70478
         * lra-constraints.c (process_alt_operands): Disfavor alternative
         insn memory operands.
Index: ira-color.c
===================================================================
--- ira-color.c (revision 246763)
+++ ira-color.c (working copy)
@@ -1522,7 +1522,7 @@ update_conflict_hard_regno_costs (int *c
                 index = ira_class_hard_reg_index[aclass][hard_regno];
                 if (index < 0)
                   continue;
-               cost = (int) (((HOST_WIDE_INT) conflict_costs [i] * 
mult) / div);
+               cost = (int) (((int64_t) conflict_costs [i] * mult) / div);
                 if (cost == 0)
                   continue;
                 cont_p = true;

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

end of thread, other threads:[~2017-04-07 16:07 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-05 15:11 patch to fix PR70703 Vladimir Makarov
2017-04-05 15:25 ` Jakub Jelinek
2017-04-05 16:07   ` Vladimir Makarov
2017-04-05 16:18     ` Vladimir Makarov
2017-04-06 10:24       ` Richard Biener
2017-04-07 16:07         ` 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).