public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/106570] New: DCE sometimes fails with depending if statements
@ 2022-08-09 11:35 tmayerl at student dot ethz.ch
  2022-08-09 13:15 ` [Bug tree-optimization/106570] [12/13 Regression] DCE sometimes fails with depending if statements since r12-2305-g398572c1544d8b75 marxin at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: tmayerl at student dot ethz.ch @ 2022-08-09 11:35 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 106570
           Summary: DCE sometimes fails with depending if statements
           Product: gcc
           Version: 12.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: tmayerl at student dot ethz.ch
  Target Milestone: ---

Sometimes, DCE fails when multiple if statements are used. 

For example, GCC detects that the following if statements always evaluate to
false and thus removes the dead code:

#include <stdio.h>
#include <stdbool.h>

void DCEMarker0_();

void f(bool s, bool c) {
    if (!c == !s) {
        if (s && !c) {
            DCEMarker0_();
        }
    }
}

In the next snippet, the if statements are used to set a variable. This
variable is then used in the next if statement. However, GCC now fails to
detect and eliminate the dead code:

#include <stdio.h>
#include <stdbool.h>

void DCEMarker0_();

void f(bool s, bool c) {
    int intermediate_result = 0;
    if (!c == !s) {
        if (s && !c) {
            intermediate_result = 1;
        }
    }
    if (((!c == !s) && (s && !c)) || intermediate_result) {
        DCEMarker0_();
    }
}

This is actually a regression: It works fine until GCC 11.3.

This can also be seen via the following Compiler Explorer link:
https://godbolt.org/z/n9dKMfqsd

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

* [Bug tree-optimization/106570] [12/13 Regression] DCE sometimes fails with depending if statements since r12-2305-g398572c1544d8b75
  2022-08-09 11:35 [Bug tree-optimization/106570] New: DCE sometimes fails with depending if statements tmayerl at student dot ethz.ch
@ 2022-08-09 13:15 ` marxin at gcc dot gnu.org
  2022-08-09 13:28 ` amacleod at redhat dot com
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: marxin at gcc dot gnu.org @ 2022-08-09 13:15 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2022-08-09
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1
            Summary|DCE sometimes fails with    |[12/13 Regression] DCE
                   |depending if statements     |sometimes fails with
                   |                            |depending if statements
                   |                            |since
                   |                            |r12-2305-g398572c1544d8b75
                 CC|                            |aldyh at gcc dot gnu.org,
                   |                            |amacleod at redhat dot com,
                   |                            |marxin at gcc dot gnu.org

--- Comment #1 from Martin Liška <marxin at gcc dot gnu.org> ---
Started with r12-2305-g398572c1544d8b75.

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

* [Bug tree-optimization/106570] [12/13 Regression] DCE sometimes fails with depending if statements since r12-2305-g398572c1544d8b75
  2022-08-09 11:35 [Bug tree-optimization/106570] New: DCE sometimes fails with depending if statements tmayerl at student dot ethz.ch
  2022-08-09 13:15 ` [Bug tree-optimization/106570] [12/13 Regression] DCE sometimes fails with depending if statements since r12-2305-g398572c1544d8b75 marxin at gcc dot gnu.org
@ 2022-08-09 13:28 ` amacleod at redhat dot com
  2022-08-09 13:48 ` rguenth at gcc dot gnu.org
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: amacleod at redhat dot com @ 2022-08-09 13:28 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Andrew Macleod <amacleod at redhat dot com> ---
I think this is a duplicate of PR106379 .   At the VRP2 stage I see:

  <bb 2> [local count: 1073741824]:
  if (c_6(D) == s_7(D))
    goto <bb 3>; [34.00%]
  else
    goto <bb 5>; [66.00%]

  <bb 3> [local count: 365072224]:
  _1 = ~c_6(D);
  _2 = _1 & s_7(D);
  if (_2 != 0)
    goto <bb 4>; [75.00%]
  else
    goto <bb 5>; [25.00%]

  <bb 4> [local count: 628138969]:
  DCEMarker0_ ();

  <bb 5> [local count: 1073741824]:
  return;

Which is basically the identical sequence.. it just took longer to get to it
:-)  We aren't removing this yet with ranger as I need to get to integrate
rangers relation oracle with the simplifier so that it will see that  _2 = ~s_7
& s_7.

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

* [Bug tree-optimization/106570] [12/13 Regression] DCE sometimes fails with depending if statements since r12-2305-g398572c1544d8b75
  2022-08-09 11:35 [Bug tree-optimization/106570] New: DCE sometimes fails with depending if statements tmayerl at student dot ethz.ch
  2022-08-09 13:15 ` [Bug tree-optimization/106570] [12/13 Regression] DCE sometimes fails with depending if statements since r12-2305-g398572c1544d8b75 marxin at gcc dot gnu.org
  2022-08-09 13:28 ` amacleod at redhat dot com
@ 2022-08-09 13:48 ` rguenth at gcc dot gnu.org
  2022-08-10 13:53 ` rguenth at gcc dot gnu.org
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-08-09 13:48 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |12.2

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

* [Bug tree-optimization/106570] [12/13 Regression] DCE sometimes fails with depending if statements since r12-2305-g398572c1544d8b75
  2022-08-09 11:35 [Bug tree-optimization/106570] New: DCE sometimes fails with depending if statements tmayerl at student dot ethz.ch
                   ` (2 preceding siblings ...)
  2022-08-09 13:48 ` rguenth at gcc dot gnu.org
@ 2022-08-10 13:53 ` rguenth at gcc dot gnu.org
  2023-03-11 17:07 ` pinskia at gcc dot gnu.org
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-08-10 13:53 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |missed-optimization
           Priority|P3                          |P2

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

* [Bug tree-optimization/106570] [12/13 Regression] DCE sometimes fails with depending if statements since r12-2305-g398572c1544d8b75
  2022-08-09 11:35 [Bug tree-optimization/106570] New: DCE sometimes fails with depending if statements tmayerl at student dot ethz.ch
                   ` (3 preceding siblings ...)
  2022-08-10 13:53 ` rguenth at gcc dot gnu.org
@ 2023-03-11 17:07 ` pinskia at gcc dot gnu.org
  2023-03-14 13:16 ` marxin at gcc dot gnu.org
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-03-11 17:07 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |needs-bisection
      Known to fail|                            |12.1.0
      Known to work|                            |11.1.0

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Note on the trunk, now the first example fails at -O2 and not just -O3. It
might be useful to do a bisect there too.

The second example failed for -O2 for GCC 12 too.

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

* [Bug tree-optimization/106570] [12/13 Regression] DCE sometimes fails with depending if statements since r12-2305-g398572c1544d8b75
  2022-08-09 11:35 [Bug tree-optimization/106570] New: DCE sometimes fails with depending if statements tmayerl at student dot ethz.ch
                   ` (4 preceding siblings ...)
  2023-03-11 17:07 ` pinskia at gcc dot gnu.org
@ 2023-03-14 13:16 ` marxin at gcc dot gnu.org
  2023-05-08 12:25 ` [Bug tree-optimization/106570] [12/13/14 " rguenth at gcc dot gnu.org
  2023-07-13 18:38 ` pinskia at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: marxin at gcc dot gnu.org @ 2023-03-14 13:16 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|needs-bisection             |

--- Comment #5 from Martin Liška <marxin at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #4)
> Note on the trunk, now the first example fails at -O2 and not just -O3. It
> might be useful to do a bisect there too.

That started with r13-3596-ge7310e24b1c0ca67.

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

* [Bug tree-optimization/106570] [12/13/14 Regression] DCE sometimes fails with depending if statements since r12-2305-g398572c1544d8b75
  2022-08-09 11:35 [Bug tree-optimization/106570] New: DCE sometimes fails with depending if statements tmayerl at student dot ethz.ch
                   ` (5 preceding siblings ...)
  2023-03-14 13:16 ` marxin at gcc dot gnu.org
@ 2023-05-08 12:25 ` rguenth at gcc dot gnu.org
  2023-07-13 18:38 ` pinskia at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-05-08 12:25 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|12.3                        |12.4

--- Comment #6 from Richard Biener <rguenth at gcc dot gnu.org> ---
GCC 12.3 is being released, retargeting bugs to GCC 12.4.

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

* [Bug tree-optimization/106570] [12/13/14 Regression] DCE sometimes fails with depending if statements since r12-2305-g398572c1544d8b75
  2022-08-09 11:35 [Bug tree-optimization/106570] New: DCE sometimes fails with depending if statements tmayerl at student dot ethz.ch
                   ` (6 preceding siblings ...)
  2023-05-08 12:25 ` [Bug tree-optimization/106570] [12/13/14 " rguenth at gcc dot gnu.org
@ 2023-07-13 18:38 ` pinskia at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-07-13 18:38 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=107880

--- Comment #7 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
I suspect if we optimize:
 _1 = ~c_6(D);
  _2 = _1 & s_7(D);

to:
c < s;

VRP will just work now.

(that would be PR 107880 ).

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

end of thread, other threads:[~2023-07-13 18:38 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-09 11:35 [Bug tree-optimization/106570] New: DCE sometimes fails with depending if statements tmayerl at student dot ethz.ch
2022-08-09 13:15 ` [Bug tree-optimization/106570] [12/13 Regression] DCE sometimes fails with depending if statements since r12-2305-g398572c1544d8b75 marxin at gcc dot gnu.org
2022-08-09 13:28 ` amacleod at redhat dot com
2022-08-09 13:48 ` rguenth at gcc dot gnu.org
2022-08-10 13:53 ` rguenth at gcc dot gnu.org
2023-03-11 17:07 ` pinskia at gcc dot gnu.org
2023-03-14 13:16 ` marxin at gcc dot gnu.org
2023-05-08 12:25 ` [Bug tree-optimization/106570] [12/13/14 " rguenth at gcc dot gnu.org
2023-07-13 18:38 ` 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).