From patchwork Sat Feb 11 00:29:55 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Modra X-Patchwork-Id: 726795 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 3vKt505Zhnz9s7p for ; Sat, 11 Feb 2017 11:30:26 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="M4x3dzkx"; 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:references:mime-version :content-type:in-reply-to; q=dns; s=default; b=o0TpYkbuB8Ln6V/DC kAiycZ5Zacz0EsVk6TGnt9xmfEXGfE3fZhYwfOyV9wU2NmKLLTewMT8SIrT1yM7f SssyRYzICz6dfxH73KG0aDnuyyI3Fo/73ND3j+Df2oJfuWAjSpkz+8SRBXDx56nY sI6veK8CorvsQQ2VaVtzFtr9zU= 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:references:mime-version :content-type:in-reply-to; s=default; bh=SDTY03OKPiQhGVNYCkhaFif Oe18=; b=M4x3dzkx/ZsMrw5JOrTnEwSqSjKNAvym59cwkWGp93oZKllsnQE0ySR Rn1URBM/czqRG+IY66HyiMJrUivdDWHEZ2+7guUo9+JARrTADS9BQFJ/4zaJK7+H /FPDS2Q6MrsgesmJAUK+vkFRwKSGcyxip500Kj0LVf69ceO9eKMc= Received: (qmail 49713 invoked by alias); 11 Feb 2017 00:30:18 -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 49444 invoked by uid 89); 11 Feb 2017 00:30:04 -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=dominance, non-local, nonlocal, 33AM X-HELO: mail-pf0-f175.google.com Received: from mail-pf0-f175.google.com (HELO mail-pf0-f175.google.com) (209.85.192.175) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 11 Feb 2017 00:30:03 +0000 Received: by mail-pf0-f175.google.com with SMTP id 202so9762845pfx.2 for ; Fri, 10 Feb 2017 16:30:02 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=KA/fslR1EZ2Lr4ccN4uOvoTHMsHkpoQWP1X+rbjQGEM=; b=s6rpqeBRxRydTVqA+u5cJhB+H58X8szUUO2XCqD2wkFzezcnLw4u+HqXupfYTGw6sP vVJMyTqdNQdYYxxuWF3dOkmnBvCp7kaqJC0HJTQbfDwSPVT6LF6PWapQ3GFdqLNDz40X Ezibm5+GGCS9PE471v1J7NPMwJn5PaqwvbYL6Euesk7opfqtiwM13yg10UfnNibcVJiJ ao7xkkkFA93HvI3UuqtLiCWs/hv8ONr2WOq47balVgepdOabHg/rgey6tluNJORYUaF+ nIuQRzmEzkY0+30wUV6q53lIp9691FUmVoSsueBuQ3MefXbz1Uc3i22TZjIZrFp2hy9W 9AUA== X-Gm-Message-State: AMke39nfJhOYV35C0TsZP3AtKNfnB9srRTMKcOyFFZLZqeeqx34/Ijwk94RM8FcxelA5Fw== X-Received: by 10.84.177.129 with SMTP id x1mr14731570plb.75.1486773000999; Fri, 10 Feb 2017 16:30:00 -0800 (PST) Received: from bubble.grove.modra.org (CPE-58-160-71-80.tyqh2.lon.bigpond.net.au. [58.160.71.80]) by smtp.gmail.com with ESMTPSA id e13sm7652067pgn.38.2017.02.10.16.29.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 10 Feb 2017 16:30:00 -0800 (PST) Received: by bubble.grove.modra.org (Postfix, from userid 1000) id E3E80C3418; Sat, 11 Feb 2017 10:59:55 +1030 (ACDT) Date: Sat, 11 Feb 2017 10:59:55 +1030 From: Alan Modra To: Jeff Law Cc: gcc-patches@gcc.gnu.org Subject: Re: PR79286, ira combine_and_move_insns in loops Message-ID: <20170211002955.GR3731@bubble.grove.modra.org> References: <20170201134830.GA3731@bubble.grove.modra.org> <20170201213722.GB3731@bubble.grove.modra.org> <20170202093138.GF3731@bubble.grove.modra.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) X-IsSubscribed: yes On Fri, Feb 03, 2017 at 01:55:33AM -0700, Jeff Law wrote: > That seems pretty pessimistic -- do we have dominance information at this > point? If so we could check that the assignment to the register dominates > the use. If they are in the same block, then you have to look at LUIDs or > somesuch. > > That would address the problem you're trying to solve without pessimizing > the code. Fair enough. Revised and regression tested x86_64-linux. PR rtl-optimization/79286 * ira.c (def_dominates_uses): New function. (update_equiv_regs): Don't create an equivalence for insns that may trap where the register def does not dominate the use. testsuite/ * gcc.c-torture/execute/pr79286.c: New. diff --git a/gcc/ira.c b/gcc/ira.c index 96b4b62..6fb8aaf 100644 --- a/gcc/ira.c +++ b/gcc/ira.c @@ -3300,6 +3300,49 @@ adjust_cleared_regs (rtx loc, const_rtx old_rtx ATTRIBUTE_UNUSED, void *data) return NULL_RTX; } +/* Given register REGNO is set only once, return true if the defining + insn dominates all uses. */ + +static bool +def_dominates_uses (int regno) +{ + df_ref def = DF_REG_DEF_CHAIN (regno); + + struct df_insn_info *def_info = DF_REF_INSN_INFO (def); + /* If this is an artificial def (eh handler regs, hard frame pointer + for non-local goto, regs defined on function entry) then def_info + is NULL and the reg is always live before any use. We might + reasonably return true in that case, but since the only call + of this function is currently here in ira.c when we are looking + at a defining insn we can't have an artificial def as that would + bump DF_REG_DEF_COUNT. */ + gcc_assert (DF_REG_DEF_COUNT (regno) == 1 && def_info != NULL); + + rtx_insn *def_insn = DF_REF_INSN (def); + basic_block def_bb = BLOCK_FOR_INSN (def_insn); + + for (df_ref use = DF_REG_USE_CHAIN (regno); + use; + use = DF_REF_NEXT_REG (use)) + { + struct df_insn_info *use_info = DF_REF_INSN_INFO (use); + /* Only check real uses, not artificial ones. */ + if (use_info) + { + rtx_insn *use_insn = DF_REF_INSN (use); + if (!DEBUG_INSN_P (use_insn)) + { + basic_block use_bb = BLOCK_FOR_INSN (use_insn); + if (use_bb != def_bb + ? !dominated_by_p (CDI_DOMINATORS, use_bb, def_bb) + : DF_INSN_INFO_LUID (use_info) < DF_INSN_INFO_LUID (def_info)) + return false; + } + } + } + return true; +} + /* Find registers that are equivalent to a single value throughout the compilation (either because they can be referenced in memory or are set once from a single constant). Lower their priority for a @@ -3498,9 +3541,18 @@ update_equiv_regs (void) = gen_rtx_INSN_LIST (VOIDmode, insn, reg_equiv[regno].init_insns); /* If this register is known to be equal to a constant, record that - it is always equivalent to the constant. */ + it is always equivalent to the constant. + Note that it is possible to have a register use before + the def in loops (see gcc.c-torture/execute/pr79286.c) + where the reg is undefined on first use. If the def insn + won't trap we can use it as an equivalence, effectively + choosing the "undefined" value for the reg to be the + same as the value set by the def. */ if (DF_REG_DEF_COUNT (regno) == 1 - && note && ! rtx_varies_p (XEXP (note, 0), 0)) + && note + && !rtx_varies_p (XEXP (note, 0), 0) + && (!may_trap_p (XEXP (note, 0)) + || def_dominates_uses (regno))) { rtx note_value = XEXP (note, 0); remove_note (insn, note); diff --git a/gcc/testsuite/gcc.c-torture/execute/pr79286.c b/gcc/testsuite/gcc.c-torture/execute/pr79286.c new file mode 100644 index 0000000..e6d0e93 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/pr79286.c @@ -0,0 +1,15 @@ +int a = 0, c = 0; +static int d[][8] = {}; + +int main () +{ + int e; + for (int b = 0; b < 4; b++) + { + __builtin_printf ("%d\n", b, e); + while (a && c++) + e = d[300000000000000000][0]; + } + + return 0; +}