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

            Bug ID: 106701
           Summary: s390: Compiler does not take into account number range
                    limitation to avoid subtract from immediate
           Product: gcc
           Version: 11.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jens.seifert at de dot ibm.com
  Target Milestone: ---

unsigned long long subfic(unsigned long long a)
{
    if (a > 15) __builtin_unreachable();
    return 15 - a;
}

With clang on x86 subtract from immediate gets translated to xor:
_Z6subficy:                             # @_Z6subficy
        mov     rax, rdi
        xor     rax, 15
        ret

Platforms like 390 and x86 which have no subtract from immediate would benefit
from this optimization:

gcc currently generates:
_Z6subficy:
        lghi    %r1,15
        sgr     %r1,%r2
        lgr     %r2,%r1
        br      %r14

Reply via email to