From patchwork Wed Oct 7 22:57:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Modra X-Patchwork-Id: 1378328 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=TeJ2tO//; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4C68sL1xdSz9sPB for ; Thu, 8 Oct 2020 09:59:02 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1E1C6386F83E; Wed, 7 Oct 2020 22:58:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1E1C6386F83E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1602111531; bh=RBuXOtdzSTndDwbkYLHHWBCKQMZOUzkw+ROxoJIt4PU=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=TeJ2tO//o9/70vYjbgdjXTiuO1/wT+q+Mqc+JBe1/LcA0b0oO6hM1um+HMyJiPjZg hVHK80Jrxv3OAUeC4Ka6ycMr7GgdHEc+1SLtn0Q/WMHKoSBTzTemQlUKN8ZZFf8YWv JQ72oZsDYXN5YPRwA9WOCvxWN9XwPRU75KthGzzE= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pg1-x52f.google.com (mail-pg1-x52f.google.com [IPv6:2607:f8b0:4864:20::52f]) by sourceware.org (Postfix) with ESMTPS id 162DF386F45B for ; Wed, 7 Oct 2020 22:58:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 162DF386F45B Received: by mail-pg1-x52f.google.com with SMTP id x16so2591867pgj.3 for ; Wed, 07 Oct 2020 15:58:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=RBuXOtdzSTndDwbkYLHHWBCKQMZOUzkw+ROxoJIt4PU=; b=HPfH5MBW0C4iextZvm4bLcb6a/8mMFHo1DKfCv0sQsdr17/xzuRd+af0IRTZ1BRsfd M2nmADnGM6b/bxoqnrBbiovhCFZseJsR15yLRjbEX+eXkXY62q3Qalq1AhS0hqAvzOzV 8JHkZuDlceZPuGm5rujGV+ETDitjXvu0SsIEEPqPUWlcgd4jeDXCX3Hk1wM0yRQ53rRd jCYygiEij/nUmkre6OKhtRGWfgddlTlh7cvBTqH3vEgXNs8PQo5RA0vBLpEemRS6Hga4 dGl8+LLiWcj6KM8RLYchzW4kcoCl5zMnsp2axamSU/bU4v/2UuIPrW+bzbCYF0K+gyCB h1Wg== X-Gm-Message-State: AOAM532a1uZqmawqjewmF0PG79G0xQ8UxPYgFU/TuDko2CUGY1kLvwl+ UM/jydb/GrcXN7WLQYeCDGymvPlOpvh1Bg== X-Google-Smtp-Source: ABdhPJy9/Im+mZqbHOdWB0nRtraKndgxquA3QlCFbPosVXDvHARjBBqz9ThgF/R3bTstjlnDHceMrw== X-Received: by 2002:a63:2120:: with SMTP id h32mr4894538pgh.276.1602111527835; Wed, 07 Oct 2020 15:58:47 -0700 (PDT) Received: from bubble.grove.modra.org ([2406:3400:51d:8cc0:e872:ea73:2f18:2dba]) by smtp.gmail.com with ESMTPSA id u15sm4451348pfm.61.2020.10.07.15.58.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Oct 2020 15:58:47 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [PATCH 6/8] [RS6000] rs6000_rtx_costs multi-insn constants Date: Thu, 8 Oct 2020 09:27:58 +1030 Message-Id: <20201007225800.9536-7-amodra@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201007225800.9536-1-amodra@gmail.com> References: <20201007225800.9536-1-amodra@gmail.com> X-Spam-Status: No, score=-10.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Alan Modra via Gcc-patches From: Alan Modra Reply-To: Alan Modra Cc: segher@kernel.crashing.org Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" This small patch to rs6000_rtx_costs 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 up to five dependent instructions. Note that the rs6000 backend does generate large constants as loads from memory at expand time but optimisation passes replace them with SETs of the value due to not having correct costs. PR 94393 * config/rs6000/rs6000.c (rs6000_rtx_costs): Cost multi-insn constants. diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c index 15a806fe307..76aedbfae6f 100644 --- a/gcc/config/rs6000/rs6000.c +++ b/gcc/config/rs6000/rs6000.c @@ -21343,7 +21343,9 @@ rs6000_rtx_costs (rtx x, machine_mode mode, int outer_code, switch (code) { - /* On the RS/6000, if it is valid in the insn, it is free. */ + /* (reg) is costed at zero by rtlanal.c:rtx_cost. That sets a + baseline for rtx costs: If a constant is valid in an insn, + it is free. */ case CONST_INT: if (((outer_code == SET || outer_code == PLUS @@ -21404,6 +21406,17 @@ 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. 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. All special cases + for codes other than SET must be handled before we get + here. */ + *total = COSTS_N_INSNS (num_insns_constant (x, mode) + - (outer_code == SET ? 1 : 0)); + return true; + case CONST: case HIGH: case SYMBOL_REF: