From patchwork Thu Sep 14 15:28:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Vladimir Makarov X-Patchwork-Id: 139644 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp431305vqi; Thu, 14 Sep 2023 08:29:22 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH/Val+HHGYzCLbIszDoQRUftqZF5KxWtDxPvLuhiOA1zkQeFY9zhQqPIQANTnr8flC7Q+C X-Received: by 2002:a2e:9791:0:b0:2b9:e93e:65e6 with SMTP id y17-20020a2e9791000000b002b9e93e65e6mr5556270lji.35.1694705361799; Thu, 14 Sep 2023 08:29:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694705361; cv=none; d=google.com; s=arc-20160816; b=iB+WE9wKvzqaI3N5P1rvCsncRk13+qKeRKW5f2lL5+k3TnTNB8gMLNS72xSJ51KoNd ExM5KdWclclp5QJ7pO7qpJSDglzqGYJRfTAprSkvhxBY1phpfikqTih1ynF1OLZRg/rz dsTIJJ9ENHsj/nIr+IMwP1c5QBjuKeeWKJGMgCC+35yRT4cBcvpj1jUwRFI0GzBBByZs ZK9kTdaTHM/GU9ZxZ948YbCR8PTIRjk4QQHb1z88LTKqVvexBfyGAvuoLbpbevuBMxcb NYozW9IFZi1GoMGhEBbxwdrq3QW6Zns+OgDvoIFUk0tBVdx20fXNvDwLskIguK/zhZps bxJw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:content-language :subject:to:user-agent:mime-version:date:message-id:dmarc-filter :delivered-to:dkim-signature:dkim-filter; bh=jeXyrpaxBQRI+CF7pTN/rQYYOtpPUjTTMIChy33fXus=; fh=XNn3asQvIblazGK92GBt13dVv+YmGV3pBS0JC29ZQco=; b=JwiYI4eB+ApUwuufPT8DvfCYEgUDoe8u6KDwBZFtDEhVakHcvcU+JU9bpLy2mrt0Et MFi0mgylBiyj2sg0xzJCpWiotvVaM3XcENKn3g4ws9HeUsY9OETXwjr3N1pr2PFTTsUQ n+tChZh20dxquypLP3Ifu1NTI600HMAjdMDyROaRPwIgRg/WJHEDpG4vSEd1kJBfS8WU dIt1A9UY+x6XWEktSyCNUvqSpfFHS+cuJw+uU1uzp1mzMqOuj+DiXoZhNLyt1lvrjKwf +9wsM2r/lXcrExupqUmu2LJ8asfur1vzlM6sqz0mVgSRu8xgsjP9dG4WAq1xGrTfFe+u ogVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=VxOZmZib; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id y14-20020a170906470e00b009a1960b4ad9si1447180ejq.515.2023.09.14.08.29.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 08:29:21 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=VxOZmZib; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A981D385800A for ; Thu, 14 Sep 2023 15:29:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A981D385800A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1694705360; bh=jeXyrpaxBQRI+CF7pTN/rQYYOtpPUjTTMIChy33fXus=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=VxOZmZibsRU9BgHMWMgv6ZxYX/SlsfBlYLl4RLB4EMcymsW5g7I1oreo+VQMS/pH/ OJujWlpgPExQnPknkH/q1jMJPqXZm/w/fRe3+ar3vWiaWa4/nQYK6f1MCEv0uJsdBi UWx4m8nlEZwog/Toc3rlMjL16WGmPBdrh8Ja5pLw= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 8B3123858CDA for ; Thu, 14 Sep 2023 15:28:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8B3123858CDA Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-574-sS9AgYc_MiS-G8v2LCkdWw-1; Thu, 14 Sep 2023 11:28:35 -0400 X-MC-Unique: sS9AgYc_MiS-G8v2LCkdWw-1 Received: by mail-qt1-f199.google.com with SMTP id d75a77b69052e-414d73cb191so17227671cf.0 for ; Thu, 14 Sep 2023 08:28:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694705315; x=1695310115; h=subject:from:to:content-language:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=pcmbgSPe9pi2dhmEtP4oy9N34oZxoZz5W7bYQvEuM20=; b=RrA3D5o+jUUxsAzC84iZymjliAe2gI7lFA3i50IBu3aaA6JRTXulerUqEvEwJe3NuW vmaBQjMMxvSJGBSgLy0ghO8fbycOrYG+PkSXfJUxvYIbzrNb52OOQqGEbjxBKxARy665 o/OXs05IFdJzVFk/DOyK0d29DoYhUXCWhm/tzQLa/7SRHGEkWWHLgb9eOhH4b1EURHLk amGl2aDkc1Galvjzl5UHzG0PLqsMih4Eo7PGkx7tcwHyr3aCr7X/XQjL6LuTy4OZ+OXj TYpMJADKl7/KxaJ++xrrCdrYssFVefv/QJ2AYM0DExDbEcvtH5vl06Sr/lPN+5v0K2/t w7ew== X-Gm-Message-State: AOJu0YwIif/RbLeZB/zQS8k8SAAgMLpx4K/uS6dpybcyxsI1VpkBLXYr Ic5faL2ubBcBF1nl3p46lGYkTgBpXEhTB46RK4wg/OOk1bUtKKmrD7CLb0ZV0sOUEbP/I1s95Pe rCz50wLi0+4HQo9E4vFDm+LQDD3VTPBbXQLJ0BHE572npCFu3sKnY+SWa9nhIcaEIIRYXbPumor sOcw== X-Received: by 2002:a05:622a:170b:b0:403:e745:2622 with SMTP id h11-20020a05622a170b00b00403e7452622mr2650312qtk.19.1694705314945; Thu, 14 Sep 2023 08:28:34 -0700 (PDT) X-Received: by 2002:a05:622a:170b:b0:403:e745:2622 with SMTP id h11-20020a05622a170b00b00403e7452622mr2650291qtk.19.1694705314627; Thu, 14 Sep 2023 08:28:34 -0700 (PDT) Received: from [192.168.1.88] (192-0-143-139.cpe.teksavvy.com. [192.0.143.139]) by smtp.gmail.com with ESMTPSA id l25-20020ac87259000000b00413152fb99esm519548qtp.49.2023.09.14.08.28.33 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 14 Sep 2023 08:28:34 -0700 (PDT) Message-ID: Date: Thu, 14 Sep 2023 11:28:33 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 To: "gcc-patches@gcc.gnu.org" Subject: [pushed] [RA]: Improve cost calculation of pseudos with equivalences X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US X-Spam-Status: No, score=-11.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP 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: , X-Patchwork-Original-From: Vladimir Makarov via Gcc-patches From: Vladimir Makarov Reply-To: Vladimir Makarov Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777027369165057587 X-GMAIL-MSGID: 1777027369165057587 I've committed the following patch.  The reason for this patch is explained in its commit message. The patch was successfully bootstrapped and tested on x86-64, aarch64, and ppc64le. commit 3c834d85f2ec42c60995c2b678196a06cb744959 Author: Vladimir N. Makarov Date: Thu Sep 14 10:26:48 2023 -0400 [RA]: Improve cost calculation of pseudos with equivalences RISCV target developers reported that RA can spill pseudo used in a loop although there are enough registers to assign. It happens when the pseudo has an equivalence outside the loop and the equivalence is not merged into insns using the pseudo. IRA sets up that memory cost to zero when the pseudo has an equivalence and it means that the pseudo will be probably spilled. This approach worked well for i686 (different approaches were benchmarked long time ago on spec2k). Although common sense says that the code is wrong and this was confirmed by RISCV developers. I've tried the following patch on I7-9700k and it improved spec17 fp by 1.5% (21.1 vs 20.8) although spec17 int is a bit worse by 0.45% (8.54 vs 8.58). The average generated code size is practically the same (0.001% difference). In the future we probably need to try more sophisticated cost calculation which should take into account that the equiv can not be combined in usage insns and the costs of reloads because of this. gcc/ChangeLog: * ira-costs.cc (find_costs_and_classes): Decrease memory cost by equiv savings. diff --git a/gcc/ira-costs.cc b/gcc/ira-costs.cc index d9e700e8947..8c93ace5094 100644 --- a/gcc/ira-costs.cc +++ b/gcc/ira-costs.cc @@ -1947,15 +1947,8 @@ find_costs_and_classes (FILE *dump_file) } if (i >= first_moveable_pseudo && i < last_moveable_pseudo) i_mem_cost = 0; - else if (equiv_savings < 0) - i_mem_cost = -equiv_savings; - else if (equiv_savings > 0) - { - i_mem_cost = 0; - for (k = cost_classes_ptr->num - 1; k >= 0; k--) - i_costs[k] += equiv_savings; - } - + else + i_mem_cost -= equiv_savings; best_cost = (1 << (HOST_BITS_PER_INT - 2)) - 1; best = ALL_REGS; alt_class = NO_REGS;