From patchwork Sun Jun 16 13:26:26 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joern Rennecke X-Patchwork-Id: 251679 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "localhost", Issuer "www.qmailtoaster.com" (not verified)) by ozlabs.org (Postfix) with ESMTPS id D9FE32C00AF for ; Sun, 16 Jun 2013 23:26:42 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:to:cc:subject:references:in-reply-to :mime-version:content-type:content-transfer-encoding; q=dns; s= default; b=QXxODK54roH5d5gLZVd0LtMiL+GHvL6cRBRs96/YwdogmgWlJXJ+f hX8khZjt8Z6yWnyAbpWPr6dZ/0ZE6tvoOhjX7xiPwuRz7caTW5v8N4ZnZswSB3i7 FYkxahaxcsNc0QEkjLZOSZL/hBOcPOhrPYgMxXi5IzXFtyJ3gywnqE= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:to:cc:subject:references:in-reply-to :mime-version:content-type:content-transfer-encoding; s=default; bh=dz3X/LQsW2jvU4s3J/d5L4mzHJs=; b=vwRUvA2tIJPbVNYsMyK8eryTjNc0 veu88imbA+kVxf1HzPiYN5ikYzKj31oapJ87pUCti1pCirH46OigJvQrgoHs2UGw YOYZU/npa2IE0fW9KQq69otOTRtVZdpGkhjqL4W5Eff0MS9Z8tSv0aG4HqoTendA qsBkKElmKLhlF1c= Received: (qmail 13570 invoked by alias); 16 Jun 2013 13:26:35 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 13526 invoked by uid 89); 16 Jun 2013 13:26:29 -0000 X-Spam-SWARE-Status: No, score=-3.2 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, KHOP_THREADED, MIME_QP_LONG_LINE, RCVD_IN_DNSWL_MED, TW_SV autolearn=ham version=3.3.1 Received: from c62.cesmail.net (HELO c62.cesmail.net) (216.154.195.54) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Sun, 16 Jun 2013 13:26:28 +0000 Received: from unknown (HELO delta2) ([192.168.1.50]) by c62.cesmail.net with ESMTP; 16 Jun 2013 09:26:26 -0400 Received: from cust213-dsl91-135-11.idnet.net (cust213-dsl91-135-11.idnet.net [91.135.11.213]) by webmail.spamcop.net (Horde MIME library) with HTTP; Sun, 16 Jun 2013 09:26:26 -0400 Message-ID: <20130616092626.oidnkv1n8gkg808w-nzlynne@webmail.spamcop.net> Date: Sun, 16 Jun 2013 09:26:26 -0400 From: Joern Rennecke To: Eric Botcazou Cc: gcc-patches@gcc.gnu.org, Michael Matz Subject: Re: RFA: Fix rtl-optimization/57425 References: <20130615190823.wzbakvee68w0kcwo-nzlynne@webmail.spamcop.net> <1601106.B4Cs0hoEPR@polaris> In-Reply-To: <1601106.B4Cs0hoEPR@polaris> MIME-Version: 1.0 User-Agent: Internet Messaging Program (IMP) H3 (4.1.4) X-Virus-Found: No Quoting Eric Botcazou : > Could you also check that your patch also fixes PR opt/57569 and, if so, add > the reference to the ChangeLog as well as the testcase? Attached is what I'm currently testing. bootstrap on i686-pc-linux-gnu finished, now regtesting. On x86_64-pc-linux-gnu, bootstrap is still in progress & I also still have to verify if the pr57569.c testcase FAILs/PASSes for unpatched/patched svn trunk. 2013-06-15 Joern Rennecke gcc: PR rtl-optimization/57425 PR rtl-optimization/57569 * alias.c (write_dependence_p): Add new parameters mem_size, canon_mem_addr and mem_canonicalized. Change type of writep to bool. Changed all callers. (canon_anti_dependence): New function. * cse.c (check_dependence): Use canon_anti_dependence. * cselib.c (cselib_invalidate_mem): Likewise. * rtl.h (canon_anti_dependence): Declare. gcc/testsuite: PR rtl-optimization/57425 PR rtl-optimization/57569 * gcc.dg/torture/pr57425-1.c, gcc.dg/torture/pr57425-2.c: New files. * gcc.dg/torture/pr57425-3.c, gcc.dg/torture/pr57569.c: Likewise. Index: alias.c =================================================================== --- alias.c (revision 200126) +++ alias.c (working copy) @@ -156,7 +156,8 @@ static int insert_subset_children (splay static alias_set_entry get_alias_set_entry (alias_set_type); static bool nonoverlapping_component_refs_p (const_rtx, const_rtx); static tree decl_for_component_ref (tree); -static int write_dependence_p (const_rtx, const_rtx, int); +static int write_dependence_p (const_rtx, enum machine_mode, rtx, const_rtx, + bool, bool); static void memory_modified_1 (rtx, const_rtx, void *); @@ -2553,15 +2554,22 @@ canon_true_dependence (const_rtx mem, en } /* Returns nonzero if a write to X might alias a previous read from - (or, if WRITEP is nonzero, a write to) MEM. */ + (or, if WRITEP is true, a write to) MEM. + If MEM_CANONCALIZED is nonzero, CANON_MEM_ADDR is the canonicalized + address of MEM, and MEM_MODE the mode for that access. */ static int -write_dependence_p (const_rtx mem, const_rtx x, int writep) +write_dependence_p (const_rtx mem, enum machine_mode mem_mode, + rtx canon_mem_addr, const_rtx x, + bool mem_canonicalized, bool writep) { rtx x_addr, mem_addr; rtx base; int ret; + gcc_checking_assert (mem_canonicalized ? (canon_mem_addr != NULL_RTX) + : (canon_mem_addr == NULL_RTX && mem_mode == VOIDmode)); + if (MEM_VOLATILE_P (x) && MEM_VOLATILE_P (mem)) return 1; @@ -2612,9 +2620,15 @@ write_dependence_p (const_rtx mem, const return 0; x_addr = canon_rtx (x_addr); - mem_addr = canon_rtx (mem_addr); + if (mem_canonicalized) + mem_addr = canon_mem_addr; + else + { + mem_addr = canon_rtx (mem_addr); + mem_mode = GET_MODE (mem); + } - if ((ret = memrefs_conflict_p (SIZE_FOR_MODE (mem), mem_addr, + if ((ret = memrefs_conflict_p (GET_MODE_SIZE (mem_mode), mem_addr, SIZE_FOR_MODE (x), x_addr, 0)) != -1) return ret; @@ -2629,7 +2643,20 @@ write_dependence_p (const_rtx mem, const int anti_dependence (const_rtx mem, const_rtx x) { - return write_dependence_p (mem, x, /*writep=*/0); + return write_dependence_p (mem, VOIDmode, NULL_RTX, x, + /*mem_canonicalized=*/false, /*writep=*/false); +} + +/* Likewise, but we already have a canonicalized MEM_ADDR for MEM. + Also, consider MEM in MEM_MODE (which might be from an enclosing + STRICT_LOW_PART / ZERO_EXTRACT). */ + +int +canon_anti_dependence (const_rtx mem, enum machine_mode mem_mode, + rtx mem_addr, const_rtx x) +{ + return write_dependence_p (mem, mem_mode, mem_addr, x, + /*mem_canonicalized=*/true, /*writep=*/false); } /* Output dependence: X is written after store in MEM takes place. */ @@ -2637,7 +2664,8 @@ anti_dependence (const_rtx mem, const_rt int output_dependence (const_rtx mem, const_rtx x) { - return write_dependence_p (mem, x, /*writep=*/1); + return write_dependence_p (mem, VOIDmode, NULL_RTX, x, + /*mem_canonicalized=*/false, /*writep=*/true); } Index: cse.c =================================================================== --- cse.c (revision 200126) +++ cse.c (working copy) @@ -1824,7 +1824,7 @@ flush_hash_table (void) } } -/* Function called for each rtx to check whether true dependence exist. */ +/* Function called for each rtx to check whether an anti dependence exist. */ struct check_dependence_data { enum machine_mode mode; @@ -1837,7 +1837,7 @@ check_dependence (rtx *x, void *data) { struct check_dependence_data *d = (struct check_dependence_data *) data; if (*x && MEM_P (*x)) - return canon_true_dependence (d->exp, d->mode, d->addr, *x, NULL_RTX); + return canon_anti_dependence (d->exp, d->mode, d->addr, *x); else return 0; } Index: cselib.c =================================================================== --- cselib.c (revision 200126) +++ cselib.c (working copy) @@ -2263,8 +2263,8 @@ cselib_invalidate_mem (rtx mem_rtx) continue; } if (num_mems < PARAM_VALUE (PARAM_MAX_CSELIB_MEMORY_LOCATIONS) - && ! canon_true_dependence (mem_rtx, GET_MODE (mem_rtx), - mem_addr, x, NULL_RTX)) + && ! canon_anti_dependence (mem_rtx, GET_MODE (mem_rtx), + mem_addr, x)) { has_mem = true; num_mems++; Index: rtl.h =================================================================== --- rtl.h (revision 200126) +++ rtl.h (working copy) @@ -2705,6 +2705,8 @@ extern int canon_true_dependence (const_ const_rtx, rtx); extern int read_dependence (const_rtx, const_rtx); extern int anti_dependence (const_rtx, const_rtx); +extern int canon_anti_dependence (const_rtx, enum machine_mode, rtx, + const_rtx); extern int output_dependence (const_rtx, const_rtx); extern int may_alias_p (const_rtx, const_rtx); extern void init_alias_target (void); Index: testsuite/gcc.dg/torture/pr57425-1.c =================================================================== --- testsuite/gcc.dg/torture/pr57425-1.c (revision 0) +++ testsuite/gcc.dg/torture/pr57425-1.c (working copy) @@ -0,0 +1,37 @@ +/* { dg-do run } */ + +extern void abort (void) __attribute__((noreturn)); + +union setconflict +{ + int a[20]; + long b[10]; +}; + +int +main () +{ + int sum = 0; + { + union setconflict a; + int *c; + c = a.a; + asm ("": "=r" (c):"0" (c)); + *c = 0; + asm ("": "=r" (c):"0" (c)); + sum += *c; + } + { + union setconflict a; + long *c; + c = a.b; + asm ("": "=r" (c):"0" (c)); + *c = 1; + asm ("": "=r" (c):"0" (c)); + sum += *c; + } + + if (sum != 1) + abort(); + return 0; +} Index: testsuite/gcc.dg/torture/pr57425-2.c =================================================================== --- testsuite/gcc.dg/torture/pr57425-2.c (revision 0) +++ testsuite/gcc.dg/torture/pr57425-2.c (working copy) @@ -0,0 +1,31 @@ +/* { dg-do run } */ + +extern void abort (void) __attribute__((noreturn)); + +int +main () +{ + int sum = 0; + { + int a[20]; + int *c; + c = a; + asm ("": "=r" (c):"0" (c)); + *c = 0; + asm ("": "=r" (c):"0" (c)); + sum += *c; + } + { + long b[10]; + long *c; + c = b; + asm ("": "=r" (c):"0" (c)); + *c = 1; + asm ("": "=r" (c):"0" (c)); + sum += *c; + } + + if (sum != 1) + abort(); + return 0; +} Index: testsuite/gcc.dg/torture/pr57425-3.c =================================================================== --- testsuite/gcc.dg/torture/pr57425-3.c (revision 0) +++ testsuite/gcc.dg/torture/pr57425-3.c (working copy) @@ -0,0 +1,31 @@ +/* { dg-do run } */ + +extern void abort (void) __attribute__((noreturn)); + +int +main () +{ + int sum = 0; + { + long a[20]; + long *c; + c = a; + asm ("": "=r" (c):"0" (c)); + *c = 0; + asm ("": "=r" (c):"0" (c)); + sum += *c; + } + { + long long b[10]; + long long *c; + c = b; + asm ("": "=r" (c):"0" (c)); + *c = 1; + asm ("": "=r" (c):"0" (c)); + sum += *c; + } + + if (sum != 1) + abort(); + return 0; +} Index: testsuite/gcc.dg/torture/pr57569.c =================================================================== --- testsuite/gcc.dg/torture/pr57569.c (revision 0) +++ testsuite/gcc.dg/torture/pr57569.c (working copy) @@ -0,0 +1,37 @@ +/* { dg-do run } */ + +extern void abort (void) __attribute__((noreturn)); + +struct S { int f0; } a; + +int b, e, *d = &b, f; + +void +fn1 () +{ + int **g[9][6]; + int ***h = &g[6][3]; + for (; e < 9; e++) { + f = 0; + for (; f < 6; f++) + g[e][f] = &d; + } + ***h = 0; +} + +void +fn2 () +{ + fn1 (); + struct S c[4][10] = {}; + a = c[3][9]; +} + +int +main () +{ + fn2 (); + if (a.f0 != 0) + abort (); + return 0; +}