Commit b58b21d5 by Roger Sayle Committed by Roger Sayle

re PR rtl-optimization/12322 (Significant slowdown when compiling computed-goto code in Parrot)


	PR optimization/12322
	* gcse.c (struct ls_expr): Change type of hash_index from int to
	unsigned int.
	(hash_expr): Document hash_table_size parameter and wrap long line.
	(ldst_entry): Calculate expression's hash_index and record in ptr.
	(trim_ld_motion_mems): Use hash_index to search a single bucket
	instead of scanning the entire hash_table.  Remove the "del" local
	variable and use the equivalent "expr == 0" instead.  Change last
	to be a pointer to the pointer to the current element, to simplify
	and speed-up deleting from a linked list.

From-SVN: r74144
parent 98376d4a
2003-12-01 Roger Sayle <roger@eyesopen.com>
PR optimization/12322
* gcse.c (struct ls_expr): Change type of hash_index from int to
unsigned int.
(hash_expr): Document hash_table_size parameter and wrap long line.
(ldst_entry): Calculate expression's hash_index and record in ptr.
(trim_ld_motion_mems): Use hash_index to search a single bucket
instead of scanning the entire hash_table. Remove the "del" local
variable and use the equivalent "expr == 0" instead. Change last
to be a pointer to the pointer to the current element, to simplify
and speed-up deleting from a linked list.
2003-12-01 James E Wilson <wilson@specifixinc.com> 2003-12-01 James E Wilson <wilson@specifixinc.com>
* doc/c-tree.texi (CONSTRUCTOR): Clarify element order and handling * doc/c-tree.texi (CONSTRUCTOR): Clarify element order and handling
......
...@@ -468,7 +468,7 @@ struct ls_expr ...@@ -468,7 +468,7 @@ struct ls_expr
struct ls_expr * next; /* Next in the list. */ struct ls_expr * next; /* Next in the list. */
int invalid; /* Invalid for some reason. */ int invalid; /* Invalid for some reason. */
int index; /* If it maps to a bitmap index. */ int index; /* If it maps to a bitmap index. */
int hash_index; /* Index when in a hash table. */ unsigned int hash_index; /* Index when in a hash table. */
rtx reaching_reg; /* Register to use when re-writing. */ rtx reaching_reg; /* Register to use when re-writing. */
}; };
...@@ -1513,12 +1513,14 @@ oprs_available_p (rtx x, rtx insn) ...@@ -1513,12 +1513,14 @@ oprs_available_p (rtx x, rtx insn)
MODE is only used if X is a CONST_INT. DO_NOT_RECORD_P is a boolean MODE is only used if X is a CONST_INT. DO_NOT_RECORD_P is a boolean
indicating if a volatile operand is found or if the expression contains indicating if a volatile operand is found or if the expression contains
something we don't want to insert in the table. something we don't want to insert in the table. HASH_TABLE_SIZE is
the current size of the hash table to be probed.
??? One might want to merge this with canon_hash. Later. */ ??? One might want to merge this with canon_hash. Later. */
static unsigned int static unsigned int
hash_expr (rtx x, enum machine_mode mode, int *do_not_record_p, int hash_table_size) hash_expr (rtx x, enum machine_mode mode, int *do_not_record_p,
int hash_table_size)
{ {
unsigned int hash; unsigned int hash;
...@@ -6519,28 +6521,29 @@ one_code_hoisting_pass (void) ...@@ -6519,28 +6521,29 @@ one_code_hoisting_pass (void)
static struct ls_expr * static struct ls_expr *
ldst_entry (rtx x) ldst_entry (rtx x)
{ {
int do_not_record_p = 0;
struct ls_expr * ptr; struct ls_expr * ptr;
unsigned int hash;
for (ptr = first_ls_expr(); ptr != NULL; ptr = next_ls_expr (ptr)) hash = hash_expr_1 (x, GET_MODE (x), & do_not_record_p);
if (expr_equiv_p (ptr->pattern, x))
break;
if (!ptr) for (ptr = pre_ldst_mems; ptr != NULL; ptr = ptr->next)
{ if (ptr->hash_index == hash && expr_equiv_p (ptr->pattern, x))
ptr = xmalloc (sizeof (struct ls_expr)); return ptr;
ptr->next = pre_ldst_mems; ptr = xmalloc (sizeof (struct ls_expr));
ptr->expr = NULL;
ptr->pattern = x; ptr->next = pre_ldst_mems;
ptr->pattern_regs = NULL_RTX; ptr->expr = NULL;
ptr->loads = NULL_RTX; ptr->pattern = x;
ptr->stores = NULL_RTX; ptr->pattern_regs = NULL_RTX;
ptr->reaching_reg = NULL_RTX; ptr->loads = NULL_RTX;
ptr->invalid = 0; ptr->stores = NULL_RTX;
ptr->index = 0; ptr->reaching_reg = NULL_RTX;
ptr->hash_index = 0; ptr->invalid = 0;
pre_ldst_mems = ptr; ptr->index = 0;
} ptr->hash_index = hash;
pre_ldst_mems = ptr;
return ptr; return ptr;
} }
...@@ -6800,56 +6803,41 @@ compute_ld_motion_mems (void) ...@@ -6800,56 +6803,41 @@ compute_ld_motion_mems (void)
static void static void
trim_ld_motion_mems (void) trim_ld_motion_mems (void)
{ {
struct ls_expr * last = NULL; struct ls_expr * * last = & pre_ldst_mems;
struct ls_expr * ptr = first_ls_expr (); struct ls_expr * ptr = pre_ldst_mems;
while (ptr != NULL) while (ptr != NULL)
{ {
int del = ptr->invalid; struct expr * expr;
struct expr * expr = NULL;
/* Delete if entry has been made invalid. */ /* Delete if entry has been made invalid. */
if (!del) if (! ptr->invalid)
{ {
unsigned int i;
del = 1;
/* Delete if we cannot find this mem in the expression list. */ /* Delete if we cannot find this mem in the expression list. */
for (i = 0; i < expr_hash_table.size && del; i++) unsigned int hash = ptr->hash_index % expr_hash_table.size;
{
for (expr = expr_hash_table.table[i];
expr != NULL;
expr = expr->next_same_hash)
if (expr_equiv_p (expr->expr, ptr->pattern))
{
del = 0;
break;
}
}
}
if (del) for (expr = expr_hash_table.table[hash];
{ expr != NULL;
if (last != NULL) expr = expr->next_same_hash)
{ if (expr_equiv_p (expr->expr, ptr->pattern))
last->next = ptr->next; break;
free_ldst_entry (ptr);
ptr = last->next;
}
else
{
pre_ldst_mems = pre_ldst_mems->next;
free_ldst_entry (ptr);
ptr = pre_ldst_mems;
}
} }
else else
expr = (struct expr *) 0;
if (expr)
{ {
/* Set the expression field if we are keeping it. */ /* Set the expression field if we are keeping it. */
last = ptr;
ptr->expr = expr; ptr->expr = expr;
last = & ptr->next;
ptr = ptr->next; ptr = ptr->next;
} }
else
{
*last = ptr->next;
free_ldst_entry (ptr);
ptr = * last;
}
} }
/* Show the world what we've found. */ /* Show the world what we've found. */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment