From patchwork Tue Dec 20 16:01:19 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kyrill Tkachov X-Patchwork-Id: 88608 Delivered-To: patch@linaro.org Received: by 10.140.20.101 with SMTP id 92csp1795937qgi; Tue, 20 Dec 2016 08:01:46 -0800 (PST) X-Received: by 10.99.150.10 with SMTP id c10mr37447027pge.121.1482249706669; Tue, 20 Dec 2016 08:01:46 -0800 (PST) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id y14si22734860pfg.18.2016.12.20.08.01.46 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 20 Dec 2016 08:01:46 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-return-444855-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org; spf=pass (google.com: domain of gcc-patches-return-444855-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-444855-patch=linaro.org@gcc.gnu.org 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=lf5KqZHlVPOn25czzrH9o1cWY6Og/fXxtAEr5Ee2VVLs+W rpQITmRmmw1iamk/nS71prZSATo/5TFVf1TK+FHtmy+EZTsYnCgBz+b4Qg31rftL z5sT9uTKpcgIS+v/uDC5dg6mwGrYFM6AhI/aiSTpZAMKPZLhGPQo9S1bzB9lc= 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=5RSilY95vXekacY7vtBgtQKbxFw=; b=cqYt4CK0WyENV96kT8x9 RktRQLEO6wfHKiyLqWoZOfmzS9KYZ8nqqNagMJ7CH6zSfaNMfmnz1yeh8PEoS4ev /19OMDvDqxjYTuYWtZdtLRKu9enRsILr7LghncEkvCn3TUJg17LTluMr65OQZUOt Ys8y9NV70541xoopejvtA10= Received: (qmail 87314 invoked by alias); 20 Dec 2016 16:01:34 -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 87294 invoked by uid 89); 20 Dec 2016 16:01:33 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-4.0 required=5.0 tests=BAYES_00, KAM_LAZY_DOMAIN_SECURITY, RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=assemble X-HELO: foss.arm.com Received: from foss.arm.com (HELO foss.arm.com) (217.140.101.70) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 20 Dec 2016 16:01:23 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 21C06AD7; Tue, 20 Dec 2016 08:01:21 -0800 (PST) Received: from [10.2.207.77] (e100706-lin.cambridge.arm.com [10.2.207.77]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id C8E633F24D for ; Tue, 20 Dec 2016 08:01:20 -0800 (PST) Message-ID: <585955CF.3010501@foss.arm.com> Date: Tue, 20 Dec 2016 16:01:19 +0000 From: Kyrill Tkachov User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.2.0 MIME-Version: 1.0 To: GCC Patches Subject: [PATCH][tree-ssa-address] Use simplify_gen_binary in gen_addr_rtx Hi all, The testcase in this patch generates bogus assembly for arm with -O1 -mfloat-abi=soft: strd r4, [#0, r3] This is due to non-canonical RTL being generated during expansion: (set (mem:DI (plus:SI (const_int 0 [0]) (reg/f:SI 153)) [0 MEM[symbol: a, index: _26, offset: 0B]+0 S8 A64]) (reg:DI 154)) Note the (plus (const_int 0) (reg)). This is being generated in gen_addr_rtx in tree-ssa-address.c where it creates an explicit PLUS rtx through gen_rtx_PLUS, which doesn't try to canonicalise its arguments or simplify. The correct thing to do is to use simplify_gen_binary that will handle all this properly. I didn't change the other gen_rtx_PLUS calls in this function as their results is later used in XEXP operations that seem to rely on a PLUS expression being explicitly produced, but this particular call doesn't, so it's okay to change it. With this patch the sane assembly is generated: strd r4, [r3] Bootstrapped and tested on arm-none-linux-gnueabihf, x86_64, aarch64-none-linux-gnu. Ok for trunk? Thanks, Kyrill 2016-12-20 Kyrylo Tkachov * tree-ssa-address.c (gen_addr_rtx): Use simplify_gen_binary to add *addr to act_elem. 2016-12-20 Kyrylo Tkachov * gcc.dg/20161219.c: New test. diff --git a/gcc/testsuite/gcc.dg/20161219.c b/gcc/testsuite/gcc.dg/20161219.c new file mode 100644 index 0000000000000000000000000000000000000000..93ea8d2364d9ab54704a84e6c0bff0427df82db8 --- /dev/null +++ b/gcc/testsuite/gcc.dg/20161219.c @@ -0,0 +1,30 @@ +/* { dg-do assemble } */ +/* { dg-options "-O1 -w" } */ + +static long long a[9]; +int b, c, d, e, g; + +static int +fn1 (int *p1) +{ + b = 1; + for (; b >= 0; b--) + { + d = 0; + for (;; d++) + { + e && (a[d] = 0); + if (*p1) + break; + c = (int) a; + } + } + return 0; +} + +int +main () +{ + int f = fn1 ((int *) f); + return f; +} diff --git a/gcc/tree-ssa-address.c b/gcc/tree-ssa-address.c index a53ade0600d01c9d48f6c789b78fd42d7a06a95b..0c7c5902cebb0196c8e27f4eba45ce176cc3f0a5 100644 --- a/gcc/tree-ssa-address.c +++ b/gcc/tree-ssa-address.c @@ -154,7 +154,7 @@ gen_addr_rtx (machine_mode address_mode, } if (*addr) - *addr = gen_rtx_PLUS (address_mode, *addr, act_elem); + *addr = simplify_gen_binary (PLUS, address_mode, *addr, act_elem); else *addr = act_elem; }