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/36020] New: shift operator strength reduction in loops not done.


Consider this simple loop:

int shift_integer (int value, unsigned int amount)
{
  unsigned int i;

  for (i=0; i<amount; i++)
   value<<=1;

  return value;
}

The compiler generates aloop to evalue the result and does not strength-reduce
the calculation.

A slightly different version of that loop gets strength-reduced. I just
replaced the shift with an add.

int inc_integer (int value, unsigned int amount)
{
  unsigned int i;

  for (i=0; i<amount; i++)
   value+=1;

  return value;
}

Tested with gcc 4.3.0 i686-pc-cygwin. 

Assembly-Output with -O3 -fomit-frame-pointer:

        .file   "test.c"
        .text
        .p2align 4,,15
.globl _shift_integer
        .def    _shift_integer; .scl    2;      .type   32;     .endef
_shift_integer:
        movl    8(%esp), %ecx
        movl    4(%esp), %eax
        testl   %ecx, %ecx
        je      L2
        xorl    %edx, %edx
        .p2align 4,,7
L3:
        addl    $1, %edx
        addl    %eax, %eax
        cmpl    %edx, %ecx
        ja      L3
L2:
        rep
        ret
        .p2align 4,,15
.globl _inc_integer
        .def    _inc_integer;   .scl    2;      .type   32;     .endef
_inc_integer:
        movl    8(%esp), %edx
        movl    4(%esp), %eax
        testl   %edx, %edx      
        je      L8             
        addl    %edx, %eax
L8:
        rep
        ret


-- 
           Summary: shift operator strength reduction in loops not done.
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: tree-optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: n dot pipenbrinck at cubic dot org


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


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