From patchwork Tue Mar 1 09:01:11 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Modra X-Patchwork-Id: 590408 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 0B3DF14033B for ; Tue, 1 Mar 2016 20:01:34 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=HkDM7yIf; 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:date :from:to:cc:subject:message-id:mime-version:content-type; q=dns; s=default; b=yKhyND3TNYkI86SsaP8+QKpi4IV4e6Z8kbNSZhx72vWuwOnBng onDuZHll6e2fNAPkyIb0ZFJ82VUDlP9L9h13OFVIHn/97+qBrSb+dzPJKBTLbXpf O2khyyiXUrYUC6IE2iwhvRy1OD4+5DGZskheo5WqP03pVNB7VMvY+Q8s8= 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:date :from:to:cc:subject:message-id:mime-version:content-type; s= default; bh=nTUUEpO+1xPAzHCsYW4QYtjT7lw=; b=HkDM7yIfO3RulpMopgZ0 LSAwjGRz5lNhn9gIF+o3TaGtnpKK4k+siJ3j3R++WIdqEo/Wyc36BtdPCcK8Uqd4 NL/4RQ2M6Vj11rTNIKO51QH0u+bUbxzqLEtzgNYqnBiNsGATxGjEZH3IxBbMiTi3 7TvfrmtsnGWKhcpvE/4JBpc= Received: (qmail 115123 invoked by alias); 1 Mar 2016 09:01:28 -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 114992 invoked by uid 89); 1 Mar 2016 09:01:24 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.4 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 spammy=H*Ad:U*rguenth, sk:dg-requ, sk:dgrequ, incompatible X-Spam-User: qpsmtpd, 3 recipients X-HELO: mail-pf0-f181.google.com Received: from mail-pf0-f181.google.com (HELO mail-pf0-f181.google.com) (209.85.192.181) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Tue, 01 Mar 2016 09:01:18 +0000 Received: by mail-pf0-f181.google.com with SMTP id w128so64415098pfb.2; Tue, 01 Mar 2016 01:01:18 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=6muHoxzx+7tkF9bipw36BwbdyCMkKN/qBwam5RibGVc=; b=DL7e+yCuXnsC4jmc20w5qGy2sLARSGe/q8+M6NFKIygua/j4fv+4EpVwVgzvq8v5hI XvhDvxad+gn6OtxPDT51OhL3HiNP0E5dBWMwGAbqN0lqhCOTcI1EyAONXxdoVPLF7Jg/ Q4oWuRJIiCW2dTiv9FSxrCi+7G66Z/28m3cKsyk9aNNQxGOm79GqiC2fIXSX1sbs4DjT rauqoRgXqY52PMmSr9gpaHGBo8WBFpe6i8XSofdNaT82rbdgCUglIy3xTWKZx2EIjwSe mKRNYHI+dxLijss/vqFDRG76o7VkEvZ9H26DBxa7M9MCd7oLngzaKBJPO28O2XpBxHdY 3YEw== X-Gm-Message-State: AD7BkJKjxZBmbQLvs5+TzpmjyRIJsqNLlN4mIZCunf3DQsdOV9Qr8y4+CAaLpUO59YELDA== X-Received: by 10.98.76.194 with SMTP id e63mr28386196pfj.9.1456822877126; Tue, 01 Mar 2016 01:01:17 -0800 (PST) Received: from bubble.grove.modra.org (CPE-58-160-146-233.sa.bigpond.net.au. [58.160.146.233]) by smtp.gmail.com with ESMTPSA id s14sm14737048pfa.3.2016.03.01.01.01.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 01 Mar 2016 01:01:16 -0800 (PST) Received: by bubble.grove.modra.org (Postfix, from userid 1000) id D052AEA0157; Tue, 1 Mar 2016 19:31:11 +1030 (ACDT) Date: Tue, 1 Mar 2016 19:31:11 +1030 From: Alan Modra To: gcc-patches@gcc.gnu.org Cc: rguenth@gcc.gnu.org, hubicka@gcc.gnu.org Subject: [PATCH] decl alignment not respected Message-ID: <20160301090111.GQ10657@bubble.grove.modra.org> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) X-IsSubscribed: yes This patch cures a problem with ICF of read-only variables at the intersection of -fsection-anchors, -ftree-loop-vectorize, and targets with alignment restrictions. The testcase results in /usr/local/powerpc64le-linux/bin/ld: pack.o: In function `main': pack.c:(.text.startup+0xc): error: R_PPC64_TOC16_LO_DS not a multiple of 4 /usr/local/powerpc64le-linux/bin/ld: final link failed: Bad value on powerpc64le-linux. What happens is: - "c" is referenced in a constructor, thus make_decl_rtl for "c", - make_decl_rtl puts "c" in an anchor block (-fsection-anchors), - anchor block contents can't move, so "c" alignment can't change by ipa_increase_alignment (-ftree-loop-vectorize), - however "a" alignment can be increased, - ICF aliases "a" to "c". So we have a decl for "a" saying it is aligned to 128 bits, using mem for "c" which is only 16 bit aligned. The supposed increased alignment causes "a" to be accessed as a 64-bit word, and the powerpc64 backend to use a ds-form addressing mode. Somewhere this chain of events needs to be broken. It isn't possible to stop ipa_increase_alignment changing "a", because at that stage ICF aliases don't exist. So it seemed to me that ICF needed to be taught not to create a problematic alias. Not being very familiar with this code, I don't know if the following is the best place to change, but sem_variable::merge does throw away aliases for quite a lot of other reasons. Another possibility is sem_variable::equals_wpa, where there's a comment about DECL_ALIGN being safe to merge "because we will always choose the largest alignment out of all aliases". Except with this testcase we don't choose the largest alignment, and indeed can't (I think) due to "c" being used in a constructor. Bootstrapped and regression tested powerpc64le-linux. OK to apply? gcc/ PR ipa/69990 * ipa-icf.c (sem_variable::merge): Do not merge an alias with larger alignment. gcc/testsuite/ gcc.dg/pr69990.c: New. diff --git a/gcc/ipa-icf.c b/gcc/ipa-icf.c index ef04c55..d82eb87 100644 --- a/gcc/ipa-icf.c +++ b/gcc/ipa-icf.c @@ -2209,6 +2209,16 @@ sem_variable::merge (sem_item *alias_item) "adress of original and alias may be compared.\n\n"); return false; } + + if (DECL_ALIGN (original->decl) < DECL_ALIGN (alias->decl)) + { + if (dump_file) + fprintf (dump_file, "Not unifying; " + "original and alias have incompatible alignments\n\n"); + + return false; + } + if (DECL_COMDAT_GROUP (original->decl) != DECL_COMDAT_GROUP (alias->decl)) { if (dump_file) diff --git a/gcc/testsuite/gcc.dg/pr69990.c b/gcc/testsuite/gcc.dg/pr69990.c new file mode 100644 index 0000000..efb835e --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr69990.c @@ -0,0 +1,24 @@ +/* { dg-do run } */ +/* { dg-require-effective-target section_anchors } */ +/* { dg-options "-O2 -fsection-anchors -ftree-loop-vectorize" } */ + +#pragma pack(1) +struct S0 { + volatile int f0:12; +} static a[] = {{15}}, c[] = {{15}}; + +struct S0 b[] = {{7}}; + +int __attribute__ ((noinline, noclone)) +ok (int a, int b, int c) +{ + return a == 15 && b == 7 && c == 15 ? 0 : 1; +} + +int +main (void) +{ + struct S0 *f[] = { c, b }; + + return ok (a[0].f0, b[0].f0, f[0]->f0); +}