public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/100685] New: #pragma GCC push_options ineffective for optimize options
@ 2021-05-19 16:58 msebor at gcc dot gnu.org
  2021-05-20  6:37 ` [Bug middle-end/100685] " rguenth at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: msebor at gcc dot gnu.org @ 2021-05-19 16:58 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 100685
           Summary: #pragma GCC push_options ineffective for optimize
                    options
           Product: gcc
           Version: 11.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

The #pragma GCC push_options in the program below should prevent the folding of
the strlen() call in g() but doesn't.  This has changed in GCC 11 (GCC 10
behaves as expected).  The dump shows that the optimize attribute has both
optimization options, -O1 as well as -O2.  That also seems unexpected but it
has not changed between 10 and 11.

$ cat a.c && gcc -O0 -S -Wall -fdump-tree-optimized=/dev/stdout a.c
#pragma GCC optimize ("2")

int f (void)
{
  const char s[] = "12";
  return __builtin_strlen (s);   // folded to 1 (good)
}

#pragma GCC push_options
#pragma GCC optimize ("1")

int g (void)
{
  const char s[] = "1";
  return __builtin_strlen (s);   // also folded but shouldn't be
}

;; Function f (f, funcdef_no=0, decl_uid=1943, cgraph_uid=1, symbol_order=0)

__attribute__((optimize ("2")))
int f ()
{
  <bb 2> [local count: 1073741824]:
  return 2;

}



;; Function g (g, funcdef_no=1, decl_uid=1947, cgraph_uid=2, symbol_order=1)

__attribute__((optimize ("2", "1")))
int g ()
{
  <bb 2> [local count: 1073741824]:
  return 1;

}

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

* [Bug middle-end/100685] #pragma GCC push_options ineffective for optimize options
  2021-05-19 16:58 [Bug middle-end/100685] New: #pragma GCC push_options ineffective for optimize options msebor at gcc dot gnu.org
@ 2021-05-20  6:37 ` rguenth at gcc dot gnu.org
  2021-05-20  7:54 ` marxin at gcc dot gnu.org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-05-20  6:37 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
IIRC we changed behavior so that optimize appends to the global options,
thus optimize("no-tree-pre") gives you -O2 -fno-tree-pre instead of
-O0 -fno-tree-pre.

But -O2 -O1 should still get you -O1 and thus the same as -O1 stand-alone.
So sth is broken it seems?

push_options simply haves the old state for restore, it does not stash
away previous applied options.

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

* [Bug middle-end/100685] #pragma GCC push_options ineffective for optimize options
  2021-05-19 16:58 [Bug middle-end/100685] New: #pragma GCC push_options ineffective for optimize options msebor at gcc dot gnu.org
  2021-05-20  6:37 ` [Bug middle-end/100685] " rguenth at gcc dot gnu.org
@ 2021-05-20  7:54 ` marxin at gcc dot gnu.org
  2021-06-01 14:24 ` marxin at gcc dot gnu.org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: marxin at gcc dot gnu.org @ 2021-05-20  7:54 UTC (permalink / raw)
  To: gcc-bugs

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

Martin Liška <marxin at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at gcc dot gnu.org      |marxin at gcc dot gnu.org
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |ASSIGNED
   Last reconfirmed|                            |2021-05-20

--- Comment #2 from Martin Liška <marxin at gcc dot gnu.org> ---
(In reply to Richard Biener from comment #1)
> IIRC we changed behavior so that optimize appends to the global options,
> thus optimize("no-tree-pre") gives you -O2 -fno-tree-pre instead of
> -O0 -fno-tree-pre.

Not yet, the patch was sent but then I decided to postpone it for GCC 12.

> 
> But -O2 -O1 should still get you -O1 and thus the same as -O1 stand-alone.
> So sth is broken it seems?
> 
> push_options simply haves the old state for restore, it does not stash
> away previous applied options.

I'll investigate what has changed in GCC 11.

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

* [Bug middle-end/100685] #pragma GCC push_options ineffective for optimize options
  2021-05-19 16:58 [Bug middle-end/100685] New: #pragma GCC push_options ineffective for optimize options msebor at gcc dot gnu.org
  2021-05-20  6:37 ` [Bug middle-end/100685] " rguenth at gcc dot gnu.org
  2021-05-20  7:54 ` marxin at gcc dot gnu.org
@ 2021-06-01 14:24 ` marxin at gcc dot gnu.org
  2021-06-01 20:24 ` msebor at gcc dot gnu.org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: marxin at gcc dot gnu.org @ 2021-06-01 14:24 UTC (permalink / raw)
  To: gcc-bugs

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

Martin Liška <marxin at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |INVALID
             Status|ASSIGNED                    |RESOLVED

--- Comment #3 from Martin Liška <marxin at gcc dot gnu.org> ---
(In reply to Martin Sebor from comment #0)
> The #pragma GCC push_options in the program below should prevent the folding
> of the strlen() call in g() but doesn't.  This has changed in GCC 11 (GCC 10
> behaves as expected).  The dump shows that the optimize attribute has both
> optimization options, -O1 as well as -O2.  That also seems unexpected but it
> has not changed between 10 and 11.

There's a change that caused that:

r11-6922-gefc9ccbfd0ca4da6(27 Jan 2021 10:08)(jakub@redhat.com): [took: 0.596s]
result: FAILED (1)
varpool: Restore GENERIC TREE_READONLY automatic var optimization [PR7260]

In 4.8 and earlier we used to fold the following to 0 during GENERIC folding,
but we don't do that anymore because ctor_for_folding etc. has been turned into
a
GIMPLE centric API, but as the testcase shows, it is invoked even during
GENERIC folding and there the automatic vars still should have meaningful
initializers.  I've verified that the C++ FE drops TREE_READONLY on
automatic vars with const qualified types if they require non-constant
(runtime) initialization.

2021-01-27  Jakub Jelinek  <jakub@redhat.com>

        PR tree-optimization/97260
        * varpool.c: Include tree-pass.h.
        (ctor_for_folding): In GENERIC return DECL_INITIAL for TREE_READONLY
        non-TREE_SIDE_EFFECTS automatic variables.

        * gcc.dg/tree-ssa/pr97260.c: New test.

So the code snippet is optimized out even with -O1. So you should use:
#pragma GCC optimize ("0")

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

* [Bug middle-end/100685] #pragma GCC push_options ineffective for optimize options
  2021-05-19 16:58 [Bug middle-end/100685] New: #pragma GCC push_options ineffective for optimize options msebor at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2021-06-01 14:24 ` marxin at gcc dot gnu.org
@ 2021-06-01 20:24 ` msebor at gcc dot gnu.org
  2021-07-01 13:22 ` marxin at gcc dot gnu.org
  2021-07-01 14:47 ` msebor at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: msebor at gcc dot gnu.org @ 2021-06-01 20:24 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Martin Sebor <msebor at gcc dot gnu.org> ---
Thanks.  I belatedly realized that the test case didn't reproduce the problem I
was seeing.  The one below demonstrates that the -O1 option does override the
-O2 set earlier.  Sorry for the noise!

$ cat pr100685.c && gcc -O2 -S -Wall -fdump-tree-optimized=/dev/stdout
pr100685.c
#pragma GCC optimize ("2")

int f (void)
{
  char s[] = "abc";
  return __builtin_strlen (s);   // folded to 3 (good)
}

#pragma GCC push_options
#pragma GCC optimize ("1")

int g (void)
{
  char s[] = "abc";
  return __builtin_strlen (s);   // not folded and shouldn't be
}

;; Function f (f, funcdef_no=0, decl_uid=1943, cgraph_uid=1, symbol_order=0)

__attribute__((optimize ("2")))
int f ()
{
  <bb 2> [local count: 1073741824]:
  return 3;

}



;; Function g (g, funcdef_no=1, decl_uid=1947, cgraph_uid=2, symbol_order=1)

__attribute__((optimize ("2", "1")))
int g ()
{
  char s[4];
  long unsigned int _1;
  int _4;

  <bb 2> [local count: 1073741824]:
  s = "abc";
  _1 = __builtin_strlen (&s);
  _4 = (int) _1;
  s ={v} {CLOBBER};
  return _4;

}

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

* [Bug middle-end/100685] #pragma GCC push_options ineffective for optimize options
  2021-05-19 16:58 [Bug middle-end/100685] New: #pragma GCC push_options ineffective for optimize options msebor at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2021-06-01 20:24 ` msebor at gcc dot gnu.org
@ 2021-07-01 13:22 ` marxin at gcc dot gnu.org
  2021-07-01 14:47 ` msebor at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: marxin at gcc dot gnu.org @ 2021-07-01 13:22 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Martin Liška <marxin at gcc dot gnu.org> ---
Good. So all is fine, right?

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

* [Bug middle-end/100685] #pragma GCC push_options ineffective for optimize options
  2021-05-19 16:58 [Bug middle-end/100685] New: #pragma GCC push_options ineffective for optimize options msebor at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2021-07-01 13:22 ` marxin at gcc dot gnu.org
@ 2021-07-01 14:47 ` msebor at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: msebor at gcc dot gnu.org @ 2021-07-01 14:47 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Martin Sebor <msebor at gcc dot gnu.org> ---
Yes, thanks.

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

end of thread, other threads:[~2021-07-01 14:47 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-19 16:58 [Bug middle-end/100685] New: #pragma GCC push_options ineffective for optimize options msebor at gcc dot gnu.org
2021-05-20  6:37 ` [Bug middle-end/100685] " rguenth at gcc dot gnu.org
2021-05-20  7:54 ` marxin at gcc dot gnu.org
2021-06-01 14:24 ` marxin at gcc dot gnu.org
2021-06-01 20:24 ` msebor at gcc dot gnu.org
2021-07-01 13:22 ` marxin at gcc dot gnu.org
2021-07-01 14:47 ` msebor 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).