Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp391134ybl; Fri, 30 Aug 2019 01:07:52 -0700 (PDT) X-Google-Smtp-Source: APXvYqzSOEeQLJjt5m0b/c8gowAJmiYk0v1qlyQB8y6EJLU6B5o+3kxVA1uO2+yS9bpoGTuSxwZg X-Received: by 2002:a17:902:748a:: with SMTP id h10mr12826128pll.31.1567152472765; Fri, 30 Aug 2019 01:07:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567152472; cv=none; d=google.com; s=arc-20160816; b=faVAkLu38JAMsd/AF/NpudIX7Uvpdvrkfv4PTBBjgl4fiW89xAZQcl/FhQ1jdgjlak rXfT2RrsKkHvZYkUGX/eSyxh8iaBw0gM9SWIC0bBOsu0LYdRtIC/ulWECU/mGLD98BuB Y4WRp0YR9x5WTxVdXEFX4fwxEhIOOIDjadkINRMbOReQ7GWu4+58wa/wITYXEPICgBOW CNT7J8MxuTTUS0L5ZBEw6JzicKKs81WFnVjeWN89jeU1l9ml2FSDkkG68jdeTuw96PEH vYBr8vVJBi2A8IMLAE6LrcKbcSa6CBAyAoaGEbriQOYFhi5XW7tgWha6yWW0M91k9O2E BQMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=l6zzYJYM7QGVQzakKPo5DCouz5vaM1VLR9vr/7r0mrM=; b=sP46EY1Fi04uIAFBda5qHkQmpUPl+9SwRwIWbHmS4pdFDbdsc8PLoA17+TVk0o526j SBkXx3qxmgqlgc4ieNJ1MRHeCF3qEPI7hSUg2yGclMamcp8ChSFq4q3eifs+oDUTR0Np Nub10aJ9OuKKtoL4syzC7yiu/LlR9zWUVeOfWfVbvyodEAMXeKxOXVln6I/FuXvCUpIp oqDHZjrnG/AxzadhdYG/4wvQor3Cab5ND4tzkvyW/3bQbVZJiaSZ4lHpVPJwyfb9A56D VFh646CAPHgxpIvk+r//Yphl4hA8qR767hjlwYs5v2SftUV++BP5fMOMZFLmyXk6JOyA XI0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b="BK/+q4Ku"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l67si4134505plb.336.2019.08.30.01.07.36; Fri, 30 Aug 2019 01:07:52 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b="BK/+q4Ku"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728236AbfH3IGn (ORCPT + 99 others); Fri, 30 Aug 2019 04:06:43 -0400 Received: from mail-lf1-f66.google.com ([209.85.167.66]:43810 "EHLO mail-lf1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727525AbfH3IGn (ORCPT ); Fri, 30 Aug 2019 04:06:43 -0400 Received: by mail-lf1-f66.google.com with SMTP id q27so4628886lfo.10 for ; Fri, 30 Aug 2019 01:06:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rasmusvillemoes.dk; s=google; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=l6zzYJYM7QGVQzakKPo5DCouz5vaM1VLR9vr/7r0mrM=; b=BK/+q4KuJkEIjJTJUJ2S7jb1ppSxuJKOOTNSS6cyz88U6Z47pOdntEenfzc63oaz15 RhJHYxyYNKu7L9f360FCRgBOJmmEJKJft+jRTezQr8KZD+J+MmlKfxdH8q2X37SZg2nH VF/+COeqVB08odAGg3f6mk4HNLNtCqFyY/mU0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=l6zzYJYM7QGVQzakKPo5DCouz5vaM1VLR9vr/7r0mrM=; b=M+B4gkLDc3N0o3dxxV+rSO5Jd10nWghtvm0ILFTfi2ZGDa5fr5x2i/jglb34umXI1p H+oIEyRNj3vgL5BFsrSn7OLXuCm1Zu2BUJJyuy/QyV6C4TJmhvZLTTDhrGm9rrJEyhx4 SpHwqMIVIw9q+Nx9Dcu9WryNv1eDdDsZJoWO5ZS1GXzWY0Ou3q2tvONUC1nkry93aQaR BeY8WkbVcPHBv/igQudA0DIXOR7i5r/1R65p3JYfMLfWWJIefS3k3P0WN5nOYdiRQ/af 1trrEqAjQtoCp+Qr7ZBQPOXiFlmivGeMoN8lebQNdUhOuMAJtDRITKM00bfQ1ngGW1W4 5p5g== X-Gm-Message-State: APjAAAUlxHad6GqvCrYY8Dz2G83b/WNthVlmbAGTVqEL9gPGUwEtxS1/ e5Rqkt5MgLs5x67ZgL4NU1/CDg== X-Received: by 2002:a19:ae1a:: with SMTP id f26mr8442234lfc.172.1567152401476; Fri, 30 Aug 2019 01:06:41 -0700 (PDT) Received: from [172.16.11.28] ([81.216.59.226]) by smtp.gmail.com with ESMTPSA id u12sm492350lfl.86.2019.08.30.01.06.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 30 Aug 2019 01:06:41 -0700 (PDT) Subject: Re: [PATCH v2] scripts: coccinelle: check for !(un)?likely usage To: Denis Efremov , Julia Lawall Cc: linux-kernel@vger.kernel.org, cocci@systeme.lip6.fr, Gilles Muller , Nicolas Palix , Michal Marek , Markus Elfring , Joe Perches References: <20190825130536.14683-1-efremov@linux.com> <20190829171013.22956-1-efremov@linux.com> <7933d51f-5c2e-26a4-2dee-e13e61d0ac8c@linux.com> From: Rasmus Villemoes Message-ID: Date: Fri, 30 Aug 2019 10:06:39 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: <7933d51f-5c2e-26a4-2dee-e13e61d0ac8c@linux.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 30/08/2019 08.56, Denis Efremov wrote: > > > On 30.08.2019 03:42, Julia Lawall wrote: >> >> >> On Thu, 29 Aug 2019, Denis Efremov wrote: >> >>> On 8/29/19 8:10 PM, Denis Efremov wrote: >>>> This patch adds coccinelle script for detecting !likely and >>>> !unlikely usage. These notations are confusing. It's better >>>> to replace !likely(x) with unlikely(!x) and !unlikely(x) with >>>> likely(!x) for readability. >>> >>> I'm not sure that this rule deserves the acceptance. >>> Just to want to be sure that "!unlikely(x)" and "!likely(x)" >>> are hard-readable is not only my perception and that they >>> become more clear in form "likely(!x)" and "unlikely(!x)" too. >> >> Is likely/unlikely even useful for anything once it is a subexpression? >>> julia >> > > Well, as far as I understand it, Yes, and it could in fact make sense in cases like if (likely(foo->bar) && unlikely(foo->bar->baz)) { do_stuff_with(foo->bar->baz); do_more_stuff(); } which the compiler could then compile as (of course actual code generation is always much more complicated due to things in the surrounding code) load foo->bar; test bar; if 0 goto skip; load bar->baz; test baz; if !0 goto far_away; skip: .... so in the normal flow, neither branch is taken. If instead one wrote unlikely(foo->bar && foo->bar->baz), gcc doesn't really know why we expect the whole conjuntion to turn out false, so it could compile this as a jump when foo->bar turns out non-zero - i.e., in the normal case, we'd end up jumping. But as far as !(un)likely(), I agree that it's easier to read as a human if the ! operator is moved inside (and the "un" prefix stripped/added). Whether it deserves a cocci script I don't know. Rasmus