Re: Defect in linearization of short circuit &&

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

 



2010/2/15 Jacek Śliwerski <sliwers@xxxxxxxxxxxxxx>:
> 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@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