http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56309



--- Comment #10 from arturomdn at gmail dot com 2013-02-14 16:43:23 UTC ---

Might be worth mentioning here what I said in the stackoverflow answer, that in

this particular case the entire conditional branch can be avoided because it is

redundant.



This code



    if (tmp >= imax) {

        carry = tmp >> numbits;    // <---- A

        tmp &= imax - 1;                // <---- B

    } else {

        carry = 0;                            // <---- C

    }



can be reduced to



    carry = tmp >> numbits;

    tmp &= imax - 1;



Proof:

    1) numbits is 32

    2) imax is 1ULL << 32 so lower 32 bits are zero

    3) imax - 1 is 0xFFFFFFFF (see 2)

    4) if tmp >= imax then tmp has bits set in upper 32 bits

    5) otherwise if tmp < imax then tmp does not have bits set in upper 32 bits

    6) statement "A" is equivalent to "C" when tmp < imax (because of 4)

    7) statement "B" is a NOP when tmp < imax (because of 3 and 5)

Reply via email to