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

--- Comment #35 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Roger Sayle <[email protected]>:

https://gcc.gnu.org/g:850b5135e5ea7e64c7694a4a12c894a052696c1b

commit r17-5451-g850b5135e5ea7e64c7694a4a12c894a052696c1b
Author: Roger Sayle <[email protected]>
Date:   Wed Oct 21 13:17:43 2026 +0100

    combine: Missed any-or-plus optimization in make_field_assignment.

    This simple patch tweaks combine.cc to catch a missed-optimization
    identified by my recent any-or-plus changes.  Currently the logic
    in make_field_assignment checks for IOR or XOR, this one-line tweak
    adds PLUS to the list.

    The motivating example is taken from PR target/15184.

    On i386, for the code:

    unsigned int x;

    void foo(unsigned char c)
    {
        x = (x & 0xFFFFFF00) + (unsigned int)c;
    }

    current GCC (and earlier GCCs) with -m32 -O2 generates:

    foo:    movl    x, %eax
            movzbl  4(%esp), %edx
            xorb    %al, %al
            addl    %edx, %eax
            movl    %eax, x
            ret

    with this patch, we now generate:

    foo:    movzbl  4(%esp), %eax
            movb    %al, x
            ret

    which matches what we'd generate if the source code
    had used "|" or "^" as an operator.

    2026-10-21  Roger Sayle  <[email protected]>

    gcc/ChangeLog
            * combine.cc (make_field_assignment): Treat PLUS like IOR and XOR.

    gcc/testsuite/ChangeLog
            * gcc.target/i386/pr15184-3.c: New test case.

Reply via email to