public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/108873] New: Using the C++ front-end causes no DCE from happening
@ 2023-02-21 16:27 pinskia at gcc dot gnu.org
  2023-02-21 16:34 ` [Bug c++/108873] " pinskia at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-02-21 16:27 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 108873
           Summary: Using the C++ front-end causes no DCE from happening
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: enhancement
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pinskia at gcc dot gnu.org
                CC: amacleod at redhat dot com, dimhen at gmail dot com,
                    theodort at inf dot ethz.ch, unassigned at gcc dot gnu.org,
                    yinyuefengyi at gmail dot com
        Depends on: 105833
  Target Milestone: ---

+++ This bug was initially created as a clone of Bug #105833 +++
Testcase from #105833
```
void foo();

static int b;
static int **c;
static int ***d = &c;
static int ****e = &d;

static char(a)(char g, int h) { return h >= 2 ? g : g << h; }

int main() {
  **e == 0;
  b = b ? 4 : 0;
  if (!a(*e != 0, b))
    foo();
}
```
For some reason (I Have not done any anlysis of why), using the C++ front-end
with the above does not get optimized by does when using the C front-end.
This does not seem like a regression either.


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105833
[Bug 105833] [13 Regression] Dead Code Elimination Regression at -O2 (trunk vs.
12.1.0)

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

* [Bug c++/108873] Using the C++ front-end causes no DCE from happening
  2023-02-21 16:27 [Bug tree-optimization/108873] New: Using the C++ front-end causes no DCE from happening pinskia at gcc dot gnu.org
@ 2023-02-21 16:34 ` pinskia at gcc dot gnu.org
  2023-02-21 19:05 ` jakub at gcc dot gnu.org
  2023-02-21 19:16 ` pinskia at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-02-21 16:34 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|tree-optimization           |c++

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
For the C++ front-end:
The statement/expression:
**e == 0;
Is not emitted to the gimple, meaning the following statements are not added:
    e.0_1 = e;
    _2 = *e.0_1;
    _3 = *_2;

Which means evpr does see the above and then optimizing:
  _8 = _2 != 0B;

as _2 cannot be a null ptr.

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

* [Bug c++/108873] Using the C++ front-end causes no DCE from happening
  2023-02-21 16:27 [Bug tree-optimization/108873] New: Using the C++ front-end causes no DCE from happening pinskia at gcc dot gnu.org
  2023-02-21 16:34 ` [Bug c++/108873] " pinskia at gcc dot gnu.org
@ 2023-02-21 19:05 ` jakub at gcc dot gnu.org
  2023-02-21 19:16 ` pinskia at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: jakub at gcc dot gnu.org @ 2023-02-21 19:05 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

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

--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Well, it doesn't have side-effects, so why would it be emitted?
convert_to_void has:
1655      if (! TREE_SIDE_EFFECTS (expr))
1656        expr = void_node;

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

* [Bug c++/108873] Using the C++ front-end causes no DCE from happening
  2023-02-21 16:27 [Bug tree-optimization/108873] New: Using the C++ front-end causes no DCE from happening pinskia at gcc dot gnu.org
  2023-02-21 16:34 ` [Bug c++/108873] " pinskia at gcc dot gnu.org
  2023-02-21 19:05 ` jakub at gcc dot gnu.org
@ 2023-02-21 19:16 ` pinskia at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-02-21 19:16 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Jakub Jelinek from comment #2)
> Well, it doesn't have side-effects, so why would it be emitted?

Even though the side effect of deferencing here can be optimized away, VRP can
notice that *e will be non-null after the statement happens and then later on
optimize the "*e != 0" expression to being always true.
I am not saying this is an important testcase to optimize but we are starting
to get some of these testcases where doing early DCE of unused expressions will
not do other optimizations regression testcases too ...

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

end of thread, other threads:[~2023-02-21 19:16 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-21 16:27 [Bug tree-optimization/108873] New: Using the C++ front-end causes no DCE from happening pinskia at gcc dot gnu.org
2023-02-21 16:34 ` [Bug c++/108873] " pinskia at gcc dot gnu.org
2023-02-21 19:05 ` jakub at gcc dot gnu.org
2023-02-21 19:16 ` pinskia 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).