* GCSE: Use HOST_WIDE_INT instead of int (PR, rtl-optimization/79574).
@ 2017-03-02 17:50 Martin Liška
2017-03-02 19:58 ` Bernd Schmidt
0 siblings, 1 reply; 4+ messages in thread
From: Martin Liška @ 2017-03-02 17:50 UTC (permalink / raw)
To: GCC Patches
[-- Attachment #1: Type: text/plain, Size: 197 bytes --]
Hello.
This is second part of fixes needed to not trigger integer overflow in gcse pass.
Patch can bootstrap on ppc64le-redhat-linux and survives regression tests.
Ready to be installed?
Martin
[-- Attachment #2: 0001-GCSE-Use-HOST_WIDE_INT-instead-of-int-PR-rtl-optimiz.patch --]
[-- Type: text/x-patch, Size: 5626 bytes --]
From a3e8ca75be55bd6d707f54ae3972e30285b64566 Mon Sep 17 00:00:00 2001
From: marxin <mliska@suse.cz>
Date: Thu, 2 Mar 2017 12:21:07 +0100
Subject: [PATCH] GCSE: Use HOST_WIDE_INT instead of int (PR
rtl-optimization/79574).
gcc/ChangeLog:
2017-03-02 Martin Liska <mliska@suse.cz>
PR rtl-optimization/79574
* gcse.c (struct gcse_expr): Use HOST_WIDE_INT instead of int.
(hash_scan_set): Likewise.
(dump_hash_table): Likewise.
(hoist_code): Likewise.
gcc/testsuite/ChangeLog:
2017-03-02 Martin Liska <mliska@suse.cz>
PR rtl-optimization/79574
* gcc.dg/pr79574-2.c: New test.
---
gcc/gcse.c | 26 +++++++++++++++-----------
gcc/testsuite/gcc.dg/pr79574-2.c | 33 +++++++++++++++++++++++++++++++++
2 files changed, 48 insertions(+), 11 deletions(-)
create mode 100644 gcc/testsuite/gcc.dg/pr79574-2.c
diff --git a/gcc/gcse.c b/gcc/gcse.c
index 5c6984c3240..2b0a11268eb 100644
--- a/gcc/gcse.c
+++ b/gcc/gcse.c
@@ -281,7 +281,7 @@ struct gcse_expr
to keep register pressure under control.
A value of "0" removes restrictions on how far the expression can
travel. */
- int max_distance;
+ HOST_WIDE_INT max_distance;
};
/* Occurrence of an expression.
@@ -458,7 +458,7 @@ static int oprs_unchanged_p (const_rtx, const rtx_insn *, int);
static int oprs_anticipatable_p (const_rtx, const rtx_insn *);
static int oprs_available_p (const_rtx, const rtx_insn *);
static void insert_expr_in_table (rtx, machine_mode, rtx_insn *, int, int,
- int, struct gcse_hash_table_d *);
+ HOST_WIDE_INT, struct gcse_hash_table_d *);
static unsigned int hash_expr (const_rtx, machine_mode, int *, int);
static void record_last_reg_set_info (rtx_insn *, int);
static void record_last_mem_set_info (rtx_insn *);
@@ -488,8 +488,10 @@ static void alloc_code_hoist_mem (int, int);
static void free_code_hoist_mem (void);
static void compute_code_hoist_vbeinout (void);
static void compute_code_hoist_data (void);
-static int should_hoist_expr_to_dom (basic_block, struct gcse_expr *, basic_block,
- sbitmap, int, int *, enum reg_class,
+static int should_hoist_expr_to_dom (basic_block, struct gcse_expr *,
+ basic_block,
+ sbitmap, HOST_WIDE_INT, int *,
+ enum reg_class,
int *, bitmap, rtx_insn *);
static int hoist_code (void);
static enum reg_class get_regno_pressure_class (int regno, int *nregs);
@@ -743,7 +745,7 @@ static basic_block current_bb;
GCSE. */
static int
-want_to_gcse_p (rtx x, machine_mode mode, int *max_distance_ptr)
+want_to_gcse_p (rtx x, machine_mode mode, HOST_WIDE_INT *max_distance_ptr)
{
#ifdef STACK_REGS
/* On register stack architectures, don't GCSE constants from the
@@ -1115,7 +1117,8 @@ expr_equiv_p (const_rtx x, const_rtx y)
static void
insert_expr_in_table (rtx x, machine_mode mode, rtx_insn *insn,
int antic_p,
- int avail_p, int max_distance, struct gcse_hash_table_d *table)
+ int avail_p, HOST_WIDE_INT max_distance,
+ struct gcse_hash_table_d *table)
{
int found, do_not_record_p;
unsigned int hash;
@@ -1231,7 +1234,7 @@ hash_scan_set (rtx set, rtx_insn *insn, struct gcse_hash_table_d *table)
else if (REG_P (dest))
{
unsigned int regno = REGNO (dest);
- int max_distance = 0;
+ HOST_WIDE_INT max_distance = 0;
/* See if a REG_EQUAL note shows this equivalent to a simpler expression.
@@ -1300,7 +1303,7 @@ hash_scan_set (rtx set, rtx_insn *insn, struct gcse_hash_table_d *table)
else if (flag_gcse_las && REG_P (src) && MEM_P (dest))
{
unsigned int regno = REGNO (src);
- int max_distance = 0;
+ HOST_WIDE_INT max_distance = 0;
/* Only record sets of pseudo-regs in the hash table. */
if (regno >= FIRST_PSEUDO_REGISTER
@@ -1413,7 +1416,7 @@ dump_hash_table (FILE *file, const char *name, struct gcse_hash_table_d *table)
{
expr = flat_table[i];
fprintf (file, "Index %d (hash value %d; max distance %d)\n ",
- expr->bitmap_index, hash_val[i], expr->max_distance);
+ expr->bitmap_index, hash_val[i], (int)expr->max_distance);
print_rtl (file, expr->expr);
fprintf (file, "\n");
}
@@ -2884,7 +2887,8 @@ update_bb_reg_pressure (basic_block bb, rtx_insn *from)
static int
should_hoist_expr_to_dom (basic_block expr_bb, struct gcse_expr *expr,
- basic_block bb, sbitmap visited, int distance,
+ basic_block bb, sbitmap visited,
+ HOST_WIDE_INT distance,
int *bb_size, enum reg_class pressure_class,
int *nregs, bitmap hoisted_bbs, rtx_insn *from)
{
@@ -3161,7 +3165,7 @@ hoist_code (void)
computes the expression. */
FOR_EACH_VEC_ELT (domby, j, dominated)
{
- int max_distance;
+ HOST_WIDE_INT max_distance;
/* Ignore self dominance. */
if (bb == dominated)
diff --git a/gcc/testsuite/gcc.dg/pr79574-2.c b/gcc/testsuite/gcc.dg/pr79574-2.c
new file mode 100644
index 00000000000..995dff40174
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr79574-2.c
@@ -0,0 +1,33 @@
+/* PR rtl-optimization/79574 */
+/* { dg-do compile } */
+/* { dg-options "-Os --param gcse-cost-distance-ratio=2147483647" } */
+
+#include "stdarg.h"
+
+int buf[100];
+int buf1[10];
+
+int rd (int *pppp, int n, ...)
+{
+ va_list argp;
+ int *p;
+ int i;
+ int res;
+
+ va_start (argp, n);
+ for (; n > 0; n--)
+ va_arg (argp, double);
+ p = va_arg (argp, int *);
+ i = va_arg (argp, int);
+
+ res = p[i];
+ __builtin_printf ("%d\n", res);
+
+ return res;
+}
+
+int mpx_test (int argc, const char **argv)
+{
+ rd (buf1, 2, 10.0d, 10.0d, buf, 100, buf1);
+ return 0;
+}
--
2.11.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: GCSE: Use HOST_WIDE_INT instead of int (PR, rtl-optimization/79574).
2017-03-02 17:50 GCSE: Use HOST_WIDE_INT instead of int (PR, rtl-optimization/79574) Martin Liška
@ 2017-03-02 19:58 ` Bernd Schmidt
2017-03-03 10:31 ` Martin Liška
2017-03-03 11:04 ` Richard Biener
0 siblings, 2 replies; 4+ messages in thread
From: Bernd Schmidt @ 2017-03-02 19:58 UTC (permalink / raw)
To: Martin Liška, GCC Patches
On 03/02/2017 06:50 PM, Martin Liška wrote:
> Hello.
>
> This is second part of fixes needed to not trigger integer overflow in gcse pass.
So, how is this intended to work? The min/max stored in the param is an
int, and by using a HOST_WIDE_INT here, we expect that it is a larger
type and therefore won't overflow?
> {
> expr = flat_table[i];
> fprintf (file, "Index %d (hash value %d; max distance %d)\n ",
> - expr->bitmap_index, hash_val[i], expr->max_distance);
> + expr->bitmap_index, hash_val[i], (int)expr->max_distance);
> print_rtl (file, expr->expr);
> fprintf (file, "\n");
Use HOST_WIDE_INT_PRINT_DEC maybe? Otherwise OK, I guess.
Bernd
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: GCSE: Use HOST_WIDE_INT instead of int (PR, rtl-optimization/79574).
2017-03-02 19:58 ` Bernd Schmidt
@ 2017-03-03 10:31 ` Martin Liška
2017-03-03 11:04 ` Richard Biener
1 sibling, 0 replies; 4+ messages in thread
From: Martin Liška @ 2017-03-03 10:31 UTC (permalink / raw)
To: Bernd Schmidt, GCC Patches
On 03/02/2017 08:58 PM, Bernd Schmidt wrote:
> On 03/02/2017 06:50 PM, Martin Liška wrote:
>> Hello.
>>
>> This is second part of fixes needed to not trigger integer overflow in gcse pass.
>
> So, how is this intended to work? The min/max stored in the param is an int, and by using a HOST_WIDE_INT here, we expect that it is a larger type and therefore won't overflow?
Using int type is fine, but as gcse.c does an arithmetic with a distance:
/* Prefer to hoist EXPR if register pressure is decreased. */
if (decreased_pressure > *nregs)
distance += bb_size[bb->index];
...
max_distance += (bb_size[dominated->index]
- to_bb_head[INSN_UID (occr->insn)]);
>
>> {
>> expr = flat_table[i];
>> fprintf (file, "Index %d (hash value %d; max distance %d)\n ",
>> - expr->bitmap_index, hash_val[i], expr->max_distance);
>> + expr->bitmap_index, hash_val[i], (int)expr->max_distance);
>> print_rtl (file, expr->expr);
>> fprintf (file, "\n");
>
> Use HOST_WIDE_INT_PRINT_DEC maybe? Otherwise OK, I guess.
That's for nit, I'll install the patch with that.
Martin
>
>
> Bernd
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: GCSE: Use HOST_WIDE_INT instead of int (PR, rtl-optimization/79574).
2017-03-02 19:58 ` Bernd Schmidt
2017-03-03 10:31 ` Martin Liška
@ 2017-03-03 11:04 ` Richard Biener
1 sibling, 0 replies; 4+ messages in thread
From: Richard Biener @ 2017-03-03 11:04 UTC (permalink / raw)
To: Bernd Schmidt; +Cc: Martin Liška, GCC Patches
On Thu, Mar 2, 2017 at 8:58 PM, Bernd Schmidt <bschmidt@redhat.com> wrote:
> On 03/02/2017 06:50 PM, Martin Liška wrote:
>>
>> Hello.
>>
>> This is second part of fixes needed to not trigger integer overflow in
>> gcse pass.
>
>
> So, how is this intended to work? The min/max stored in the param is an int,
> and by using a HOST_WIDE_INT here, we expect that it is a larger type and
> therefore won't overflow?
HOST_WIDE_INT is equal to uint64_t (and we could mass-replace where we can
do so consistently)
Richard.
>> {
>> expr = flat_table[i];
>> fprintf (file, "Index %d (hash value %d; max distance %d)\n ",
>> - expr->bitmap_index, hash_val[i], expr->max_distance);
>> + expr->bitmap_index, hash_val[i],
>> (int)expr->max_distance);
>> print_rtl (file, expr->expr);
>> fprintf (file, "\n");
>
>
> Use HOST_WIDE_INT_PRINT_DEC maybe? Otherwise OK, I guess.
>
>
> Bernd
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2017-03-03 11:04 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-02 17:50 GCSE: Use HOST_WIDE_INT instead of int (PR, rtl-optimization/79574) Martin Liška
2017-03-02 19:58 ` Bernd Schmidt
2017-03-03 10:31 ` Martin Liška
2017-03-03 11:04 ` Richard Biener
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).