linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Christopher Li <sparse@chrisli.org>
To: "Jacek Śliwerski" <sliwers@googlemail.com>
Cc: linux-sparse@vger.kernel.org
Subject: Re: Defect in linearization of short circuit &&
Date: Mon, 15 Feb 2010 11:41:11 -0800	[thread overview]
Message-ID: <70318cbf1002151141p35e49f92l73510d09452f56ee@mail.gmail.com> (raw)
In-Reply-To: <4B799CA6.70807@googlemail.com>

2010/2/15 Jacek Śliwerski <sliwers@googlemail.com>:
> Christopher Li pisze:
>      /*
>       * If the right side is safe and cheaper than a branch,
>       * just avoid the branch and turn it into a regular binop
>       * style SAFELOGICAL.
>       */
>      if (rcost < BRANCH_COST) {
>              expr->type = EXPR_BINOP;
>              rcost -= BRANCH_COST - 1;
>      }
>
> After removing these lines, everything works fine.
>
> But I guess that there must have been a reason to add them in the first
> place.  I see it checking the cost of the operation, but I don't know why
> somebody assumes that it would be safe not to make a branch. Does anybody
> know how to fix it without simply removing these lines?

That is an optimization from Linus. It basically find out the simple variable
case comparing variable and turn it into binary operations and avoiding the
branch. It is cheaper to use "setne" than "cmp; jne; mov;".

It is safe because all the unsafe operations, e.g. dereferencing memory,
should have set the cost high enough to avoid this optimization.
e.g. all local variable dereferencing should be safe, because the address
is in the stack.

Deferencing a pointer is not, so sparse will not optimize it.

Chris
--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

  reply	other threads:[~2010-02-15 19:41 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-02-14 13:39 Defect in linearization of short circuit && Jacek Śliwerski
2010-02-14 21:04 ` Jacek Śliwerski
2010-02-14 23:09   ` Christopher Li
2010-02-15 19:12     ` Jacek Śliwerski
2010-02-15 19:41       ` Christopher Li [this message]
2010-02-15 20:18         ` Jacek Śliwerski
2010-02-15 21:11           ` Christopher Li
2010-02-16  9:28             ` Bernd Petrovitsch
2010-02-16 19:02               ` Christopher Li
2010-02-16 19:10                 ` Christopher Li
2010-02-16 19:19                 ` Jacek Śliwerski
2010-02-16 19:36                   ` Christopher Li
2010-02-16 20:11                     ` enum warning patch (was Re: Defect in linearization of short circuit &&) Kamil Dudka
2010-02-16 20:18                       ` Kamil Dudka
2010-02-16 22:44                         ` Christopher Li
2010-02-17 14:00                           ` Kamil Dudka
2010-02-17 11:47                 ` Defect in linearization of short circuit && Bernd Petrovitsch
2010-02-17 20:22                   ` Christopher Li

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=70318cbf1002151141p35e49f92l73510d09452f56ee@mail.gmail.com \
    --to=sparse@chrisli.org \
    --cc=linux-sparse@vger.kernel.org \
    --cc=sliwers@googlemail.com \
    /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).