From patchwork Fri May 31 15:03:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robin Dapp X-Patchwork-Id: 1942188 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=DGGeJ8A8; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VrRGp5HxLz20Wc for ; Sat, 1 Jun 2024 01:04:18 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E2F4C386D60D for ; Fri, 31 May 2024 15:04:16 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-ej1-x634.google.com (mail-ej1-x634.google.com [IPv6:2a00:1450:4864:20::634]) by sourceware.org (Postfix) with ESMTPS id 19C7B384B434 for ; Fri, 31 May 2024 15:03:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 19C7B384B434 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 19C7B384B434 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::634 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1717167839; cv=none; b=w3GTOJjwkCYNVmQ/8dWq5Fx6GvihEXfzC32KM39tFJ3RBlMDYEGY9Rz4Cdszoc3Svawo1VsHwBuuW+IOuZaX6Pa4GP7xqnEC7SijGcT7txjChbUHwCBsy++ztN+5/J4DX9EX1a1tJunvzUTR4Vx6hghgykN33ghlqaRt60zZ0tA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1717167839; c=relaxed/simple; bh=nyzNUJTL7dgWYK/YpvztaR4+w6oVLTfZH1lvsQC/xC0=; h=DKIM-Signature:Message-ID:Date:MIME-Version:To:From:Subject; b=gUgXit60V42M76riTchysUmlCzVNoIEKnIGxlj4FI/1hJA3B6k6t/lLgNaowXAnx0f9A+S+Y5w/LzhkkIdow1phONmmi9+lrjdIFyDun75WyxCo0BB79dIxiYqBIcJm8Js8hE5KUPZrGAQnCFn85ptaukdy5gPfQM94RirARfUk= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-ej1-x634.google.com with SMTP id a640c23a62f3a-a6302bdb54aso266140666b.0 for ; Fri, 31 May 2024 08:03:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717167835; x=1717772635; darn=gcc.gnu.org; h=content-transfer-encoding:subject:from:to:content-language:cc :user-agent:mime-version:date:message-id:from:to:cc:subject:date :message-id:reply-to; bh=ySmhRwwA+ACpQXfnKCzyuGNEoum259RXAUOJViU/GjI=; b=DGGeJ8A8bz7Brt0WofFQ8R7w3N02smrehUYm44VnhzyjdRLiN/L1QDK9ZoNliAUdzp QuB3TUGaJzBs3pQxcwnVEHPMcIyDUqEBhMGPAxOZWbavhghz1MfNAR5CDREpdU9Bf8Sf K9QI7KIuVse4axLFa2qy+xMvEjAdprbaxSwhX0chx6h29sTxEZLS10rvnvsDEwxFPCSj zJtgsEIpake1716epCom3KdQaXTppvC+vBaQsMMarvABeCq+YJ1VD32Gjl91GD+Pg9Rt tHzQlWZpbrM/5QHCM2PNDjf8cyTWcyPl1yItYu4oxWxjZ1/ZcHK0sR4ClfID7ftAKvf2 NHmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717167835; x=1717772635; h=content-transfer-encoding:subject:from:to:content-language:cc :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=ySmhRwwA+ACpQXfnKCzyuGNEoum259RXAUOJViU/GjI=; b=kLqzc14P2QAOR1UDCmgnhReRgU3uO+ZrJs2I3C+7D+M1fjvBCiY8Ua0bVTde71X2nF F2Ng8TayrkK0BCkCMWyW8yFdl5iqusrJSHy5PKzzYwhEp1PRX9acQkZFPoOH3dCeYsnZ ejNxEPzOD6IUToY2awMEScT95SQMuW9KeFhUR9ZEJbPQFM1pTYnmznmkE52eha8+0ct2 69pbony3jI/ngLGQm4asmN444NFZObjQAbEaXwl9YQk97F21SO6sNWZAwbXEqdJZYrGA I8g/7e7MKzqUFgIuXzHeP6K+nphSw5liG6WgOdTirQjLo2j1KbPhgR9aDude6TMaU/BS bvKA== X-Gm-Message-State: AOJu0YxnqmXUoFPe9NXMLcyvmeuoQPeo+xbER8rKr/rPPQJEhuf1bBK/ lw8laoZzvs6453js1bRtP2/2quecXg+YsHXEGE2diQEu3x6vdf/2nEUFMQ== X-Google-Smtp-Source: AGHT+IECoJlCg1CsueFChS9BvhBNvutpgtbqFp7VW8MxCfakVhO6vrbELt67kgA2sAbNWF2OxdEUqA== X-Received: by 2002:a17:907:7b86:b0:a68:6032:463c with SMTP id a640c23a62f3a-a6860326209mr159621066b.18.1717167834920; Fri, 31 May 2024 08:03:54 -0700 (PDT) Received: from [192.168.1.23] (ip-149-172-150-237.um42.pools.vodafone-ip.de. [149.172.150.237]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a67eb3444a6sm94922466b.211.2024.05.31.08.03.54 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 31 May 2024 08:03:54 -0700 (PDT) Message-ID: <57bb6ce5-79c3-4b08-b524-e807b9ac431b@gmail.com> Date: Fri, 31 May 2024 17:03:53 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Cc: rdapp.gcc@gmail.com, jeffreyalaw Content-Language: en-US To: gcc-patches From: Robin Dapp Subject: [PATCH] ifcvt: Clarify if_info.original_cost. X-Spam-Status: No, score=-9.1 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, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Hi, before noce_find_if_block processes a block it sets up an if_info structure that holds the original costs. At that point the costs of the then/else blocks have not been added so we only care about the "if" cost. The code originally used BRANCH_COST for that but was then changed to COST_N_INSNS (2) - a compare and a jump. This patch computes the jump costs via insn_cost (if_info.jump, ...) which is supposed to incorporate the branch costs and, in case of a CC comparison, pattern_cost (if_info.cond, ...) which is supposed to account for the CC creation. For compare_and_jump patterns insn_cost should have already computed the right cost. Does this "split" make sense, generally? Bootstrapped and regtested on x86, aarch64 and power10. Regtested on riscv. Regards Robin gcc/ChangeLog: * ifcvt.cc (noce_process_if_block): Subtract condition pattern cost if applicable. (noce_find_if_block): Use insn_cost and pattern_cost for original cost. --- gcc/ifcvt.cc | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/gcc/ifcvt.cc b/gcc/ifcvt.cc index 58ed42673e5..305b9faed38 100644 --- a/gcc/ifcvt.cc +++ b/gcc/ifcvt.cc @@ -3940,7 +3940,9 @@ noce_process_if_block (struct noce_if_info *if_info) ??? Actually, instead of the branch instruction costs we might want to use COSTS_N_INSNS (BRANCH_COST ()) as in other places. */ - unsigned potential_cost = if_info->original_cost - COSTS_N_INSNS (1); + unsigned potential_cost = if_info->original_cost; + if (cc_in_cond (if_info->cond)) + potential_cost -= pattern_cost (if_info->cond, if_info->speed_p); unsigned old_cost = if_info->original_cost; if (!else_bb && HAVE_conditional_move @@ -4703,11 +4705,13 @@ noce_find_if_block (basic_block test_bb, edge then_edge, edge else_edge, = targetm.max_noce_ifcvt_seq_cost (then_edge); /* We'll add in the cost of THEN_BB and ELSE_BB later, when we check that they are valid to transform. We can't easily get back to the insn - for COND (and it may not exist if we had to canonicalize to get COND), - and jump_insns are always given a cost of 1 by seq_cost, so treat - both instructions as having cost COSTS_N_INSNS (1). */ - if_info.original_cost = COSTS_N_INSNS (2); - + for COND (and it may not exist if we had to canonicalize to get COND). + Here we assume one CC compare insn (if the target uses CC) and one + jump insn that is costed via insn_cost. It is assumed that the + costs of a jump insn are dependent on the branch costs. */ + if (cc_in_cond (if_info.cond)) + if_info.original_cost = pattern_cost (if_info.cond, if_info.speed_p); + if_info.original_cost += insn_cost (if_info.jump, if_info.speed_p); /* Do the real work. */