From patchwork Fri Apr 19 20:00:04 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Makarov X-Patchwork-Id: 238099 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 8E3092C021C for ; Sat, 20 Apr 2013 06:24:09 +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:mime-version:to:subject:content-type; q= dns; s=default; b=UUqntR1t5T+JmLAFWEjwehTHNXVV0y2PHSHlBNpSRFk7bh uhZr8Gxv3oE9X/kZs2BVfEhhNqMWk/OOKa4JrjwRA3wpo1hEkTRKmbq++l6vV2Fk JX+ddehVUUqaxP0kkLRo8dODpYlQVlhcCLAAseysn7/c0D1R8vCb0w+qrmBWk= 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:subject:content-type; s= default; bh=grk13W+EKQYBxVxlvTCsm8nop44=; b=pdab51s0Wpl9z8va7BPq Az4lIRF36dBUDhR7iCcJIV+ZpT8mDjVp9UhWCPIaV/ZsJzVS1TBPv4n8d0I4XZEy WlyfczB0nAG/mVd42lnWpcwfYUY0d0pNKLHkLWk/2CDWuM9gObdT0o2FYF2KYtiO HfIOoBuNg7w75MnwpWU4i1s= Received: (qmail 11069 invoked by alias); 19 Apr 2013 20:24:03 -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 11059 invoked by uid 89); 19 Apr 2013 20:24:02 -0000 X-Spam-SWARE-Status: No, score=-6.9 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, RCVD_IN_DNSWL_HI, RCVD_IN_HOSTKARMA_W, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.1 Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Fri, 19 Apr 2013 20:24:01 +0000 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r3JKO0eK011386 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 19 Apr 2013 16:24:00 -0400 Received: from Mair.local (vpn-48-120.rdu2.redhat.com [10.10.48.120]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r3JK05ET024636 for ; Fri, 19 Apr 2013 16:00:05 -0400 Message-ID: <5171A244.8040607@redhat.com> Date: Fri, 19 Apr 2013 16:00:04 -0400 From: Vladimir Makarov User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:17.0) Gecko/20130328 Thunderbird/17.0.5 MIME-Version: 1.0 To: GCC Patches Subject: patch to fix PR 56847 X-Virus-Found: No The following patch fixes http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56847 Reload pass is lucky choosing alternative without offsettable memory in movti_internal pattern as this alternative for some reason has reject value less by one than alternative with offsettable memory. LRA chooses offsettable memory alternative as it looks cheaper and don't need secondary reload in alternative chosen by reload pass (and reload pass completely ignores this fact). LRA choice results in failure to generate insns for reloading address to make it offsettable. After several tries, I think I found a good solution for the problem. The patch was successfully bootstrapped on x86 and x86-64 (with and without -fpie). I tried 500K lines of test code and did not find any difference in generated code using different options including -fpie. So the patch will not affect huge majority of the code. Committed as rev. 198101. 2013-04-19 Vladimir Makarov PR rtl-optimization/56847 * lra-constraints.c (process_alt_operands): Discourage alternative with non-matche doffsettable memory constraint fro memory with known offset. 2013-04-19 Vladimir Makarov PR rtl-optimization/56847 * gcc.dg/pr56847.c: New test. Index: lra-constraints.c =================================================================== --- lra-constraints.c (revision 198092) +++ lra-constraints.c (working copy) @@ -1978,8 +1978,15 @@ process_alt_operands (int only_alternati (op, this_alternative) == NO_REGS)))) reject += LRA_MAX_REJECT; - if (! ((const_to_mem && constmemok) - || (MEM_P (op) && offmemok))) + if (MEM_P (op) && offmemok) + { + /* If we know offset and this non-offsetable memory, + something wrong with this memory and it is better + to try other memory possibilities. */ + if (MEM_OFFSET_KNOWN_P (op)) + reject += LRA_MAX_REJECT; + } + else if (! (const_to_mem && constmemok)) { /* We prefer to reload pseudos over reloading other things, since such reloads may be able to be Index: testsuite/gcc.dg/pr56847.c =================================================================== --- testsuite/gcc.dg/pr56847.c (revision 0) +++ testsuite/gcc.dg/pr56847.c (working copy) @@ -0,0 +1,12 @@ +/* PR rtl-optimization/56847 */ +/* { dg-do compile { target pie } } */ +/* { dg-options "-O2 -fpie" } */ + +struct S { long int a, b; } e; +__thread struct S s; + +void +foo (void) +{ + s = e; +}