From patchwork Sat Mar 25 09:53:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 74885 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp354600vqo; Sat, 25 Mar 2023 04:49:55 -0700 (PDT) X-Google-Smtp-Source: AKy350acdRpOFkM9TiNQvBCricUE1RiPZb+685XdeE+ns9IEKSrpZSi/94xTuB82WD/OHMDiSfmm X-Received: by 2002:a17:906:9f19:b0:93c:847d:a456 with SMTP id fy25-20020a1709069f1900b0093c847da456mr6800210ejc.22.1679744995624; Sat, 25 Mar 2023 04:49:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679744995; cv=none; d=google.com; s=arc-20160816; b=jT282D8ShdGDMKjYy6RY31Ve/Kg/gwjBNXWrL7uDVRY7rkRA4dFQFhw/yL+0cYIUUf uXiIAPZYtw4oKb5S79xDdYZvyuSYoZFK/jKQiYjQHEBsJQ+WYas5ItrLiBP1igOWI+R6 QOzi/WcpkbSPXqReWJnbxgCwC2F5JMPsNnEUpS0rKQm6ONxq7LJm8OBgZrcXT7TiABZN s/yddBF28+ogV8c9B7j1ALQEaGbxbz2jvArpGmL0QjicHcEn7N7ioqUIwcCqde65S/4s zPN39ySdKNOdHZrMknX6kqdrLN7V8rjwiV/SCwcvn1GSktiMQW2gIUKwQo+3pSxtKh5i /ySQ== 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-disposition:mime-version:message-id:subject:cc:to:date :resent-to:resent-message-id:resent-date:resent-from:dmarc-filter :delivered-to:dkim-signature:dkim-filter; bh=Mx+R8OJE4VJeVLZEbVkLUBIU84hwh7biKU6qqbaB744=; b=lUiMs6TWd7LFJF7MkqZStUNTqbrbQLf3LD96FbRH7iME6pXataYPx8U3mkEKw4nhVW Vm2oPKcZcUXg6DI6rFgzuW//d6aS09kk0baV8Pp+aLCOQ51Xu+MeiMBbT2HvWkpTwsWu 7WTBuIhaEWSMwWPsEqmtDk3QDf9bNRwkJLpDIwIr5Cq9HdpusUihGZZN7FHiQpHYwSFB 1ca4VRkIR+2omIfLraaMzoc2c9TLC1wa3gLZfEb6VnFgXFJHeIFIq54PUtr2t+v0wwJt Eqymgf1+m95kOWLqogXdyr5MrT09ypbibekSIe6z4y0L6rMqPMnr8rOZ7GTQeLxrOZbt WovA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=eGCBoiPW; 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 sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id q1-20020aa7cc01000000b0050212939157si5579086edt.654.2023.03.25.04.49.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Mar 2023 04:49:55 -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=eGCBoiPW; 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 8681338708AA for ; Sat, 25 Mar 2023 11:49:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8681338708AA DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1679744994; bh=Mx+R8OJE4VJeVLZEbVkLUBIU84hwh7biKU6qqbaB744=; h=Resent-From:Resent-Date:Resent-To:Date:To:Cc:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=eGCBoiPWsrEzM4dR9BPNfBymjjiuyaGV/4FbJIz8ssY7pUGVLJ3oUU7IB+atdFI7b 8VTeusmFx1W1RRZQsMUGWLGqmtMzQyO1GUIeTHOy5OpmsTeHyrxfSKfX8w/w4LqvQQ tYI+8Fk0oFJgzE6UFTt89o7E+99/iwY0VFie0m8E= 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.129.124]) by sourceware.org (Postfix) with ESMTPS id 0FA3A3858D20 for ; Sat, 25 Mar 2023 11:49:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0FA3A3858D20 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-433-hdaHVV1RO4uKhI4KUFEl_w-1; Sat, 25 Mar 2023 07:49:09 -0400 X-MC-Unique: hdaHVV1RO4uKhI4KUFEl_w-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E43B5101A54F for ; Sat, 25 Mar 2023 11:49:08 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.16]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0104B2166B26 for ; Sat, 25 Mar 2023 11:49:07 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 32PA2Qq33359745 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Sat, 25 Mar 2023 11:03:50 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 32PA11XI3359733; Sat, 25 Mar 2023 11:01:01 +0100 Resent-From: Jakub Jelinek Resent-Date: Sat, 25 Mar 2023 11:01:01 +0100 Resent-Message-ID: Resent-To: Richard Biener , Jan Hubicka , gcc-patches@gcc.gnu.org Date: Sat, 25 Mar 2023 10:53:09 +0100 To: Richard Biener , Jan Hubicka Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] predict: Don't emit -Wsuggest-attribute=cold warning for functions which already have that attribute [PR105685] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.3 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761340288730849030?= X-GMAIL-MSGID: =?utf-8?q?1761340288730849030?= Hi! In the following testcase, we predict baz to have cold entry regardless of the user supplied attribute (as it call unconditionally a cold function), but still issue a -Wsuggest-attribute=cold warning despite it having that attribute already. The following patch avoids that. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2023-03-25 Jakub Jelinek PR ipa/105685 * predict.cc (compute_function_frequency): Don't call warn_function_cold if function already has cold attribute. * c-c++-common/cold-2.c: New test. Jakub --- gcc/predict.cc.jj 2023-01-02 09:32:38.273055726 +0100 +++ gcc/predict.cc 2023-03-24 16:54:13.658606215 +0100 @@ -4033,7 +4033,9 @@ compute_function_frequency (void) } node->frequency = NODE_FREQUENCY_UNLIKELY_EXECUTED; - warn_function_cold (current_function_decl); + if (lookup_attribute ("cold", DECL_ATTRIBUTES (current_function_decl)) + == NULL) + warn_function_cold (current_function_decl); if (ENTRY_BLOCK_PTR_FOR_FN (cfun)->count.ipa() == profile_count::zero ()) return; FOR_EACH_BB_FN (bb, cfun) --- gcc/testsuite/c-c++-common/cold-2.c.jj 2023-03-24 16:56:07.344000973 +0100 +++ gcc/testsuite/c-c++-common/cold-2.c 2023-03-24 16:55:58.985119001 +0100 @@ -0,0 +1,19 @@ +/* PR ipa/105685 */ +/* { dg-do compile } */ +/* { dg-options "-O2 -Wsuggest-attribute=cold" } */ + +extern void foo (char *, char const *, int); + +__attribute__((cold)) char * +bar (int x) +{ + static char b[42]; + foo (b, "foo", x); + return b; +} + +__attribute__((cold)) char * +baz (int x) /* { dg-bogus "function might be candidate for attribute 'cold'" } */ +{ + return bar (x); +}