linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Sparse Mailing-list <linux-sparse@vger.kernel.org>
Subject: Re: [PATCH 00/10] simplify and canonicalize signed compares
Date: Sat, 17 Apr 2021 20:20:54 +0200	[thread overview]
Message-ID: <20210417182054.rz52qrkm5hjnlv4z@mail> (raw)
In-Reply-To: <CAHk-=wgO=9N_Qz6MsXB2SVUGXHX53bFEvNDbmLHB6_W+dEBN-A@mail.gmail.com>

On Sat, Apr 17, 2021 at 10:16:31AM -0700, Linus Torvalds wrote:
> On Tue, Jan 26, 2021 at 7:45 PM Luc Van Oostenryck
> <luc.vanoostenryck@gmail.com> wrote:
> >
> > This series fixes and improves the simplification and the
> > canonicalization of signed compares.
> 
> Hmm. Sorry for not replying earlier, but I just checked the most
> common simplification of signed compares, and it didn't work.
> 
> This:
> 
>     _Bool test(int a)
>     {
>         return a >=0 && a < 16;
>     }
> 
> should simplify to be the same as
> 
>     _Bool test(int a)
>     {
>         return (unsigned)a < 16;
>     }
> 
> but it doesn't. It generates the silly - but straightforward - "two
> comparisons and a 'and' of the result".

Yes, I've a draft for this but I still needs to add some tests and such.

> In fact, the recent canonicalizations means that the compare against
> zero is actually pessimised, and ">= 0" becomes "> 0xffffffff", which
> is often a much more expensive operation.

Yes, I'm aware of the problem, more or less.
When I did the canonicalization, I wondered what was better:
* canonicalize toward 0
* canonicalize toward the smallest

I choose the later because at the moment it was somehow advantageous
because it reduced by 2 some patterns (it allows to eliminate all >=
and all <; when doing it toward 0 you can eliminate one set for positive
and the other one for negatives values so you need both sets). The
compare with -1 instead of with 0 didn't looked much problematic and
relatively rare. But in the following days I realized it was in fact
quite annoying.

So, yes, it's something I'll change very soon.

-- Luc

      reply	other threads:[~2021-04-17 18:21 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-26 22:04 [PATCH 00/10] simplify and canonicalize signed compares Luc Van Oostenryck
2021-01-26 22:04 ` [PATCH 01/10] cmps: make clearer we're using the operands' size Luc Van Oostenryck
2021-01-26 22:04 ` [PATCH 02/10] cmps: fix simplification of sext(x) + signed compare of {SMAX,SMIN} Luc Van Oostenryck
2021-01-26 22:04 ` [PATCH 03/10] cmpu: fix canonicalization of unsigned (x {<,>=} C) --> (x {<=,>} C-1) Luc Van Oostenryck
2021-01-26 22:04 ` [PATCH 04/10] cmps: add testcases for simplification of signed compares Luc Van Oostenryck
2021-01-26 22:04 ` [PATCH 05/10] cmps: simplify signed compares with SMIN or SMAX Luc Van Oostenryck
2021-01-26 22:04 ` [PATCH 06/10] cmps: canonicalize signed compares with SMIN/SMAX Luc Van Oostenryck
2021-01-26 22:04 ` [PATCH 07/10] cmps: canonicalize SMIN/SMAX +- 1 --> EQ/NE Luc Van Oostenryck
2021-01-26 22:04 ` [PATCH 08/10] cmps: canonicalize signed compares with constant Luc Van Oostenryck
2021-01-26 22:04 ` [PATCH 09/10] cmps: canonicalize SEL(x {<,<=} y, a, b) --> SEL(x {>=,>} y, b, a) Luc Van Oostenryck
2021-01-26 22:04 ` [PATCH 10/10] cmps: canonicalize SEL(x > 0, a, -a) --> SEL(x >= 0, a, -a) Luc Van Oostenryck
2021-04-17 17:16 ` [PATCH 00/10] simplify and canonicalize signed compares Linus Torvalds
2021-04-17 18:20   ` Luc Van Oostenryck [this message]

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=20210417182054.rz52qrkm5hjnlv4z@mail \
    --to=luc.vanoostenryck@gmail.com \
    --cc=linux-sparse@vger.kernel.org \
    --cc=torvalds@linux-foundation.org \
    /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;
as well as URLs for NNTP newsgroup(s).