From patchwork Wed Jun 15 08:45:15 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Revital Eres X-Patchwork-Id: 1912 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id AE55D23E52 for ; Wed, 15 Jun 2011 08:45:19 +0000 (UTC) Received: from mail-vx0-f180.google.com (mail-vx0-f180.google.com [209.85.220.180]) by fiordland.canonical.com (Postfix) with ESMTP id 63732A1881E for ; Wed, 15 Jun 2011 08:45:19 +0000 (UTC) Received: by vxk12 with SMTP id 12so161178vxk.11 for ; Wed, 15 Jun 2011 01:45:18 -0700 (PDT) Received: by 10.52.108.101 with SMTP id hj5mr333381vdb.247.1308127518759; Wed, 15 Jun 2011 01:45:18 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.52.183.130 with SMTP id em2cs111935vdc; Wed, 15 Jun 2011 01:45:18 -0700 (PDT) Received: by 10.14.25.144 with SMTP id z16mr122315eez.61.1308127517452; Wed, 15 Jun 2011 01:45:17 -0700 (PDT) Received: from mail-ew0-f50.google.com (mail-ew0-f50.google.com [209.85.215.50]) by mx.google.com with ESMTPS id q43si641353eef.105.2011.06.15.01.45.15 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 15 Jun 2011 01:45:16 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.215.50 is neither permitted nor denied by best guess record for domain of revital.eres@linaro.org) client-ip=209.85.215.50; Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.215.50 is neither permitted nor denied by best guess record for domain of revital.eres@linaro.org) smtp.mail=revital.eres@linaro.org Received: by ewy10 with SMTP id 10so72736ewy.37 for ; Wed, 15 Jun 2011 01:45:15 -0700 (PDT) MIME-Version: 1.0 Received: by 10.213.2.202 with SMTP id 10mr936573ebk.110.1308127515689; Wed, 15 Jun 2011 01:45:15 -0700 (PDT) Received: by 10.213.27.203 with HTTP; Wed, 15 Jun 2011 01:45:15 -0700 (PDT) In-Reply-To: References: Date: Wed, 15 Jun 2011 11:45:15 +0300 Message-ID: Subject: Re: [PATCH, SMS] Fix violation of memory dependence From: Revital Eres To: Ayal Zaks Cc: gcc-patches@gcc.gnu.org, Patch Tracking Hello, >>>         * ddg.c (add_intra_loop_mem_dep): New function. > > You could check first thing if (from->cuid == to->cuid), for code clarity. Attached is the new version of the patch which addresses this. The patch was re-tested as follows: On ppc64-redhat-linux regtest as well as bootstrap with SMS flags enabling SMS also on loops with stage count 1. Regtested on SPU. On arm-linux-gnueabi bootstrap c language with SMS flags enabling SMS also on loops with stage count 1 and currently regression testing on c,c++. OK for mainline once regtest on arm-linux-gnueabi completes? Thanks, Revital gcc/ * ddg.c (add_intra_loop_mem_dep): New function. (build_intra_loop_deps): Call it. testsuite/ * gcc.dg/sms-9.c: New file. Index: ddg.c =================================================================== --- ddg.c (revision 174906) +++ ddg.c (working copy) @@ -390,6 +390,38 @@ insns_may_alias_p (rtx insn1, rtx insn2) &PATTERN (insn2)); } +/* Given two nodes, analyze their RTL insns and add intra-loop mem deps + to ddg G. */ +static void +add_intra_loop_mem_dep (ddg_ptr g, ddg_node_ptr from, ddg_node_ptr to) +{ + + if ((from->cuid == to->cuid) + || !insns_may_alias_p (from->insn, to->insn)) + /* Do not create edge if memory references have disjoint alias sets + or 'to' and 'from' are the same instruction. */ + return; + + if (mem_write_insn_p (from->insn)) + { + if (mem_read_insn_p (to->insn)) + create_ddg_dep_no_link (g, from, to, + DEBUG_INSN_P (to->insn) + ? ANTI_DEP : TRUE_DEP, MEM_DEP, 0); + else + create_ddg_dep_no_link (g, from, to, + DEBUG_INSN_P (to->insn) + ? ANTI_DEP : OUTPUT_DEP, MEM_DEP, 0); + } + else + { + if (mem_read_insn_p (to->insn)) + return; + else + create_ddg_dep_no_link (g, from, to, ANTI_DEP, MEM_DEP, 0); + } +} + /* Given two nodes, analyze their RTL insns and add inter-loop mem deps to ddg G. */ static void @@ -477,10 +509,22 @@ build_intra_loop_deps (ddg_ptr g) if (DEBUG_INSN_P (j_node->insn)) continue; if (mem_access_insn_p (j_node->insn)) - /* Don't bother calculating inter-loop dep if an intra-loop dep - already exists. */ + { + /* Don't bother calculating inter-loop dep if an intra-loop dep + already exists. */ if (! TEST_BIT (dest_node->successors, j)) add_inter_loop_mem_dep (g, dest_node, j_node); + /* If -fmodulo-sched-allow-regmoves + is set certain anti-dep edges are not created. + It might be that these anti-dep edges are on the + path from one memory instruction to another such that + removing these edges could cause a violation of the + memory dependencies. Thus we add intra edges between + every two memory instructions in this case. */ + if (flag_modulo_sched_allow_regmoves + && !TEST_BIT (dest_node->predecessors, j)) + add_intra_loop_mem_dep (g, j_node, dest_node); + } } } } Index: testsuite/gcc.dg/sms-9.c =================================================================== --- testsuite/gcc.dg/sms-9.c (revision 0) +++ testsuite/gcc.dg/sms-9.c (revision 0) @@ -0,0 +1,60 @@ +/* { dg-do run } */ +/* { dg-options "-O2 -fmodulo-sched -fno-auto-inc-dec -O2 -fmodulo-sched-allow-regmoves" } */ + +#include +#include + +struct df_ref_info +{ + unsigned int *begin; + unsigned int *count; +}; + +extern void *memset (void *s, int c, __SIZE_TYPE__ n); + + +__attribute__ ((noinline)) +int +df_reorganize_refs_by_reg_by_insn (struct df_ref_info *ref_info, + int num, unsigned int start) +{ + unsigned int m = num; + unsigned int offset = 77; + unsigned int r; + + for (r = start; r < m; r++) + { + ref_info->begin[r] = offset; + offset += ref_info->count[r]; + ref_info->count[r] = 0; + } + + return offset; +} + +int +main () +{ + struct df_ref_info temp; + int num = 100; + unsigned int start = 5; + int i, offset; + + temp.begin = malloc (100 * sizeof (unsigned int)); + temp.count = malloc (100 * sizeof (unsigned int)); + + memset (temp.begin, 0, sizeof (unsigned int) * num); + memset (temp.count, 0, sizeof (unsigned int) * num); + + for (i = 0; i < num; i++) + temp.count[i] = i + 1; + + offset = df_reorganize_refs_by_reg_by_insn (&temp, num, start); + + if (offset != 5112) + abort (); + + free (temp.begin); + free (temp.count); + return 0; +}