public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* Re: optimization/6854: missed optimization with attribute const & pure
@ 2002-06-19  2:16 ghazi
  0 siblings, 0 replies; 2+ messages in thread
From: ghazi @ 2002-06-19  2:16 UTC (permalink / raw)
  To: gcc-bugs, gcc-prs, ghazi, nobody

Synopsis: missed optimization with attribute const & pure

State-Changed-From-To: open->closed
State-Changed-By: ghazi
State-Changed-When: Tue Jun 18 18:16:59 2002
State-Changed-Why:
    fixed
    http://gcc.gnu.org/ml/gcc-patches/2002-06/msg00049.html

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=6854


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

* optimization/6854: missed optimization with attribute const & pure
@ 2002-05-28 20:36 ghazi
  0 siblings, 0 replies; 2+ messages in thread
From: ghazi @ 2002-05-28 20:36 UTC (permalink / raw)
  To: gcc-gnats


>Number:         6854
>Category:       optimization
>Synopsis:       missed optimization with attribute const & pure
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          pessimizes-code
>Submitter-Id:   net
>Arrival-Date:   Tue May 28 18:56:00 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     Kaveh Ghazi
>Release:        gcc version 3.2 20020527 (experimental)
>Organization:
>Environment:
Probably all, but known to occur on at least:
sparc-sun-solaris2.7
mips-sgi-irix6.2
and judging by the testresults:
http://gcc.gnu.org/ml/gcc-testresults/2002-05/msg00989.html
http://gcc.gnu.org/ml/gcc-testresults/2002-05/msg00980.html
http://gcc.gnu.org/ml/gcc-testresults/2002-05/msg00967.html
it also occurs on i686, ia64 and alpha.
>Description:
Using the current 3.2 trunk, gcc fails to optimize several sections in the testcase attached.  It's also installed as:
gcc.c-torture/execute/pure-1.c

The testcase is designed to emit link errors when the optimizations fail to occur.  When I compile it (e.g. with -O/-O2) I get:

Undefined                       first referenced
 symbol                             in file
link_error4                         /var/tmp//cci2nHoc.o
link_error5                         /var/tmp//cci2nHoc.o
link_error6                         /var/tmp//cci2nHoc.o
link_error7                         /var/tmp//cci2nHoc.o

As noted by the particular optimizing failures, this appears to relate to the inability of gcc to detect as pure or const a function which contain calls to other const/pure functions.

NOTE: gcc-3.1.1-pre and 3.0.3 fail on 2, 4 and 6 so the appearance of link_error 5 & 7 represents a regression.  While the disappearance of 2 is a (slight) improvement.

See: http://gcc.gnu.org/ml/gcc-patches/2002-05/msg02137.html

>How-To-Repeat:
Compile the attached testcase with -O
>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: text/plain; name="pure-1.c"
Content-Disposition: inline; filename="pure-1.c"

/* Origin: Kaveh Ghazi <ghazi@caip.rutgers.edu> 2002-05-27.  */

/* Use a different function for each test so the link failures
   indicate which one is broken.  */
extern void link_error0 (void);
extern void link_error1 (void);
extern void link_error2 (void);
extern void link_error3 (void);
extern void link_error4 (void);
extern void link_error5 (void);
extern void link_error6 (void);
extern void link_error7 (void);

extern int i;

extern int func0 (int) __attribute__ ((__pure__));
extern int func1 (int) __attribute__ ((__const__));
/* GCC should automatically detect attributes for these functions.
   Don't allow -O3 to inline them.  */
#define ANI __attribute__ ((__noinline__))
static int ANI func2 (int a) { return i + a; } /* pure */
static int ANI func3 (int a) { return a * 3; } /* const */
static int ANI func4 (int a) { return func0(a) + a; } /* pure */
static int ANI func5 (int a) { return a + func1(a); } /* const */
static int ANI func6 (int a) { return func2(a) + a; } /* pure */
static int ANI func7 (int a) { return a + func3(a); } /* const */

int main ()
{
  int i[10], r;

  i[0] = 0;
  r = func0(0);
  if (i[0])
    link_error0();

  i[1] = 0;
  r = func1(0);
  if (i[1])
    link_error1();

  i[2] = 0;
  r = func2(0);
  if (i[2])
    link_error2();

  i[3] = 0;
  r = func3(0);
  if (i[3])
    link_error3();

  i[4] = 0;
  r = func4(0);
  if (i[4])
    link_error4();

  i[5] = 0;
  r = func5(0);
  if (i[5])
    link_error5();

  i[6] = 0;
  r = func6(0);
  if (i[6])
    link_error6();

  i[7] = 0;
  r = func7(0);
  if (i[7])
    link_error7();

  return r;
}

int func0 (int a) { return a - i; } /* pure */
int func1 (int a) { return a - a; } /* const */

int i = 2;

#ifndef __OPTIMIZE__
/* Avoid link failures when not optimizing. */
void link_error0() {}
void link_error1() {}
void link_error2() {}
void link_error3() {}
void link_error4() {}
void link_error5() {}
void link_error6() {}
void link_error7() {}
#endif /* ! __OPTIMIZE__ */


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

end of thread, other threads:[~2002-06-19  1:17 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-06-19  2:16 optimization/6854: missed optimization with attribute const & pure ghazi
  -- strict thread matches above, loose matches on Subject: below --
2002-05-28 20:36 ghazi

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).