From patchwork Mon Jun 8 17:45:26 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 481950 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.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 455BE1401B5 for ; Tue, 9 Jun 2015 03:46:21 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=Qx3K6Wcx; dkim-atps=neutral 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:mime-version:to:cc:subject:references :in-reply-to:content-type; q=dns; s=default; b=Nc0RT3xWc6SslvzV7 pDtFhZxmXRIizx0ySMm1yYkx77zbQ4aCvqXD73lwFv4ubBbARWpABUwj9W+VXEnJ WaNadQqcc/6c9gvAmsVoah4Mf3pATrtz0xcIwOnh/56P8ZCxF9/8K5vkCx2luI5O Wukfx6Am53s9yHQN3ipZZKAz6Q= 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:mime-version:to:cc:subject:references :in-reply-to:content-type; s=default; bh=lyJI/LLmxAjPXyuh5W62vv7 JP+A=; b=Qx3K6WcxDe9NnLrOOGQHBpAKT3lpPIss0IVuloQqp//nsFjLYZ7jQVK C0UhsZEck7nzpNPMVswewtJbxgSUg1RywIY8DAX6S+Bqovwi8LZJ8v+mTT2USU8l GvzsHOKdlsbKfE4P4QwF5/e8ALg1iuf6QcJABJKafPalHonRt8jM= Received: (qmail 118684 invoked by alias); 8 Jun 2015 17:46:13 -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 118021 invoked by uid 89); 8 Jun 2015 17:46:12 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL, BAYES_00, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: fencepost.gnu.org Received: from fencepost.gnu.org (HELO fencepost.gnu.org) (208.118.235.10) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Mon, 08 Jun 2015 17:46:11 +0000 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53826) by fencepost.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1Z217g-0000IO-L3 for gcc-patches@gnu.org; Mon, 08 Jun 2015 13:46:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Z217Z-0005zk-P2 for gcc-patches@gnu.org; Mon, 08 Jun 2015 13:46:08 -0400 Received: from relay1.mentorg.com ([192.94.38.131]:53564) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z217Z-0005zW-EU for gcc-patches@gnu.org; Mon, 08 Jun 2015 13:46:01 -0400 Received: from nat-ies.mentorg.com ([192.94.31.2] helo=SVR-IES-FEM-01.mgc.mentorg.com) by relay1.mentorg.com with esmtp id 1Z217X-0004vU-5y from Tom_deVries@mentor.com ; Mon, 08 Jun 2015 10:45:59 -0700 Received: from [127.0.0.1] (137.202.0.76) by SVR-IES-FEM-01.mgc.mentorg.com (137.202.0.104) with Microsoft SMTP Server id 14.3.224.2; Mon, 8 Jun 2015 18:45:37 +0100 Message-ID: <5575D4B6.10606@mentor.com> Date: Mon, 8 Jun 2015 19:45:26 +0200 From: Tom de Vries User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 MIME-Version: 1.0 To: Jakub Jelinek CC: Subject: Re: [PATCH, PR66444] Handle -fipa-ra in reload_combine References: <557584BC.2040603@mentor.com> <20150608153151.GW10247@tucnak.redhat.com> In-Reply-To: <20150608153151.GW10247@tucnak.redhat.com> X-detected-operating-system: by eggs.gnu.org: Windows NT kernel [generic] [fuzzy] X-Received-From: 192.94.38.131 On 08/06/15 17:31, Jakub Jelinek wrote: > On Mon, Jun 08, 2015 at 02:04:12PM +0200, Tom de Vries wrote: >> this patch fixes PR66444, a problem with -fipa-ra in reload_combine. >> >> The problem is that for the test-case, reload_combine combines these two >> insns: > > Please work out with Vlad whether reload_cse_move2add doesn't need similar > fix (and check other spots too). > >> 2015-06-08 Tom de Vries >> >> PR rtl-optimization/66444 >> * postreload.c (reload_combine): Use get_call_reg_set_usage instead of >> call_used_regs. > > LGTM. > >> * gcc.dg/pr66444.c: New test. > >> +int __attribute__((noinline, noclone)) >> +baz (void) >> +{ >> + struct S *x = (struct S *) 0xe0000000U; > > I'm still afraid this will not really work on s390-linux (which has only > 31-bit pointers) and will not work on 16-bit int targets either > (some have say 24-bit pointers etc., not really familiar with the embedded > world). > So, I'd suggest use a macro for the address, so you don't need to duplicate > it, Used a macro CONST_PTR. > and define it to say ((struct S *) 0x8000UL), if it reproduces > even with that change without your reload_combine fix. Unfortunately, it didn't. So I used __SIZEOF_POINTER__ to produce a valid constant pointer for the 16-31 bit pointer-size cases, while still triggering the original problem for x86_64 -m64 case using a larger pointer. Furthermore, I used __SIZEOF_POINTER__ to ensured a valid pointer constant suffix. > > Ok for trunk and 5.2 with that change. Committed to trunk and backported gcc-5-branch as attached. Thanks, - Tom Handle -fipa-ra in reload_combine 2015-06-08 Tom de Vries PR rtl-optimization/66444 * postreload.c (reload_combine): Use get_call_reg_set_usage instead of call_used_regs. * gcc.dg/pr66444.c: New test. --- gcc/postreload.c | 5 ++- gcc/testsuite/gcc.dg/pr66444.c | 79 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/pr66444.c diff --git a/gcc/postreload.c b/gcc/postreload.c index 7ecca15..1cc7b14 100644 --- a/gcc/postreload.c +++ b/gcc/postreload.c @@ -1352,9 +1352,12 @@ reload_combine (void) if (CALL_P (insn)) { rtx link; + HARD_REG_SET used_regs; + + get_call_reg_set_usage (insn, &used_regs, call_used_reg_set); for (r = 0; r < FIRST_PSEUDO_REGISTER; r++) - if (call_used_regs[r]) + if (TEST_HARD_REG_BIT (used_regs, r)) { reg_state[r].use_index = RELOAD_COMBINE_MAX_USES; reg_state[r].store_ruid = reload_combine_ruid; diff --git a/gcc/testsuite/gcc.dg/pr66444.c b/gcc/testsuite/gcc.dg/pr66444.c new file mode 100644 index 0000000..3f92a5c --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr66444.c @@ -0,0 +1,79 @@ +/* { dg-do run } */ +/* { dg-options "-O2 -fipa-ra" } */ + +extern void abort (void); + +#if (__SIZEOF_LONG_LONG__ == __SIZEOF_POINTER__) +#define ADD_SUFFIX(a) a ## ULL +#elif (__SIZEOF_LONG__ == __SIZEOF_POINTER__) +#define ADD_SUFFIX(a) a ## UL +#elif (__SIZEOF_INT__ == __SIZEOF_POINTER__) +#define ADD_SUFFIX(a) a ## U +#else +#error Add target support here +#endif + +#if __SIZEOF_POINTER__ <= 4 +/* Use a 16 bit pointer to have a valid pointer for 16-bit to 31-bit pointer + architectures. Using sizeof, we cannot distinguish between 31-bit and 32-bit + pointer types, so we also handle the 32-bit pointer type case here. */ +#define CONST_PTR ADD_SUFFIX (0x800) +#else +/* For x86_64 -m64, the problem reproduces with this 32-bit CONST_PTR, but not + with a 2-power below it. */ +#define CONST_PTR ADD_SUFFIX (0x80000000) +#endif + +int __attribute__((noinline, noclone)) +bar (void) +{ + return 1; +} + +struct S +{ + unsigned long p, q, r; + void *v; +}; + +struct S *s1; +struct S *s2; + +void __attribute__((noinline, noclone)) +fn2 (struct S *x) +{ + s2 = x; +} + +__attribute__((noinline, noclone)) void * +fn1 (struct S *x) +{ + /* Just a statement to make it a non-const function. */ + s1 = x; + + return (void *)0; +} + +int __attribute__((noinline, noclone)) +baz (void) +{ + struct S *x = (struct S *) CONST_PTR; + + x += bar (); + + fn1 (x); + fn2 (x); + + return 0; +} + +int +main (void) +{ + baz (); + + if (s2 != (((struct S *) CONST_PTR) + 1)) + abort (); + + return 0; +} -- 1.9.1