public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/48390] New: Multiple setting to restricted pointer variable not optimized away
@ 2011-03-31 16:37 burnus at gcc dot gnu.org
  2011-03-31 16:49 ` [Bug middle-end/48390] " burnus at gcc dot gnu.org
  2015-09-29  8:03 ` vries at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: burnus at gcc dot gnu.org @ 2011-03-31 16:37 UTC (permalink / raw)
  To: gcc-bugs

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: unassigned@gcc.gnu.org
        ReportedBy: burnus@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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug middle-end/48390] Multiple setting to restricted pointer variable not optimized away
  2011-03-31 16:37 [Bug middle-end/48390] New: Multiple setting to restricted pointer variable not optimized away burnus at gcc dot gnu.org
@ 2011-03-31 16:49 ` burnus at gcc dot gnu.org
  2015-09-29  8:03 ` vries at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: burnus at gcc dot gnu.org @ 2011-03-31 16:49 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Tobias Burnus <burnus at gcc dot gnu.org> 2011-03-31 16:15:56 UTC ---
For the C case: If "ptr" is also "restrict", the "*a = 1" is optimized away.
Ditto for Fortran, if "ptr" is not a POINTER but a normal variable.

In case of Fortran, the a/b/c cannot alias with ptr as none of has the TARGET
attribute. I would expect the same for C99 as a/b/c are "restrict" but maybe I
am wrong about the C99 semantics.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug middle-end/48390] Multiple setting to restricted pointer variable not optimized away
  2011-03-31 16:37 [Bug middle-end/48390] New: Multiple setting to restricted pointer variable not optimized away burnus at gcc dot gnu.org
  2011-03-31 16:49 ` [Bug middle-end/48390] " burnus at gcc dot gnu.org
@ 2015-09-29  8:03 ` vries at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: vries at gcc dot gnu.org @ 2015-09-29  8:03 UTC (permalink / raw)
  To: gcc-bugs

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

vries at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |vries at gcc dot gnu.org

--- Comment #2 from vries at gcc dot gnu.org ---
(In reply to Tobias Burnus from comment #0)
> 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;
> }
> 

This is supported in current trunk, and the dead store '*a = 1' is removed.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-09-29  8:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-03-31 16:37 [Bug middle-end/48390] New: Multiple setting to restricted pointer variable not optimized away burnus at gcc dot gnu.org
2011-03-31 16:49 ` [Bug middle-end/48390] " burnus at gcc dot gnu.org
2015-09-29  8:03 ` vries at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).