This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH GCC][09/13]Simply cost model merges partitions with the same references
On Wed, Jun 14, 2017 at 2:54 PM, Richard Biener
<richard.guenther@gmail.com> wrote:
> On Mon, Jun 12, 2017 at 7:03 PM, Bin Cheng <Bin.Cheng@arm.com> wrote:
>> Hi,
>> Current primitive cost model merges partitions with data references sharing the same
>> base address. I believe it's designed to maximize data reuse in distribution, but
>> that should be done by dedicated data reusing algorithm. At this stage of merging,
>> we should be conservative and only merge partitions with the same references.
>> Bootstrap and test on x86_64 and AArch64. Is it OK?
>
> Well, I'd say "conservative" is merging more, not less. For example
> splitting a[i+1] from a[i]
> would be bad(?), so I'd see to allow unequal DR_INIT as "equal" for
> merging. Maybe
> DR_INIT within a cacheline or so.
>
> How many extra distributions in say SPEC do you get from this change alone?
Hi,
I collected data for spec2006 only with/without this patch. I am a
bit surprised that it doesn't change the number of distributed loops.
>
> It shows also that having partition->reads_and_writes would be nice
> ... the code duplication
Yeah, I merged read/write data references in previous patch, now this
duplication is gone. Update patch attached. Is it OK?
Thanks.
bin
2017-06-07 Bin Cheng <bin.cheng@arm.com>
* tree-loop-distribution.c (ref_base_address): Delete.
(similar_memory_accesses): Rename ...
(share_memory_accesses): ... to this. Check if partitions access
the same memory reference.
(distribute_loop): Call share_memory_accesses.
From 98af3ab3b309ac7e7b2fb3c6b55eb19a9004225c Mon Sep 17 00:00:00 2001
From: Bin Cheng <binche01@e108451-lin.cambridge.arm.com>
Date: Fri, 9 Jun 2017 12:41:36 +0100
Subject: [PATCH 08/13] share-memory-access-20170608.txt
---
gcc/tree-loop-distribution.c | 71 ++++++++++++++++++++------------------------
1 file changed, 33 insertions(+), 38 deletions(-)
diff --git a/gcc/tree-loop-distribution.c b/gcc/tree-loop-distribution.c
index 03bb735..2e5a828 100644
--- a/gcc/tree-loop-distribution.c
+++ b/gcc/tree-loop-distribution.c
@@ -1268,30 +1268,16 @@ classify_partition (loop_p loop, struct graph *rdg, partition *partition)
}
}
-/* For a data reference REF, return the declaration of its base
- address or NULL_TREE if the base is not determined. */
-
-static tree
-ref_base_address (data_reference_p dr)
-{
- tree base_address = DR_BASE_ADDRESS (dr);
- if (base_address
- && TREE_CODE (base_address) == ADDR_EXPR)
- return TREE_OPERAND (base_address, 0);
-
- return base_address;
-}
-
-/* Returns true when PARTITION1 and PARTITION2 have similar memory
- accesses in RDG. */
+/* Returns true when PARTITION1 and PARTITION2 access the same memory
+ object in RDG. */
static bool
-similar_memory_accesses (struct graph *rdg, partition *partition1,
- partition *partition2)
+share_memory_accesses (struct graph *rdg,
+ partition *partition1, partition *partition2)
{
- unsigned i, j, k, l;
+ unsigned i, j;
bitmap_iterator bi, bj;
- data_reference_p ref1, ref2;
+ data_reference_p dr1, dr2;
/* First check whether in the intersection of the two partitions are
any loads or stores. Common loads are the situation that happens
@@ -1301,23 +1287,32 @@ similar_memory_accesses (struct graph *rdg, partition *partition1,
|| RDG_MEM_READS_STMT (rdg, i))
return true;
- /* Then check all data-references against each other. */
- EXECUTE_IF_SET_IN_BITMAP (partition1->stmts, 0, i, bi)
- if (RDG_MEM_WRITE_STMT (rdg, i)
- || RDG_MEM_READS_STMT (rdg, i))
- EXECUTE_IF_SET_IN_BITMAP (partition2->stmts, 0, j, bj)
- if (RDG_MEM_WRITE_STMT (rdg, j)
- || RDG_MEM_READS_STMT (rdg, j))
- {
- FOR_EACH_VEC_ELT (RDG_DATAREFS (rdg, i), k, ref1)
- {
- tree base1 = ref_base_address (ref1);
- if (base1)
- FOR_EACH_VEC_ELT (RDG_DATAREFS (rdg, j), l, ref2)
- if (base1 == ref_base_address (ref2))
- return true;
- }
- }
+ /* Then check whether the two partitions access the same memory object. */
+ EXECUTE_IF_SET_IN_BITMAP (partition1->datarefs, 0, i, bi)
+ {
+ gcc_assert (i < datarefs_vec.length ());
+ dr1 = datarefs_vec[i];
+
+ if (!DR_BASE_ADDRESS (dr1)
+ || !DR_OFFSET (dr1) || !DR_INIT (dr1) || !DR_STEP (dr1))
+ continue;
+
+ EXECUTE_IF_SET_IN_BITMAP (partition2->datarefs, 0, j, bj)
+ {
+ gcc_assert (j < datarefs_vec.length ());
+ dr2 = datarefs_vec[j];
+
+ if (!DR_BASE_ADDRESS (dr2)
+ || !DR_OFFSET (dr2) || !DR_INIT (dr2) || !DR_STEP (dr2))
+ continue;
+
+ if (operand_equal_p (DR_BASE_ADDRESS (dr1), DR_BASE_ADDRESS (dr2), 0)
+ && operand_equal_p (DR_OFFSET (dr1), DR_OFFSET (dr2), 0)
+ && operand_equal_p (DR_INIT (dr1), DR_INIT (dr2), 0)
+ && operand_equal_p (DR_STEP (dr1), DR_STEP (dr2), 0))
+ return true;
+ }
+ }
return false;
}
@@ -1654,7 +1649,7 @@ distribute_loop (struct loop *loop, vec<gimple *> stmts,
for (int j = i + 1;
partitions.iterate (j, &partition); ++j)
{
- if (similar_memory_accesses (rdg, into, partition))
+ if (share_memory_accesses (rdg, into, partition))
{
partition_merge_into (into, partition, FUSE_SHARE_REF);
partitions.unordered_remove (j);
--
1.9.1