From patchwork Mon Jun 8 12:04:12 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: 481852 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 8E22E14016A for ; Mon, 8 Jun 2015 22:04:54 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=bnP9vVZB; 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:content-type; q=dns; s=default; b=FSWve52Z28qypUzDXQSsDTvx2HsPRxBJOn7S1JLa0F4 jVph54XUBPSvFdShugKZG+VfQFK0BTP5M2plJ3qHNCx5uqUkp30kQH/Qi3cFROGF Vx4YailLrs4DSkYAILmzKan27u25CSNUJ6HH3tRhr3h+Xsk3VoLrfOF5LKHKpF9o = 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:content-type; s=default; bh=VdoPP/BNwt1SFZ40c2cLW2xUTKc=; b=bnP9vVZBAeAXfL66e ZfvpUQYh7MmeVMi40hQn4sf0wc12ydMX90Y86z7uySPJy8cmRRqi/rwUDfeuoxbX w/05enuNwgwF6nhOoWM7PdBg0SrhYUamiKWa+2ygZXHRbsbIXUFuKKfF7R0MCkLM ZE1FnpmL930Y3/nibouEeBoM9w= Received: (qmail 4561 invoked by alias); 8 Jun 2015 12:04:45 -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 4552 invoked by uid 89); 8 Jun 2015 12:04:44 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.6 required=5.0 tests=AWL, BAYES_50, 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 12:04:39 +0000 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33592) by fencepost.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1Z1vnB-000381-D3 for gcc-patches@gnu.org; Mon, 08 Jun 2015 08:04:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Z1vn6-0000Ii-L4 for gcc-patches@gnu.org; Mon, 08 Jun 2015 08:04:37 -0400 Received: from relay1.mentorg.com ([192.94.38.131]:45083) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z1vn6-0000GP-Ey for gcc-patches@gnu.org; Mon, 08 Jun 2015 08:04:32 -0400 Received: from nat-ies.mentorg.com ([192.94.31.2] helo=SVR-IES-FEM-02.mgc.mentorg.com) by relay1.mentorg.com with esmtp id 1Z1vmy-0001sp-Jk from Tom_deVries@mentor.com ; Mon, 08 Jun 2015 05:04:24 -0700 Received: from [127.0.0.1] (137.202.0.76) by SVR-IES-FEM-02.mgc.mentorg.com (137.202.0.106) with Microsoft SMTP Server id 14.3.224.2; Mon, 8 Jun 2015 13:04:23 +0100 Message-ID: <557584BC.2040603@mentor.com> Date: Mon, 8 Jun 2015 14:04:12 +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: CC: Jakub Jelinek Subject: [PATCH, PR66444] Handle -fipa-ra in reload_combine X-detected-operating-system: by eggs.gnu.org: Windows NT kernel [generic] [fuzzy] X-Received-From: 192.94.38.131 Hi, 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: ... (insn 13 12 14 2 (parallel [ (set (reg/v/f:DI 37 r8 [orig:92 xD.1858 ] [92]) (plus:DI (reg:DI 37 r8 [96]) (reg:DI 0 ax [orig:95 D.1884 ] [95]))) (clobber (reg:CC 17 flags)) ]) (expr_list:REG_EQUAL (plus:DI (reg:DI 0 ax [orig:95 D.1884 ] [95]) (const_int 962072674304 [0xe000000000])) (nil))) (insn 14 13 15 2 (set (reg:DI 5 di) (reg/v/f:DI 37 r8 [orig:92 xD.1858 ] [92])) (nil)) ... into this insn: ... (insn 14 12 15 2 (set (reg:DI 5 di) (plus:DI (reg:DI 37 r8 [96]) (reg:DI 0 ax [orig:95 D.1884 ] [95]))) (nil)) ... That removes the set of r8 by insn 13. And that set of r8 is used by insn 16: .... (call_insn 15 ...) (insn 16 15 17 2 (set (reg:DI 5 di) (reg/v/f:DI 37 r8 [orig:92 x ] [92])) test.c:33 85 {*movdi_internal} (nil)) ... But reload_combine doesn't acknowledge that use, because it considers that r8 is killed by call_insn 15. The patch fixes the problem by using get_call_reg_set_usage to find out that r8 is actually not killed by the call_insn. Bootstrapped and reg-tested on x86_64 on top of trunk. OK for trunk and gcc-5-branch? 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 | 58 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 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..93a7644 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr66444.c @@ -0,0 +1,58 @@ +/* { dg-do run } */ +/* { dg-options "-O2 -fipa-ra" } */ + +extern void abort (void); + +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 *) 0xe0000000U; + + x += bar (); + + fn1 (x); + fn2 (x); + + return 0; +} + +int +main (void) +{ + baz (); + + if (s2 != (((struct S *) 0xe0000000U) + 1)) + abort (); + + return 0; +} -- 1.9.1