Re: sparse -Wptr-subtraction-blows: still needed?

From: Al Viro
Date: Tue May 01 2007 - 20:27:24 EST


On Tue, May 01, 2007 at 04:59:57PM -0700, Josh Triplett wrote:
> Linus Torvalds wrote:
> >
> > On Tue, 1 May 2007, Josh Triplett wrote:
> >> Does this still apply? Do current versions of GCC still have this problem?
> >> If not, can the option and warning go away?
> >
> > Even if current versions of gcc don't triple the build time (and for the
> > kernel, I suspect it doesn't, because we've tried to clean up our header
> > files), the generated _code_ will invariably suck.
>
> "invariably"?
>
> Do you know whether the current version of GCC generates poor code for pointer
> subtraction?
>
> If so, does anything in particular make this an unfixable problem?

Just the fact that calculation itself is nasty. In the best case you
get (on x86) something like
sarl $2, %eax
imull $-1431655765, %eax, %eax
(that one is with object size equal to 12). On other targets it can get
considerably uglier - e.g. on alpha with -O2 the same will result in
sra $17,2,$17
s4subq $17,$17,$0
s8subq $0,$0,$0
s4addq $0,$17,$0
sll $0,8,$1
addq $0,$1,$0
sll $0,16,$2
addq $0,$2,$0
sll $0,32,$1
addq $0,$1,$0
addq $0,$0,$0
addl $0,$17,$0
With -Os it's
ldah $1,$LC0($29) !gprelhigh
sra $0,2,$0
ldq $1,$LC0($1) !gprellow
mull $0,$1,$0
with LC0 in rodata:
$LC0:
.quad -6148914691236517205

Now imagine the joy of having a bunch of such wonders in a hot path...
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/