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

           Summary: Multiple setting to restricted pointer variable not
                    optimized away
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: normal
          Priority: P3
         Component: middle-end
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: bur...@gcc.gnu.org


Missed optimization: In the following program, the first "a = 1" line can be
removed - as the setting is not used and the value is latter overridden,
however, the line remains even with -O3.


function foo (a, b, c, ptr)
 real :: a, b, c, foo
 real, pointer :: ptr

 a = 1 ! Can delete
 b = ptr + 2
 a = 3

 foo = a + b
end function


>From the -O3 dump:

foo (real(kind=4) & restrict a, real(kind=4) & restrict b, real(kind=4) &
restrict c, real(kind=4) * & ptr)
{ [...]
  *a_1(D) = 1.0e+0;  /* Expected: This line is removed.  */
[...]
  *a_1(D) = 3.0e+0;


The same result is obtained for the equivalent C program:

float
foo (float * restrict a, float * restrict b, float * restrict c, float *ptr)
{
 *a = 1; /* Can delete.  */
 *b = *ptr + 2;
 *a = 3;

 return *a + *b;
}


Reported in by Daniel Carrera at
http://groups.google.com/group/comp.lang.fortran/browse_thread/thread/ec8641acbcbbed10/fdc9369d5acf53f1#fdc9369d5acf53f1

Reply via email to