From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1E0CF3C8708 for ; Sun, 26 Jul 2026 16:11:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.134.164.83 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785082271; cv=none; b=Vd3W1+OlQnoyheVJWS0xNgf509Ea1eNnBG2o/FoVHB/z6KhK2le1oB1P3D5PyD9DVFMhFW/o9M9853nnbYQp39y0s+cto75sGeU3BJ59Xgl5rjiGX+IsW6/DF1zELRAI4ek8QId+Y7/gFV9Dy18dYZqX7BsrUTVMl5aD19/Y40o= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785082271; c=relaxed/simple; bh=UHaLElK3IsJzszrz9EBakKivXINl0DZ2Y7aWJfnQ6DM=; h=Date:From:To:cc:Subject:In-Reply-To:Message-ID:References: MIME-Version:Content-Type; b=KYnTD8YTENRJEsMjWKa6m/5mzdzMuCw2BsBLzWwtUybJm9po6iluWY/1F0K6i/W9aFAV8HLJsdfd5wYBG+zbOwGRfORaenwthJ2AEjC+5Riq6t1PTzZIczQEuh1XnO2ecPL5rVPr1U6x5OJ8OZsRNbgHAjWuASUMJzQ6YDkB5S8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=inria.fr; spf=pass smtp.mailfrom=inria.fr; dkim=pass (1024-bit key) header.d=inria.fr header.i=@inria.fr header.b=cj++GDJv; arc=none smtp.client-ip=192.134.164.83 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=inria.fr Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=inria.fr Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=inria.fr header.i=@inria.fr header.b="cj++GDJv" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=inria.fr; s=dc; h=date:from:to:cc:subject:in-reply-to:message-id: references:mime-version; bh=fQ7wY/c69mDre3E5Gfwi5LSSIgrgeeygssFa4FGlijw=; b=cj++GDJvqPiRu9xNVKaKBZo58zDlH4wn0FXz6Rn7kdqAV0z30JcvNurj pcgCy8l+nNUSLTL2Ce7KP64JcYMzJ5i0gNjzyECNqzJ3Pfn2dZkwqyhhY Pq74zlweaTZhAFZYx+bCGVZZiPpx5md5d/P5+PYqi0G7tM6jpNMZ7Xpst 0=; X-CSE-ConnectionGUID: 9bxL3jCkTAGERKsUuEW6Sg== X-CSE-MsgGUID: 1GqJNy7PSuGt9a/NIp+F2Q== Authentication-Results: mail2-relais-roc.national.inria.fr; dkim=none (message not signed) header.i=none; spf=SoftFail smtp.mailfrom=julia.lawall@inria.fr; dmarc=fail (p=none dis=none) d=inria.fr X-IronPort-AV: E=Sophos;i="6.25,186,1779141600"; d="scan'208";a="287946891" Received: from 88-188-149-159.subs.proxad.net (HELO hadrien.home) ([88.188.149.159]) by mail2-relais-roc.national.inria.fr with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jul 2026 18:11:06 +0200 Date: Sun, 26 Jul 2026 18:11:05 +0200 (CEST) From: Julia Lawall To: Sang-Heon Jeon cc: Julia Lawall , Nicolas Palix , cocci@inria.fr, linux-kernel@vger.kernel.org Subject: Re: [PATCH 3/3] coccinelle: misc: minmax: improve performance when no candidate exists In-Reply-To: <20260725113303.691676-4-ekffu200098@gmail.com> Message-ID: References: <20260725113303.691676-1-ekffu200098@gmail.com> <20260725113303.691676-4-ekffu200098@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII On Sat, 25 Jul 2026, Sang-Heon Jeon wrote: > The rules that report an opencoded min() or max() search every > function body, even when the file contains nothing to find. > > To avoid this, collect the candidates first and run the search only > when one exists. A candidate is any conditional expression whose > condition is a comparison. > > Every opencoded min() or max() is also a candidate, so the same > opportunities are reported as before and the output does not > change. A report-mode run over every .c file in the tree produces > identical output. Applied. I also added "candidate" rules for minif and maxif, removed the outer parentheses on rmax etc, and disabled some isomorphisms that caused the introduction of useless variants of the conditional tests. julia > > Signed-off-by: Sang-Heon Jeon > --- > scripts/coccinelle/misc/minmax.cocci | 24 +++++++++++++++++++----- > 1 file changed, 19 insertions(+), 5 deletions(-) > > diff --git a/scripts/coccinelle/misc/minmax.cocci b/scripts/coccinelle/misc/minmax.cocci > index ca4830ae3042..93c074b9439f 100644 > --- a/scripts/coccinelle/misc/minmax.cocci > +++ b/scripts/coccinelle/misc/minmax.cocci > @@ -17,7 +17,21 @@ virtual org > virtual context > virtual patch > > -@rmax depends on !patch@ > +@max_candidate@ > +expression E1, E2, E3, E4; > +binary operator cmp = {>, >=}; > +@@ > + > + (E1 cmp E2 ? E3 : E4) > + > +@min_candidate@ > +expression E1, E2, E3, E4; > +binary operator cmp = {<, <=}; > +@@ > + > + (E1 cmp E2 ? E3 : E4) > + > +@rmax depends on !patch && max_candidate@ > identifier func; > expression x, y; > binary operator cmp = {>, >=}; > @@ -51,7 +65,7 @@ func(...) > } > > // Ignore errcode returns. > -@errcode@ > +@errcode depends on min_candidate@ > position p; > identifier func; > expression x; > @@ -65,7 +79,7 @@ func(...) > ...> > } > > -@rmin depends on !patch@ > +@rmin depends on !patch && min_candidate@ > identifier func; > expression x, y; > binary operator cmp = {<, <=}; > @@ -98,7 +112,7 @@ func(...) > ...> > } > > -@pmax depends on patch@ > +@pmax depends on patch && max_candidate@ > identifier func; > expression x, y; > binary operator cmp = {>=, >}; > @@ -131,7 +145,7 @@ func(...) > ...> > } > > -@pmin depends on patch@ > +@pmin depends on patch && min_candidate@ > identifier func; > expression x, y; > binary operator cmp = {<=, <}; > -- > 2.43.0 > >