Re: [PATCHSET] fouled-bitwise handling

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On Sun, 1 Oct 2006, Linus Torvalds wrote:
>
> See? Even from a purely optimization angle, we're actually better off just 
> noticing that the whole comparison can be done in the narrower type.

So here's a test-case:

	typedef unsigned short le16;

	int cmp(le16 a, le16 b)
	{
		return a == (a & ~b);
	}

and doing a "./test-linearize" on this gets us:

	cmp:
	.L0xf7fa500c:
	        <entry-point>
	        dead        %arg1
	        scast.32    %r2 <- (16) %arg1
	        dead        %arg2
	        scast.32    %r6 <- (16) %arg2
	        dead        %r6
	        not.32      %r7 <- %r6
	        dead        %r7
	        and.32      %r8 <- %r2, %r7
	        dead        %r8
	        dead        %r2
	        seteq.32    %r9 <- %r2, %r8
	        dead        %r9
	        scast.32    %r10 <- (1) %r9
	        dead        %r10
	        ret.32      %r10

which is just horrible code anyway.

I think it _should_ be

	cmp:
	.L0xf7fa500c:
	        <entry-point>
	        dead        %arg2
	        not         %r4 <- %arg2
	        dead        %r4
	        and         %r5 <- %arg1, %r4
	        dead        %r5
	        dead        %arg1
	        seteq.16    %r6 <- %arg1, %r5
	        dead        %r6
	        scast.32    %r7 <- (1) %r6
	        dead        %r7
	        ret.32      %r7

instead, which is obviously smaller and avoids the two unnecessary casts.

(Now, it's entirely possible that we warn so early that we can't 
reasonably do this optimization until after we've already warned, but I've 
been able to remove these kinds of warnings before, so I think it should 
be possible to do it here too).

I much prefer (if possible) the "make sparse so much smarter that it sees 
that it's ok" approach over "let's add a magic special case". For example, 
a lot of the work I did to make the lock acquire/release logic useful was 
very much about teaching sparse to simplify code-flow rather than anything 
else.

But hey, maybe this case is too hard or nasty..

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

[Index of Archives]     [Newbies FAQ]     [LKML]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Trinity Fuzzer Tool]

  Powered by Linux