From patchwork Tue Sep 15 01:19:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Modra X-Patchwork-Id: 1364026 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=none (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=sDCCl1P1; 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 4Br55s1MK0z9sTC for ; Tue, 15 Sep 2020 11:21:05 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 03783395CC5A; Tue, 15 Sep 2020 01:20:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 03783395CC5A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1600132849; bh=4Vs+8jOLCG+m0vsKrhwqdIxMT7ZeuR6CnnGmjyWgLzU=; 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=sDCCl1P164M56141B/Wjsc4UVDOzoBVc3CCA8hw3cAeD3Dz6wnWYDJegWkW/Or/J7 53ae3ERYDfVQ8cYWOkFueQF7U02k5JkWoT9aiIBvOvw5gQ6wiL1RBtkk++lmi2q+fh DMtoHsdMSyJAN2BY7YbTQxSlnptTzZBG9uuj3JTE= X-Original-To: gcc-patches@sourceware.org Delivered-To: gcc-patches@sourceware.org Received: from mail-pf1-x42b.google.com (mail-pf1-x42b.google.com [IPv6:2607:f8b0:4864:20::42b]) by sourceware.org (Postfix) with ESMTPS id 7A6613857003 for ; Tue, 15 Sep 2020 01:20:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 7A6613857003 Received: by mail-pf1-x42b.google.com with SMTP id f18so952814pfa.10 for ; Mon, 14 Sep 2020 18:20:46 -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=4Vs+8jOLCG+m0vsKrhwqdIxMT7ZeuR6CnnGmjyWgLzU=; b=Qaym5UtJ7uqj76dHQ7d0NtxXnK8jRlNW6CQ/PZZO34YknS6p8ovxsE4BsxtD7DxKLm 5DlPgdGzkb+0fDWkr2s3U4xe4X3bmzJHVbzvlnF6asJG0/vXdOuc9YzYp6MOfMQ6fq3O RY+OvvyC3O9WQYOXcXBUjnzBXV7LEdpW61idkZCTB3rwCBio9JEkVN72I3IHPTtMpB6/ SX54rI8fodnq9xZpFQo39xISmI9+14vPqj20O9RAiAXLkjkUCDLKGSZYNctOzWxEvDlU xWoRoFG5OxhnEfLIZV9Vs4dM3gVx16MvU2Xf+9KCGjmQ8B5175qIWq84csF3UkJrYcMO iEYw== X-Gm-Message-State: AOAM533OqPzMgquX7Ct06DR97WjGIclEm+JlcJjUJHZun2w5WiAdie/g 3KOjKm+Kbaqg5STz1wlKVieW9ZHFkI0= X-Google-Smtp-Source: ABdhPJyS08MVpKMmd8D8ZA71JUBXoY3I7TPZ9SUJOz8I5H1Yc5YZElfPKbdTgactdQkD7HCxa0ePSQ== X-Received: by 2002:a62:7c82:0:b029:13c:1611:6532 with SMTP id x124-20020a627c820000b029013c16116532mr15667446pfc.4.1600132845649; Mon, 14 Sep 2020 18:20:45 -0700 (PDT) Received: from bubble.grove.modra.org ([2406:3400:51d:8cc0:2474:1d78:84bf:1670]) by smtp.gmail.com with ESMTPSA id e207sm12210851pfh.171.2020.09.14.18.20.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Sep 2020 18:20:45 -0700 (PDT) To: Segher Boessenkool Subject: [RS6000] rs6000_rtx_costs reduce cost for SETs Date: Tue, 15 Sep 2020 10:49:45 +0930 Message-Id: <20200915011946.3395-8-amodra@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200915011946.3395-1-amodra@gmail.com> References: <20200915011946.3395-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: gcc-patches@sourceware.org Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" Also use rs6000_cost only for speed. * config/rs6000/rs6000.c (rs6000_rtx_costs): Reduce cost for SETs when insn operation cost handled on recursive call. Only use rs6000_cost for speed. Tidy break/return. Tidy AND costing. diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c index fb5fe7969a3..86c90c4d756 100644 --- a/gcc/config/rs6000/rs6000.c +++ b/gcc/config/rs6000/rs6000.c @@ -21277,15 +21277,19 @@ rs6000_rtx_costs (rtx x, machine_mode mode, int outer_code, case PLUS: case MINUS: - if (FLOAT_MODE_P (mode)) + if (speed && FLOAT_MODE_P (mode)) *total = rs6000_cost->fp; else *total = COSTS_N_INSNS (1); return false; case MULT: - if (CONST_INT_P (XEXP (x, 1)) - && satisfies_constraint_I (XEXP (x, 1))) + if (!speed) + /* A little more than one insn so that nothing is tempted to + turn a shift left into a multiply. */ + *total = COSTS_N_INSNS (1) + 1; + else if (CONST_INT_P (XEXP (x, 1)) + && satisfies_constraint_I (XEXP (x, 1))) { if (INTVAL (XEXP (x, 1)) >= -256 && INTVAL (XEXP (x, 1)) <= 255) @@ -21304,18 +21308,22 @@ rs6000_rtx_costs (rtx x, machine_mode mode, int outer_code, return false; case FMA: - if (mode == SFmode) + if (!speed) + *total = COSTS_N_INSNS (1) + 1; + else if (mode == SFmode) *total = rs6000_cost->fp; else *total = rs6000_cost->dmul; - break; + return false; case DIV: case MOD: if (FLOAT_MODE_P (mode)) { - *total = mode == DFmode ? rs6000_cost->ddiv - : rs6000_cost->sdiv; + if (!speed) + *total = COSTS_N_INSNS (1) + 2; + else + *total = mode == DFmode ? rs6000_cost->ddiv : rs6000_cost->sdiv; return false; } /* FALLTHRU */ @@ -21334,7 +21342,9 @@ rs6000_rtx_costs (rtx x, machine_mode mode, int outer_code, } else { - if (GET_MODE (XEXP (x, 1)) == DImode) + if (!speed) + *total = COSTS_N_INSNS (1) + 2; + else if (GET_MODE (XEXP (x, 1)) == DImode) *total = rs6000_cost->divdi; else *total = rs6000_cost->divsi; @@ -21368,6 +21378,7 @@ rs6000_rtx_costs (rtx x, machine_mode mode, int outer_code, return false; case AND: + *total = COSTS_N_INSNS (1); right = XEXP (x, 1); if (CONST_INT_P (right)) { @@ -21380,15 +21391,15 @@ rs6000_rtx_costs (rtx x, machine_mode mode, int outer_code, || left_code == LSHIFTRT) && rs6000_is_valid_shift_mask (right, left, mode)) { - *total = rtx_cost (XEXP (left, 0), mode, left_code, 0, speed); - if (!CONST_INT_P (XEXP (left, 1))) - *total += rtx_cost (XEXP (left, 1), SImode, left_code, 1, speed); - *total += COSTS_N_INSNS (1); + rtx reg_op = XEXP (left, 0); + if (!REG_P (reg_op)) + *total += rtx_cost (reg_op, mode, left_code, 0, speed); + reg_op = XEXP (left, 1); + if (!REG_P (reg_op) && !CONST_INT_P (reg_op)) + *total += rtx_cost (reg_op, mode, left_code, 1, speed); return true; } } - - *total = COSTS_N_INSNS (1); return false; case IOR: @@ -21519,7 +21530,9 @@ rs6000_rtx_costs (rtx x, machine_mode mode, int outer_code, if (outer_code == TRUNCATE && GET_CODE (XEXP (x, 0)) == MULT) { - if (mode == DImode) + if (!speed) + *total = COSTS_N_INSNS (1) + 1; + else if (mode == DImode) *total = rs6000_cost->muldi; else *total = rs6000_cost->mulsi; @@ -21554,11 +21567,16 @@ rs6000_rtx_costs (rtx x, machine_mode mode, int outer_code, case FIX: case UNSIGNED_FIX: case FLOAT_TRUNCATE: - *total = rs6000_cost->fp; + if (!speed) + *total = COSTS_N_INSNS (1); + else + *total = rs6000_cost->fp; return false; case FLOAT_EXTEND: - if (mode == DFmode) + if (!speed) + *total = COSTS_N_INSNS (1); + else if (mode == DFmode) *total = rs6000_cost->sfdf_convert; else *total = rs6000_cost->fp; @@ -21576,7 +21594,7 @@ rs6000_rtx_costs (rtx x, machine_mode mode, int outer_code, *total = rs6000_cost->fp; return false; } - break; + return false; case NE: case EQ: @@ -21614,13 +21632,32 @@ rs6000_rtx_costs (rtx x, machine_mode mode, int outer_code, *total = 0; return true; } - break; + return false; + + case SET: + /* The default cost of a SET is the number of general purpose + regs being set multiplied by COSTS_N_INSNS (1). That only + works where the incremental cost of the operation and + operands is zero, when the operation performed can be done in + one instruction. For other cases where we add COSTS_N_INSNS + for some operation (see point 5 above), COSTS_N_INSNS (1) + should be subtracted from the total cost. */ + { + rtx_code src_code = GET_CODE (SET_SRC (x)); + if (src_code == CONST_INT + || src_code == CONST_DOUBLE + || src_code == CONST_WIDE_INT) + return false; + int set_cost = (rtx_cost (SET_SRC (x), mode, SET, 1, speed) + + rtx_cost (SET_DEST (x), mode, SET, 0, speed)); + if (set_cost >= COSTS_N_INSNS (1)) + *total += set_cost - COSTS_N_INSNS (1); + return true; + } default: - break; + return false; } - - return false; } /* Debug form of r6000_rtx_costs that is selected if -mdebug=cost. */