public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/53875] New: calls to const functions are eliminated at -O0
@ 2012-07-06 14:09 James.H.McKim at nasa dot gov
  2012-07-09  8:42 ` [Bug c++/53875] " rguenth at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: James.H.McKim at nasa dot gov @ 2012-07-06 14:09 UTC (permalink / raw)
  To: gcc-bugs

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

             Bug #: 53875
           Summary: calls to const functions are eliminated at -O0
    Classification: Unclassified
           Product: gcc
           Version: 4.6.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: James.H.McKim@nasa.gov


Compiler version 4.6.3.
System: ubuntu 12.1

When source containing a call to a const function is compiled, that function's
invocation is always (regardless of -O level) eliminated if the returned result
is discarded. That action is an optimization, and when no optimization is
specified, having it happen is surprising.

If the compiler is intended to always eliminate, it would be helpful if there
was a diagnostic indicating the elimination. For instance, instead of the
warning "statement has no effect", maybe "statement has no effect,
eliminating".


The code was compiled with the command:

g++ -O0 -S -o t1b.lst t1b.cxx


The example code (t1b.cxx):

extern int pthread_self (void) __attribute__ ((__const__));

int main() {

  // Demonstrate the compiler doesn't emit this call.
  pthread_self();

  // A workaround.
  // volatile int x = pthread_self();

  return 0;
}


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

* [Bug c++/53875] calls to const functions are eliminated at -O0
  2012-07-06 14:09 [Bug c++/53875] New: calls to const functions are eliminated at -O0 James.H.McKim at nasa dot gov
@ 2012-07-09  8:42 ` rguenth at gcc dot gnu.org
  2021-07-22 18:47 ` [Bug middle-end/53875] " pinskia at gcc dot gnu.org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: rguenth at gcc dot gnu.org @ 2012-07-09  8:42 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Guenther <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2012-07-09
     Ever Confirmed|0                           |1

--- Comment #1 from Richard Guenther <rguenth at gcc dot gnu.org> 2012-07-09 08:42:26 UTC ---
Confirmed.  We generally do very many "small" optimizations at -O0 that would
surprise users.  we probably should not.


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

* [Bug middle-end/53875] calls to const functions are eliminated at -O0
  2012-07-06 14:09 [Bug c++/53875] New: calls to const functions are eliminated at -O0 James.H.McKim at nasa dot gov
  2012-07-09  8:42 ` [Bug c++/53875] " rguenth at gcc dot gnu.org
@ 2021-07-22 18:47 ` pinskia at gcc dot gnu.org
  2021-11-29  2:53 ` pinskia at gcc dot gnu.org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-07-22 18:47 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|c++                         |middle-end

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
This even happens in C.
It happens during expand phase:
;; Generating RTL for gimple basic block 2

;; pthread_self ();

(nil)

Maybe at -O0 or -Og, during expand we still expand the call ...

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

* [Bug middle-end/53875] calls to const functions are eliminated at -O0
  2012-07-06 14:09 [Bug c++/53875] New: calls to const functions are eliminated at -O0 James.H.McKim at nasa dot gov
  2012-07-09  8:42 ` [Bug c++/53875] " rguenth at gcc dot gnu.org
  2021-07-22 18:47 ` [Bug middle-end/53875] " pinskia at gcc dot gnu.org
@ 2021-11-29  2:53 ` pinskia at gcc dot gnu.org
  2021-11-29  2:56 ` pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-11-29  2:53 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to work|                            |3.3.3
      Known to fail|                            |3.4.0

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
The code which introduced this was g:8c6a82695b85f8ed74cdc67f2cf74c5a62d0d91d .

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

* [Bug middle-end/53875] calls to const functions are eliminated at -O0
  2012-07-06 14:09 [Bug c++/53875] New: calls to const functions are eliminated at -O0 James.H.McKim at nasa dot gov
                   ` (2 preceding siblings ...)
  2021-11-29  2:53 ` pinskia at gcc dot gnu.org
@ 2021-11-29  2:56 ` pinskia at gcc dot gnu.org
  2021-11-29  3:00 ` pinskia at gcc dot gnu.org
  2021-11-29 11:31 ` roger at nextmovesoftware dot com
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-11-29  2:56 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #3)
> The code which introduced this was
> g:8c6a82695b85f8ed74cdc67f2cf74c5a62d0d91d .

https://gcc.gnu.org/pipermail/gcc-patches/2003-May/104797.html

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

* [Bug middle-end/53875] calls to const functions are eliminated at -O0
  2012-07-06 14:09 [Bug c++/53875] New: calls to const functions are eliminated at -O0 James.H.McKim at nasa dot gov
                   ` (3 preceding siblings ...)
  2021-11-29  2:56 ` pinskia at gcc dot gnu.org
@ 2021-11-29  3:00 ` pinskia at gcc dot gnu.org
  2021-11-29 11:31 ` roger at nextmovesoftware dot com
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-11-29  3:00 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |roger at nextmovesoftware dot com

--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
diff --git a/gcc/calls.c b/gcc/calls.c
index 27b59f26ad3..f23dde58671 100644
--- a/gcc/calls.c
+++ b/gcc/calls.c
@@ -2735,7 +2735,8 @@ expand_call (tree exp, rtx target, int ignore)
       && (!(flags & ECF_LOOPING_CONST_OR_PURE))
       && (flags & ECF_NOTHROW)
       && (ignore || target == const0_rtx
-         || TYPE_MODE (rettype) == VOIDmode))
+         || TYPE_MODE (rettype) == VOIDmode)
+      && !optimize)
     {
       bool volatilep = false;
       tree arg;

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

* [Bug middle-end/53875] calls to const functions are eliminated at -O0
  2012-07-06 14:09 [Bug c++/53875] New: calls to const functions are eliminated at -O0 James.H.McKim at nasa dot gov
                   ` (4 preceding siblings ...)
  2021-11-29  3:00 ` pinskia at gcc dot gnu.org
@ 2021-11-29 11:31 ` roger at nextmovesoftware dot com
  5 siblings, 0 replies; 7+ messages in thread
From: roger at nextmovesoftware dot com @ 2021-11-29 11:31 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Roger Sayle <roger at nextmovesoftware dot com> ---
I believe this should be "... && optimize != 0", i.e. we want to eliminate
these calls (only) when optimizing.  But this seems like a reasonable
fix/feature request (to identify breakpoints at -O0).

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

end of thread, other threads:[~2021-11-29 11:31 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-07-06 14:09 [Bug c++/53875] New: calls to const functions are eliminated at -O0 James.H.McKim at nasa dot gov
2012-07-09  8:42 ` [Bug c++/53875] " rguenth at gcc dot gnu.org
2021-07-22 18:47 ` [Bug middle-end/53875] " pinskia at gcc dot gnu.org
2021-11-29  2:53 ` pinskia at gcc dot gnu.org
2021-11-29  2:56 ` pinskia at gcc dot gnu.org
2021-11-29  3:00 ` pinskia at gcc dot gnu.org
2021-11-29 11:31 ` roger at nextmovesoftware dot com

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