This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug tree-optimization/54579] New: missed optimization: ASR idiom


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

             Bug #: 54579
           Summary: missed optimization: ASR idiom
    Classification: Unclassified
           Product: gcc
           Version: 4.8.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: normal
          Priority: P3
         Component: tree-optimization
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: rearnsha@gcc.gnu.org


The idiom

int asr(int a, int b)
{
  return a < 0 ? -(-a - 1 >> b) - 1 : a >> b;
}

is equivalent to a portable form of arithmetic right shift.  However, at -O2
GCC currently generates something like

        cmp     r0, #0
        mvnlt   r0, r0
        mvnlt   r0, r0, asr r1
        movge   r0, r0, asr r1

on ARM, or

        testl   %edi, %edi
        movl    %esi, %ecx
        js      .L7
        movl    %edi, %eax
        sarl    %cl, %eax
        ret
        .p2align 4,,7
.L7:
        movl    %edi, %eax
        notl    %eax
        sarl    %cl, %eax
        notl    %eax
        ret

on x86.

On ARM this should just be:

        asr r0, r0, r1


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]