From: Andi Kleen <andi@firstfloor.org>
To: Alan Cox <alan@lxorguk.ukuu.org.uk>
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
Josh Triplett <josh@freedesktop.org>,
linux-sparse@vger.kernel.org, linux-kernel@vger.kernel.org,
Al Viro <viro@ftp.linux.org.uk>
Subject: Re: sparse -Wptr-subtraction-blows: still needed?
Date: 02 May 2007 15:19:11 +0200 [thread overview]
Message-ID: <p734pmvxt0w.fsf@bingen.suse.de> (raw)
In-Reply-To: <20070502130204.2cc2fd1a@the-village.bc.nu>
Alan Cox <alan@lxorguk.ukuu.org.uk> writes:
>
> Good compilers even in the 1990's would defer the divide and try and
> propogate it out as a multiply the other side for constants, and they'll
> also use shifts when possible.
gcc has an algorithm that tends to generate a near perfect shift/add etc.
code sequence and also knows the obvious x / y ==> x*1/y
However it doesn't do that with -Os, prefering smaller code on x86
(idiv is fairly small compared to the expanded sequences for non power
of two dividends) and kernels are usually compiled with -Os these
days.
We've had a few cases in the past where this showed up as regression
against older kernels that still used -O2.
> Thus they'll turn
>
> (ptr.element - base.element) < NELEM
>
> into
> (ptr.char - base.char) < (constant) [NELEM *sizeof(element) ]
>
>
> at least for constant operations. Dunno if gcc is that clever
It is. However a few more complex transformations I would have liked
in the past are missing -- in particular
x / (cond ? const1 : const2) ==> cond ? (x / const1) : (x / const2)
-Andi
next prev parent reply other threads:[~2007-05-02 12:21 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-05-01 21:08 sparse -Wptr-subtraction-blows: still needed? Josh Triplett
2007-05-01 21:43 ` Linus Torvalds
2007-05-01 23:59 ` Josh Triplett
2007-05-02 0:24 ` Linus Torvalds
2007-05-02 0:35 ` Al Viro
2007-05-02 12:02 ` Alan Cox
2007-05-02 13:19 ` Andi Kleen [this message]
2007-05-02 0:26 ` Al Viro
2007-05-02 0:02 ` Al Viro
2007-05-02 2:42 ` Dave Jones
2007-05-02 13:03 ` Andi Kleen
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=p734pmvxt0w.fsf@bingen.suse.de \
--to=andi@firstfloor.org \
--cc=alan@lxorguk.ukuu.org.uk \
--cc=josh@freedesktop.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sparse@vger.kernel.org \
--cc=torvalds@linux-foundation.org \
--cc=viro@ftp.linux.org.uk \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.