This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: FW: [PATCH] Avoid a few find_base_term calls in alias.c
- From: Yuri Rumyantsev <ysrumyan at gmail dot com>
- To: gcc-patches <gcc-patches at gcc dot gnu dot org>, Richard Biener <richard dot guenther at gmail dot com>, Igor Zamyatin <izamyatin at gmail dot com>
- Date: Thu, 4 Apr 2013 18:12:18 +0400
- Subject: Re: FW: [PATCH] Avoid a few find_base_term calls in alias.c
- References: <alpine dot LNX dot 2 dot 00 dot 1303261328590 dot 3543 at zhemvz dot fhfr dot qr> <0EFAB2BDD0F67E4FB6CCC8B9F87D7569160DFB90 at IRSMSX101 dot ger dot corp dot intel dot com> <CAEoMCqQWckc0SjN5L2zHcuMvmV-s6x9QdK6HQd_BWBYg9DHeXA at mail dot gmail dot com>
Hi Richard,
You slightly change behavior of find_base_term, namely before your fix
we have the following code:
if (REG_P (tmp1) && REG_POINTER (tmp1))
{
rtx base = find_base_term (tmp1);
if (base)
return base;
}
but in your fix you added the following checks on base:
tmp1 = find_base_term (tmp1);
if (tmp1 != NULL_RTX
&& ((REG_P (tmp1) && REG_POINTER (tmp1))
|| known_base_value_p (tmp1)))
return tmp1;
Why you added these checks since function arguments may not considered as bases.
Thanks in advance.
Yuri.
-----Original Message-----
From: gcc-patches-owner@gcc.gnu.org
[mailto:gcc-patches-owner@gcc.gnu.org] On Behalf Of Richard Biener
Sent: Tuesday, March 26, 2013 4:33 PM
To: gcc-patches@gcc.gnu.org
Subject: [PATCH] Avoid a few find_base_term calls in alias.c
We have already computed the base term for some of the arguments of
some calls to base_alias_check. PR39326 shows that find_base_term is
very costly called from RTL PRE at -O2 (it mostly recurses through the
PLUS/MINUS_EXPR case). The following patch avoids computing
find_base_term when not really necessary.
Bootstrapped and tested on x86_64-unknown-linux-gnu.
Richard.
2013-03-26 Richard Biener <rguenther@suse.de>
* alias.c (find_base_term): Avoid redundant and not used
recursion.
(base_alias_check): Get the initial base term from the
caller.
(true_dependence_1): Compute and pass base terms to base_alias_check.
(write_dependence_p): Likewise.
(may_alias_p): Likewise.
Index: gcc/alias.c
===================================================================
--- gcc/alias.c (revision 197095)
+++ gcc/alias.c (working copy)
@@ -148,7 +148,7 @@ typedef struct alias_set_entry_d *alias_ static
int rtx_equal_for_memref_p (const_rtx, const_rtx); static int
memrefs_conflict_p (int, rtx, int, rtx, HOST_WIDE_INT); static void
record_set (rtx, const_rtx, void *); -static int base_alias_check
(rtx, rtx, enum machine_mode,
+static int base_alias_check (rtx, rtx, rtx, rtx, enum machine_mode,
enum machine_mode);
static rtx find_base_value (rtx);
static int mems_in_disjoint_alias_sets_p (const_rtx, const_rtx); @@
-1672,34 +1672,30 @@ find_base_term (rtx x)
if (tmp1 == pic_offset_table_rtx && CONSTANT_P (tmp2))
return find_base_term (tmp2);
- /* If either operand is known to be a pointer, then use it
+ /* If either operand is known to be a pointer, then prefer it
to determine the base term. */
if (REG_P (tmp1) && REG_POINTER (tmp1))
+ ;
+ else if (REG_P (tmp2) && REG_POINTER (tmp2))
{
- rtx base = find_base_term (tmp1);
- if (base)
- return base;
+ rtx tem = tmp1;
+ tmp1 = tmp2;
+ tmp2 = tem;
}
- if (REG_P (tmp2) && REG_POINTER (tmp2))
- {
- rtx base = find_base_term (tmp2);
- if (base)
- return base;
- }
-
- /* Neither operand was known to be a pointer. Go ahead and find the
- base term for both operands. */
- tmp1 = find_base_term (tmp1);
- tmp2 = find_base_term (tmp2);
-
- /* If either base term is named object or a special address
+ /* Go ahead and find the base term for both operands. If either base
+ term is from a pointer or is a named object or a special address
(like an argument or stack reference), then use it for the
base term. */
- if (tmp1 != 0 && known_base_value_p (tmp1))
+ tmp1 = find_base_term (tmp1);
+ if (tmp1 != NULL_RTX
+ && ((REG_P (tmp1) && REG_POINTER (tmp1))
+ || known_base_value_p (tmp1)))
return tmp1;
-
- if (tmp2 != 0 && known_base_value_p (tmp2))
+ tmp2 = find_base_term (tmp2);
+ if (tmp2 != NULL_RTX
+ && ((REG_P (tmp2) && REG_POINTER (tmp2))
+ || known_base_value_p (tmp2)))
return tmp2;
/* We could not determine which of the two operands was the @@
-1736,12 +1732,9 @@ may_be_sp_based_p (rtx x)
objects, 1 if they might be pointers to the same object. */
static int
-base_alias_check (rtx x, rtx y, enum machine_mode x_mode,
- enum machine_mode y_mode)
+base_alias_check (rtx x, rtx x_base, rtx y, rtx y_base,
+ enum machine_mode x_mode, enum machine_mode y_mode)
{
- rtx x_base = find_base_term (x);
- rtx y_base = find_base_term (y);
-
/* If the address itself has no known base see if a known equivalent
value has one. If either address still has no known base, nothing
is known about aliasing. */
@@ -2511,7 +2504,9 @@ true_dependence_1 (const_rtx mem, enum m
&& CONSTANT_POOL_ADDRESS_P (base))))
return 0;
- if (! base_alias_check (x_addr, mem_addr, GET_MODE (x), mem_mode))
+ rtx mem_base = find_base_term (mem_addr);
+ if (! base_alias_check (x_addr, base, mem_addr, mem_base,
+ GET_MODE (x), mem_mode))
return 0;
x_addr = canon_rtx (x_addr);
@@ -2603,16 +2598,16 @@ write_dependence_p (const_rtx mem, const
mem_addr = get_addr (mem_addr);
}
- if (! writep)
- {
- base = find_base_term (mem_addr);
- if (base && (GET_CODE (base) == LABEL_REF
- || (GET_CODE (base) == SYMBOL_REF
- && CONSTANT_POOL_ADDRESS_P (base))))
- return 0;
- }
+ base = find_base_term (mem_addr);
+ if (! writep
+ && base
+ && (GET_CODE (base) == LABEL_REF
+ || (GET_CODE (base) == SYMBOL_REF
+ && CONSTANT_POOL_ADDRESS_P (base))))
+ return 0;
- if (! base_alias_check (x_addr, mem_addr, GET_MODE (x),
+ rtx x_base = find_base_term (x_addr); if (! base_alias_check
+ (x_addr, x_base, mem_addr, base, GET_MODE (x),
GET_MODE (mem)))
return 0;
@@ -2692,7 +2687,10 @@ may_alias_p (const_rtx mem, const_rtx x)
mem_addr = get_addr (mem_addr);
}
- if (! base_alias_check (x_addr, mem_addr, GET_MODE (x), GET_MODE (mem_addr)))
+ rtx x_base = find_base_term (x_addr);
+ rtx mem_base = find_base_term (mem_addr);
+ if (! base_alias_check (x_addr, x_base, mem_addr, mem_base,
+ GET_MODE (x), GET_MODE (mem_addr)))
return 0;
x_addr = canon_rtx (x_addr);