mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Julia Lawall <julia.lawall@inria.fr>
To: Sang-Heon Jeon <ekffu200098@gmail.com>
Cc: Julia Lawall <Julia.Lawall@inria.fr>,
	 Nicolas Palix <nicolas.palix@imag.fr>,
	cocci@inria.fr,  linux-kernel@vger.kernel.org
Subject: Re: [PATCH 3/3] coccinelle: misc: minmax: improve performance when no candidate exists
Date: Sun, 26 Jul 2026 18:11:05 +0200 (CEST)	[thread overview]
Message-ID: <f16e75db-2e5a-81c6-76b5-dcd0583f2f8b@inria.fr> (raw)
In-Reply-To: <20260725113303.691676-4-ekffu200098@gmail.com>



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 <ekffu200098@gmail.com>
> ---
>  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
>
>

  reply	other threads:[~2026-07-26 16:11 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-25 11:32 [PATCH 0/3] coccinelle: improve performance of mini_lock, double_lock and minmax Sang-Heon Jeon
2026-07-25 11:32 ` [PATCH 1/3] coccinelle: mini_lock: improve performance when searching loops Sang-Heon Jeon
2026-07-26 13:55   ` [cocci] " Markus Elfring
2026-07-26 14:14     ` Julia Lawall
2026-07-26 16:42   ` Julia Lawall
2026-07-27 11:11     ` Sang-Heon Jeon
2026-07-25 11:32 ` [PATCH 2/3] coccinelle: double_lock: improve performance when no double lock exists Sang-Heon Jeon
2026-07-25 19:48   ` Julia Lawall
2026-07-26 10:28     ` Sang-Heon Jeon
2026-07-25 11:32 ` [PATCH 3/3] coccinelle: misc: minmax: improve performance when no candidate exists Sang-Heon Jeon
2026-07-26 16:11   ` Julia Lawall [this message]
2026-07-26 16:28     ` Sang-Heon Jeon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f16e75db-2e5a-81c6-76b5-dcd0583f2f8b@inria.fr \
    --to=julia.lawall@inria.fr \
    --cc=cocci@inria.fr \
    --cc=ekffu200098@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nicolas.palix@imag.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®