https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112600

--- Comment #13 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Uros Bizjak <u...@gcc.gnu.org>:

https://gcc.gnu.org/g:de05e44b2ad9638d04173393b1eae3c38b2c3864

commit r15-1113-gde05e44b2ad9638d04173393b1eae3c38b2c3864
Author: Uros Bizjak <ubiz...@gmail.com>
Date:   Sat Jun 8 12:17:11 2024 +0200

    i386: Implement .SAT_ADD for unsigned scalar integers [PR112600]

    The following testcase:

    unsigned
    add_sat(unsigned x, unsigned y)
    {
        unsigned z;
        return __builtin_add_overflow(x, y, &z) ? -1u : z;
    }

    currently compiles (-O2) to:

    add_sat:
            addl    %esi, %edi
            jc      .L3
            movl    %edi, %eax
            ret
    .L3:
            orl     $-1, %eax
            ret

    We can expand through usadd{m}3 optab to use carry flag from the addition
    and generate branchless code using SBB instruction implementing:

        unsigned res = x + y;
        res |= -(res < x);

    add_sat:
            addl    %esi, %edi
            sbbl    %eax, %eax
            orl     %edi, %eax
            ret

            PR target/112600

    gcc/ChangeLog:

            * config/i386/i386.md (usadd<mode>3): New expander.
            (x86_mov<mode>cc_0_m1_neg): Use SWI mode iterator.

    gcc/testsuite/ChangeLog:

            * gcc.target/i386/pr112600-a.c: New test.

Reply via email to