From patchwork Tue Jul 5 17:07:45 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 103349 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]) by ozlabs.org (Postfix) with SMTP id 21C3BB6EDF for ; Wed, 6 Jul 2011 03:08:16 +1000 (EST) Received: (qmail 14468 invoked by alias); 5 Jul 2011 17:08:14 -0000 Received: (qmail 14450 invoked by uid 22791); 5 Jul 2011 17:08:12 -0000 X-SWARE-Spam-Status: No, hits=-2.3 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW X-Spam-Check-By: sourceware.org Received: from mail-qw0-f47.google.com (HELO mail-qw0-f47.google.com) (209.85.216.47) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 05 Jul 2011 17:07:46 +0000 Received: by qwh5 with SMTP id 5so3494484qwh.20 for ; Tue, 05 Jul 2011 10:07:45 -0700 (PDT) MIME-Version: 1.0 Received: by 10.229.18.77 with SMTP id v13mr5749117qca.56.1309885665659; Tue, 05 Jul 2011 10:07:45 -0700 (PDT) Received: by 10.229.214.83 with HTTP; Tue, 5 Jul 2011 10:07:45 -0700 (PDT) In-Reply-To: References: <201107051456.p65EuTNj023652@d06av02.portsmouth.uk.ibm.com> Date: Tue, 5 Jul 2011 10:07:45 -0700 Message-ID: Subject: Re: PING: PATCH [9/n]: Prepare x32: PR middle-end/47383: ivopts miscompiles Pmode != ptr_mode From: "H.J. Lu" To: Richard Guenther Cc: Ulrich Weigand , gcc-patches@gcc.gnu.org, Ulrich Weigand X-IsSubscribed: yes 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 On Tue, Jul 5, 2011 at 8:24 AM, Richard Guenther wrote: > On Tue, Jul 5, 2011 at 4:56 PM, Ulrich Weigand wrote: >> H.J. Lu wrote: >> >>> > However, this still seems odd to me, as I had understood the address in >>> > a TARGET_MEM_REF needs to be an *address*, i.e. use address_mode. =A0If >>> > this is not true (has changed?) a lot of other places would need to >>> > change as well ... >>> >>> I was told that TARGET_MEM_REF needs ptr_mode. >> >> Can you elaborate?  We are talking about the mode returned from >> addr_for_mem_ref here.  I do now understand how this can be anything >> but an address mode: > > That is an address mode, but the intermediate computation > (base + index * step + offset) is done in pointer mode.  The > code currently performs this in address mode as well which is > bogus.  Which is why I suggested to use pointer mode for the > computation (now, with the other target hook you mention) and > then convert the result to address mode. > I am testing this [patch. OK for trunk if there are no regressions? Thanks. diff --git a/gcc/ChangeLog.x32 b/gcc/ChangeLog.x32 index c5edfe7..7d85746 100644 --- a/gcc/ChangeLog.x32 +++ b/gcc/ChangeLog.x32 @@ -1,5 +1,11 @@ 2011-07-05 H.J. Lu + PR middle-end/47383 + * tree-ssa-address.c (addr_for_mem_ref): Use pointer_mode for + address computation and convert to address_mode if needed. + +2011-07-05 H.J. Lu + * tree-ssa-address.c (addr_for_mem_ref): Use targetm.addr_space.address_mode. diff --git a/gcc/testsuite/ChangeLog.x32 b/gcc/testsuite/ChangeLog.x32 index cde8d41..492be5c 100644 --- a/gcc/testsuite/ChangeLog.x32 +++ b/gcc/testsuite/ChangeLog.x32 @@ -1,3 +1,8 @@ +2011-07-05 H.J. Lu + + PR middle-end/47383 + * gcc.dg/pr47383.c: New. + 2011-06-23 H.J. Lu * gcc.target/i386/pr49504.c (main): Check correct return value. diff --git a/gcc/testsuite/gcc.dg/pr47383.c b/gcc/testsuite/gcc.dg/pr47383.c new file mode 100644 index 0000000..3e2b9ba --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr47383.c @@ -0,0 +1,31 @@ +/* { dg-do run { target fpic } } */ +/* { dg-options "-O2 -fPIC" } */ + +static int heap[2*(256 +1+29)+1]; +static int heap_len; +static int heap_max; +void +__attribute__ ((noinline)) +foo (int elems) +{ + int n, m; + int max_code = -1; + int node = elems; + heap_len = 0, heap_max = (2*(256 +1+29)+1); + for (n = 0; n < elems; n++) + heap[++heap_len] = max_code = n; + do { + n = heap[1]; + heap[1] = heap[heap_len--]; + m = heap[1]; + heap[--heap_max] = n; + heap[--heap_max] = m; + } while (heap_len >= 2); +} + +int +main () +{ + foo (286); + return 0; +} diff --git a/gcc/tree-ssa-address.c b/gcc/tree-ssa-address.c index e3934e1..c6dced1 100644 --- a/gcc/tree-ssa-address.c +++ b/gcc/tree-ssa-address.c @@ -189,11 +189,12 @@ addr_for_mem_ref (struct mem_address *addr, addr_space_t as, bool really_expand) { enum machine_mode address_mode = targetm.addr_space.address_mode (as); + enum machine_mode pointer_mode = targetm.addr_space.pointer_mode (as); rtx address, sym, bse, idx, st, off; struct mem_addr_template *templ; if (addr->step && !integer_onep (addr->step)) - st = immed_double_int_const (tree_to_double_int (addr->step), address_mode); + st = immed_double_int_const (tree_to_double_int (addr->step), pointer_mode);