From patchwork Mon Aug 8 02:43:18 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Modra X-Patchwork-Id: 656519 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 3s71tz0dSyz9sdg for ; Mon, 8 Aug 2016 12:43:37 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=EOg27EzE; 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=EncK8Bph24ymApC51a1cS2NpdyoUAtsa12bdUxVFm4EvHuxL1h aCd2mVlEizO9PtYMhMTWSRFdo+qxKDYPPeUULiIUZAdnvVgHlat4zzDun7ouGoWc eaMQz3KMOuQEE3FLgxUD1sj7fUNsKMvNW9Ro4ANhOiEp6BDSKMMM+RTAM= 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=YzfNYZCFZpr1JVnClyCGB7wI7bY=; b=EOg27EzEw6FoQOVw+39H Qv6SN8KWijdLKFt9wPwYUI47mbYWLRXSC8vIUWIzkqCPYjbANeEpniDWVWxKra7/ hD6l7PULreUBLativnrIbgabVrxQvLnmeOnPG9gau+jVYPmo7HbcxRzGdsJeqaZS NcDiy/z4OimtyUCsT3SeHQE= Received: (qmail 34123 invoked by alias); 8 Aug 2016 02:43: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 34101 invoked by uid 89); 8 Aug 2016 02:43:27 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.5 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 spammy=sk:ATTRIBU, sk:alterna X-HELO: mail-pf0-f193.google.com Received: from mail-pf0-f193.google.com (HELO mail-pf0-f193.google.com) (209.85.192.193) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Mon, 08 Aug 2016 02:43:26 +0000 Received: by mail-pf0-f193.google.com with SMTP id h186so24031657pfg.2 for ; Sun, 07 Aug 2016 19:43:26 -0700 (PDT) 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=N0W/13D28Ikj/ODWJwUwb/jhw0M02JhifT1UY+v3CTk=; b=igqB0zKioaq/pgBz+W2DwI4URkGS+eJhDzD9h0qZg+nCuj4x9SUKnYDFgpRG8KFVAb 5thR3XhZBzxZSOVv3rw3cyt3vXvuPUqTfnG9O9qwXosFS8Mdkm0NaYomQqFExmEmvWnU ihwy/XXrqa+xa2h9XuLq8Tnh7WCWehNN4L+Ci/JUVjGrHH5PNhS/faN8mPSXXKDcgGex jkbrJkR1Bfyw6ahFJm4s7eeFCFdSCMpdtcwZbzoVqoxet+vrKVxck8Ztz4mEmr3m3Ehm /RpBcyw2FFPIyjnizlD0qz9err6eZXaO6B5jD0DXJs3VoTkzH1k1EpEqCpCXpyc/iugW zyAA== X-Gm-Message-State: AEkoouv1QmVb/jZhluCWlwxnoJjU2GDxFAdWfJ3aShYTSP/CCgBaVwlhC1/aQ3MKP1Ha4g== X-Received: by 10.98.77.70 with SMTP id a67mr156507839pfb.151.1470624203909; Sun, 07 Aug 2016 19:43:23 -0700 (PDT) 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 d72sm43333798pfj.15.2016.08.07.19.43.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 07 Aug 2016 19:43:23 -0700 (PDT) Received: by bubble.grove.modra.org (Postfix, from userid 1000) id B1752C17F8; Mon, 8 Aug 2016 12:13:18 +0930 (ACST) Date: Mon, 8 Aug 2016 12:13:18 +0930 From: Alan Modra To: gcc-patches@gcc.gnu.org Cc: Ulrich Weigand , Bernd Schmidt Subject: [PATCH, RELOAD] Don't assume subreg mem address is ok Message-ID: <20160808024318.GX20904@bubble.grove.modra.org> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) X-IsSubscribed: yes This patch fixes a case where reload blindly assumes a subreg mem is OK if its address has been partially reloaded by legitimize_reload_address. The change ought to be fairly obvious considering that the analogous non-subreg case only gives a win to address_reloaded[i] == 1. Bootstrapped and regression tested powerpc64le-linux using RUNTESTFLAGS="--target_board=unix'{-mlra,-mno-lra}'" to run the testsuite using both lra and reload. OK for mainline and active branches? In the testcase we see this insn (insn 316 272 349 38 (parallel [ (set (reg:SF 336 [ _46 ]) (unsigned_float:SF (subreg/s/v:HI (reg:DI 360 [ g ]) 0))) (clobber (scratch:DI)) (clobber (scratch:DI)) (clobber (scratch:HI)) ]) 358 {*floatunshisf2_internal} not getting a hard reg for reg 360, which has an equivalent constant. Reload substitutes the constant, but the pattern does not allow constants so it is forced to mem. The mem address is legitimized by rs6000_legitimize_reload_address to a lo_sum/high constant pool ref. But this particular address form is not valid for the pattern, which wants either an indirect or indexed address. PR rtl-optimization/72771 * reload.c (find_reloads): Don't assume that a subreg mem is OK when find_reloads_toplev returns address_reloaded==-1. (alternative_allows_const_pool_ref): Update comment. testsuite/ * gcc.c-torture/compile/pr72771.c: New. diff --git a/gcc/reload.c b/gcc/reload.c index 1945133..bcd15a1 100644 --- a/gcc/reload.c +++ b/gcc/reload.c @@ -3960,7 +3960,7 @@ find_reloads (rtx_insn *insn, int replace, int ind_levels, int live_known, there will be no reload needed at all. */ if (plus == NULL_RTX && subreg == NULL_RTX - && alternative_allows_const_pool_ref (this_address_reloaded == 0 + && alternative_allows_const_pool_ref (this_address_reloaded != 1 ? substed_operand[i] : NULL, recog_data.constraints[i], @@ -4605,8 +4605,8 @@ find_reloads (rtx_insn *insn, int replace, int ind_levels, int live_known, /* Return true if alternative number ALTNUM in constraint-string CONSTRAINT is guaranteed to accept a reloaded constant-pool reference. - MEM gives the reference if it didn't need any reloads, otherwise it - is null. */ + MEM gives the reference if its address hasn't been fully reloaded, + otherwise it is NULL. */ static bool alternative_allows_const_pool_ref (rtx mem ATTRIBUTE_UNUSED, diff --git a/gcc/testsuite/gcc.c-torture/compile/pr72771.c b/gcc/testsuite/gcc.c-torture/compile/pr72771.c new file mode 100644 index 0000000..1cc13e3 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/compile/pr72771.c @@ -0,0 +1,29 @@ +void fn2(void); +void fn3(unsigned long); + +signed char a; +int b, c, e, f; +float *d; + +void fn1(void) { + unsigned short g = 0; +lbl_986: + for (;;) { + c = 0; + for (; c <= 2;) { + *d = g; + fn2(); + if (e) + goto lbl_986; + } + g = 2; + for (; (short) g >= 0; g--) { + for (; b;) { + fn3(45360); + f = 0; + for (; a >= 0; a--) + ; + } + } + } +}