From patchwork Fri Aug 10 10:32:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Martin_Li=C5=A1ka?= X-Patchwork-Id: 956189 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-483490-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="LrJsCuef"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41n1fG42b2z9s4Z for ; Fri, 10 Aug 2018 20:32:37 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :subject:to:cc:message-id:date:mime-version:content-type; q=dns; s=default; b=liEE/F/HlJtVUhWmK8BVGEEHUT+kLQ/siCXK75K3NYKeHCS3Wd ljb4A66CT79wra2/6N8zSwG+0MP3BoMcgqmW1nT5NFkC571xk3GbmYkRt3VfJq2r OBTf4N6kzJSvESuNhe926x1B7geEqoCBvQMxrT8hGkYJC+0YpbWFocGAM= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :subject:to:cc:message-id:date:mime-version:content-type; s= default; bh=CyB+tJZCs2DMUYnJawYKEcp0Xq8=; b=LrJsCuef1RJxjESNjs9f CsFMLRMGCgBcC0JlQtm+2iAzicW4hOhC0R3oaib0LBEqcYCki18dQWpMXyhHdmX7 lLupc5MR0UQhKPdCEiL6dG6u7hlUk82BjKLnJGwfrP4BjKr4BwBnWATkrL1fT5lI TXPO9l3wv0rzH+Gp2mjBJVU= Received: (qmail 81847 invoked by alias); 10 Aug 2018 10:32:30 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 81836 invoked by uid 89); 10 Aug 2018 10:32:29 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_PASS autolearn=ham version=3.3.2 spammy=004, 10.00 X-HELO: mx1.suse.de Received: from mx2.suse.de (HELO mx1.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 10 Aug 2018 10:32:28 +0000 Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id DA003AFDD; Fri, 10 Aug 2018 10:32:25 +0000 (UTC) From: =?utf-8?q?Martin_Li=C5=A1ka?= Subject: [PATCH] Remove not needed __builtin_expect due to malloc predictor. To: gcc-patches@gcc.gnu.org Cc: Jonathan Wakely Message-ID: <1a53e1ef-3fec-d1c7-4c9d-42fe4542da44@suse.cz> Date: Fri, 10 Aug 2018 12:32:25 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 X-IsSubscribed: yes Hi. After we introduced new non-NULL malloc predictor, we can remove these __builtin_expects. Predictors will change in following way: Before: Predictions for bb 5 first match heuristics: 10.00% combined heuristics: 10.00% __builtin_expect heuristics of edge 5->6: 10.00% call heuristics of edge 5->6 (ignored): 33.00% loop exit heuristics of edge 5->9 (ignored): 5.50% After: Predictions for bb 5 first match heuristics: 0.04% combined heuristics: 0.04% pointer (on trees) heuristics of edge 5->6 (ignored): 30.00% malloc returned non-NULL heuristics of edge 5->6: 0.04% call heuristics of edge 5->6 (ignored): 33.00% loop exit heuristics of edge 5->9 (ignored): 5.50% Maybe there are similar allocation-related expects, but I haven't found them. Ready after it survives regression tests? Martin libstdc++-v3/ChangeLog: 2018-08-10 Martin Liska * libsupc++/new_op.cc (new): Remove __builtin_expect as malloc predictor can handle that. * libsupc++/new_opa.cc: Likewise. * libsupc++/new_opnt.cc (new): Likewise. --- libstdc++-v3/libsupc++/new_op.cc | 2 +- libstdc++-v3/libsupc++/new_opa.cc | 2 +- libstdc++-v3/libsupc++/new_opnt.cc | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libstdc++-v3/libsupc++/new_op.cc b/libstdc++-v3/libsupc++/new_op.cc index 3a1e38d9df7..3caa0bab2ea 100644 --- a/libstdc++-v3/libsupc++/new_op.cc +++ b/libstdc++-v3/libsupc++/new_op.cc @@ -47,7 +47,7 @@ operator new (std::size_t sz) _GLIBCXX_THROW (std::bad_alloc) if (sz == 0) sz = 1; - while (__builtin_expect ((p = malloc (sz)) == 0, false)) + while ((p = malloc (sz)) == 0) { new_handler handler = std::get_new_handler (); if (! handler) diff --git a/libstdc++-v3/libsupc++/new_opa.cc b/libstdc++-v3/libsupc++/new_opa.cc index 68eac5b8ceb..a27ff843ca1 100644 --- a/libstdc++-v3/libsupc++/new_opa.cc +++ b/libstdc++-v3/libsupc++/new_opa.cc @@ -126,7 +126,7 @@ operator new (std::size_t sz, std::align_val_t al) #endif using __gnu_cxx::aligned_alloc; - while (__builtin_expect ((p = aligned_alloc (align, sz)) == 0, false)) + while ((p = aligned_alloc (align, sz)) == 0) { new_handler handler = std::get_new_handler (); if (! handler) diff --git a/libstdc++-v3/libsupc++/new_opnt.cc b/libstdc++-v3/libsupc++/new_opnt.cc index a2dc33ad4d3..faab44e66c2 100644 --- a/libstdc++-v3/libsupc++/new_opnt.cc +++ b/libstdc++-v3/libsupc++/new_opnt.cc @@ -40,7 +40,7 @@ operator new (std::size_t sz, const std::nothrow_t&) _GLIBCXX_USE_NOEXCEPT if (sz == 0) sz = 1; - while (__builtin_expect ((p = malloc (sz)) == 0, false)) + while ((p = malloc (sz)) == 0) { new_handler handler = std::get_new_handler (); if (! handler)