From patchwork Wed Jun 24 00:54:50 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Modra X-Patchwork-Id: 487895 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 20DD814031C for ; Wed, 24 Jun 2015 10:55:06 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=O32/sWgn; 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=Vo/WqNCU6esHbTYMW N231r0ZuQlHx2ALJkg9tOoNKtAd7F8y5bHJ6lODzAWpFUNX37R//UkRpjmpGZZ44 yeugV2aav/uvbTVG1N9af2ob5r1CbNzYv8uh2bpG4swYxJGbhwVaM476xKAUkpSk 9dNDYzSXOoVxMBF3JnC8pinu1I= 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=nrChb4DFhCyKIYoiUxI6zPQ aHSA=; b=O32/sWgnCzNwuzCcWbrjx5Vek1KJTFF6MoKLwYGQTS8kXomaDMvhY8R XtvdAiKiOC8sAFFlwCNXTefstUVrwsKWDIIOZIxAvJyzxJJ6AXlz3hslu3iQdALE jekkFqCX88oYj5P3JjuPwrGqDIh5ZJzJeme+UcOM7dU8KDiTpKQ4= Received: (qmail 89511 invoked by alias); 24 Jun 2015 00:54:58 -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 89500 invoked by uid 89); 24 Jun 2015 00:54:57 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-pd0-f180.google.com Received: from mail-pd0-f180.google.com (HELO mail-pd0-f180.google.com) (209.85.192.180) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Wed, 24 Jun 2015 00:54:56 +0000 Received: by pdbki1 with SMTP id ki1so18194212pdb.1 for ; Tue, 23 Jun 2015 17:54:55 -0700 (PDT) X-Received: by 10.68.219.42 with SMTP id pl10mr75224189pbc.154.1435107295055; Tue, 23 Jun 2015 17:54:55 -0700 (PDT) Received: from bubble.grove.modra.org (CPE-58-160-155-134.oycza5.sa.bigpond.net.au. [58.160.155.134]) by mx.google.com with ESMTPSA id y1sm24634817pdy.2.2015.06.23.17.54.53 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 23 Jun 2015 17:54:54 -0700 (PDT) Received: by bubble.grove.modra.org (Postfix, from userid 1000) id 56DBFEA0074; Wed, 24 Jun 2015 10:24:50 +0930 (ACST) Date: Wed, 24 Jun 2015 10:24:50 +0930 From: Alan Modra To: gcc-patches@gcc.gnu.org Cc: David Edelsohn Subject: [RS6000 6/7] Cost multi-insn constants Message-ID: <20150624005450.GA1723@bubble.grove.modra.org> Mail-Followup-To: gcc-patches@gcc.gnu.org, David Edelsohn References: <20150624004649.GU1723@bubble.grove.modra.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20150624004649.GU1723@bubble.grove.modra.org> User-Agent: Mutt/1.5.23 (2014-03-12) X-IsSubscribed: yes This small patch considerably improves code generated for large constants in 64-bit code, teaching gcc that it is better to load a constant from memory than to generate a sequence of five dependent instructions. Note that we already do this at expand time for plain moves. This change affects constants inside other RTL operations, ie. those generated by various optimizations. I would like to fix rtlanal.c:rtx_cost to not cost register moves at zero, but that probably disrupts many targets. See the comment. * config/rs6000/rs6000.c (rs6000_rtx_costs): Cost multi-insn CONST_INTs. diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c index 941ad02..0218d0f 100644 --- a/gcc/config/rs6000/rs6000.c +++ b/gcc/config/rs6000/rs6000.c @@ -30700,6 +30700,26 @@ rs6000_rtx_costs (rtx x, machine_mode mode, int outer_code, case CONST_DOUBLE: case CONST_WIDE_INT: + /* Subtract one insn here for consistency with the above code + that returns one less than the actual number of insns for + SETs. This is because (set (reg1) (reg2)) is costed at zero + by rtlanal.c:rtx_cost. If we cost (set (reg) (const_int 0)) + at greater than the register move cost, then a call like + foo (0, 0) will be implemented as li "r3,0; mr r4,r3; bl foo" + rather than "li r3,0; li r4,0; bl foo". Don't subtract one + for other than SETs, because other operations will require + the constant to be loaded to a register before performing + the operation. + FIXME: A call like foo (x - 1, x - 1) results in + "addi r3,rx,-1; mr r4,r3; bl foo" rather than the better + "addi r3,rx,-1; addi r4,rx,-1; bl foo" because rtx_cost + returns zero for register moves. This cannot be fixed by + reducing the cost of PLUS and other arithmetic/logic codes + to zero. */ + *total = COSTS_N_INSNS (num_insns_constant (x, mode) + - (outer_code == SET ? 1 : 0)); + return true; + case CONST: case HIGH: case SYMBOL_REF: