public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/110538] New: [14 Regression] Dead Code Elimination Regression since  r14-368-ge1366a7e4ce
@ 2023-07-04  9:20 theodort at inf dot ethz.ch
  2023-07-05  6:43 ` [Bug tree-optimization/110538] " rguenth at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: theodort at inf dot ethz.ch @ 2023-07-04  9:20 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 110538
           Summary: [14 Regression] Dead Code Elimination Regression since
                     r14-368-ge1366a7e4ce
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: theodort at inf dot ethz.ch
  Target Milestone: ---

https://godbolt.org/z/53Ys78do1

Given the following code:

void foo(void);
static int b, d, f;
static int *c, *e = &d;
static unsigned g;
void a();
int main() {
    g = -19;
    for (; g; ++g) {
        int h = g;
        int *i = &b;
        int **j = &i;
        if (d) {
            int **k = &i;
            j = &c;
            *k = &f;
        } else
            *e = 0;
        if (!(((h) >= -19) && ((h) <= -1))) {
            __builtin_unreachable();
        }
        if (i)
            ;
        else
            a();
        if (j == &i || j == &c)
            ;
        else
            foo();
        ;
    }
}

gcc-trunk -O2 does not eliminate the call to foo:

main:
        subq    $24, %rsp
        movl    $-19, g(%rip)
        .p2align 4,,10
        .p2align 3
.L4:
        movl    d(%rip), %edx
        movl    $c, %eax
        testl   %edx, %edx
        jne     .L2
        leaq    8(%rsp), %rax
.L2:
        cmpq    $c, %rax
        je      .L5
        leaq    8(%rsp), %rdx
        cmpq    %rdx, %rax
        je      .L5
        call    foo
.L5:
        addl    $1, g(%rip)
        jne     .L4
        xorl    %eax, %eax
        addq    $24, %rsp
        ret

gcc-13.1.0 -O2 eliminates the call to foo:

main:
        movl    $-19, g(%rip)
        .p2align 4,,10
        .p2align 3
.L2:
        movl    g(%rip), %eax
        addl    $1, %eax
        movl    %eax, g(%rip)
        jne     .L2
        ret

Bisects to r14-368-ge1366a7e4ce

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

* [Bug tree-optimization/110538] [14 Regression] Dead Code Elimination Regression since  r14-368-ge1366a7e4ce
  2023-07-04  9:20 [Bug tree-optimization/110538] New: [14 Regression] Dead Code Elimination Regression since r14-368-ge1366a7e4ce theodort at inf dot ethz.ch
@ 2023-07-05  6:43 ` rguenth at gcc dot gnu.org
  2023-07-07  0:27 ` pinskia at gcc dot gnu.org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-07-05  6:43 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |14.0
           Keywords|                            |missed-optimization

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

* [Bug tree-optimization/110538] [14 Regression] Dead Code Elimination Regression since  r14-368-ge1366a7e4ce
  2023-07-04  9:20 [Bug tree-optimization/110538] New: [14 Regression] Dead Code Elimination Regression since r14-368-ge1366a7e4ce theodort at inf dot ethz.ch
  2023-07-05  6:43 ` [Bug tree-optimization/110538] " rguenth at gcc dot gnu.org
@ 2023-07-07  0:27 ` pinskia at gcc dot gnu.org
  2023-07-07  0:39 ` pinskia at gcc dot gnu.org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-07-07  0:27 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2023-07-07
             Status|UNCONFIRMED                 |NEW

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed.

In .optimized we get:
  # j_24 = PHI <&i(7), &c(3)>
  _2 = j_24 == &c;
  _22 = &i == j_24;
  _23 = _2 | _22;

Obvious _23 is always 1.

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

* [Bug tree-optimization/110538] [14 Regression] Dead Code Elimination Regression since  r14-368-ge1366a7e4ce
  2023-07-04  9:20 [Bug tree-optimization/110538] New: [14 Regression] Dead Code Elimination Regression since r14-368-ge1366a7e4ce theodort at inf dot ethz.ch
  2023-07-05  6:43 ` [Bug tree-optimization/110538] " rguenth at gcc dot gnu.org
  2023-07-07  0:27 ` pinskia at gcc dot gnu.org
@ 2023-07-07  0:39 ` pinskia at gcc dot gnu.org
  2024-03-08 15:28 ` law at gcc dot gnu.org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-07-07  0:39 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
So dom3 was able to optimize that via a jump threading before in GCC 13 but no
longer on the trunk (I don't understand why though).

Anyways the only pass which is able to optimize:
```
int f123(int a, int c, int i)
{
  int *d;
  if (a) d = &i; else d = &c;
  int e = d == &i;
  int f = d == &c;
  return e | f;
}
```
to `1` is PRE ...

But note
```
int g123();
int h123();
int f123_1(int a, int c, int i)
{
  int *d;
  if (a) d = &i; else d = &c;
  int e = d == &i;
  int f = d == &c;
  if (e | f)
    return h123();
  return g123();
}
```
Still can be optimized by dom2 on the trunk (via jump threading).

So how did dom3 miss the original testcase ....

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

* [Bug tree-optimization/110538] [14 Regression] Dead Code Elimination Regression since  r14-368-ge1366a7e4ce
  2023-07-04  9:20 [Bug tree-optimization/110538] New: [14 Regression] Dead Code Elimination Regression since r14-368-ge1366a7e4ce theodort at inf dot ethz.ch
                   ` (2 preceding siblings ...)
  2023-07-07  0:39 ` pinskia at gcc dot gnu.org
@ 2024-03-08 15:28 ` law at gcc dot gnu.org
  2024-03-09  7:13 ` law at gcc dot gnu.org
  2024-05-07  7:41 ` [Bug tree-optimization/110538] [14/15 " rguenth at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: law at gcc dot gnu.org @ 2024-03-08 15:28 UTC (permalink / raw)
  To: gcc-bugs

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

Jeffrey A. Law <law at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |law at gcc dot gnu.org
           Priority|P3                          |P2

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

* [Bug tree-optimization/110538] [14 Regression] Dead Code Elimination Regression since  r14-368-ge1366a7e4ce
  2023-07-04  9:20 [Bug tree-optimization/110538] New: [14 Regression] Dead Code Elimination Regression since r14-368-ge1366a7e4ce theodort at inf dot ethz.ch
                   ` (3 preceding siblings ...)
  2024-03-08 15:28 ` law at gcc dot gnu.org
@ 2024-03-09  7:13 ` law at gcc dot gnu.org
  2024-05-07  7:41 ` [Bug tree-optimization/110538] [14/15 " rguenth at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: law at gcc dot gnu.org @ 2024-03-09  7:13 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Jeffrey A. Law <law at gcc dot gnu.org> ---
Thread references removed edge:   Cancelling jump thread: (9, 10) incoming
edge;  (10, 8) joiner (8, 6) normal;

Thread references removed edge:   Cancelling jump thread: (2, 3) incoming edge;
 (3, 9) joiner (9, 10) nocopy (10, 8) normal;

Thread references removed edge:   Cancelling jump thread: (2, 3) incoming edge;
 (3, 10) joiner (10, 8) normal;

Thread references removed edge:   Cancelling jump thread: (3, 10) incoming
edge;  (10, 8) normal;

[ ... ]

Merging blocks 10 and 8
Removing basic block 11
;; basic block 11, loop depth 1
;;  pred:         
goto <bb 3>; [100.00%]
;;  succ:       3

So one of the edges in the jump threading path gets removed.  As a result the
threader throws the path away.  At least that's my best guess.

We could possibly defer block merging until after threading.  No idea how hard
that might be.  The sequencing is a bit painful, but IIRC the key is that we
must remove unreachables in the CFG before threading (due to how unreachables
interact with the dominator tree updates).

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

* [Bug tree-optimization/110538] [14/15 Regression] Dead Code Elimination Regression since  r14-368-ge1366a7e4ce
  2023-07-04  9:20 [Bug tree-optimization/110538] New: [14 Regression] Dead Code Elimination Regression since r14-368-ge1366a7e4ce theodort at inf dot ethz.ch
                   ` (4 preceding siblings ...)
  2024-03-09  7:13 ` law at gcc dot gnu.org
@ 2024-05-07  7:41 ` rguenth at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: rguenth at gcc dot gnu.org @ 2024-05-07  7:41 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|14.0                        |14.2

--- Comment #4 from Richard Biener <rguenth at gcc dot gnu.org> ---
GCC 14.1 is being released, retargeting bugs to GCC 14.2.

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

end of thread, other threads:[~2024-05-07  7:41 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-04  9:20 [Bug tree-optimization/110538] New: [14 Regression] Dead Code Elimination Regression since r14-368-ge1366a7e4ce theodort at inf dot ethz.ch
2023-07-05  6:43 ` [Bug tree-optimization/110538] " rguenth at gcc dot gnu.org
2023-07-07  0:27 ` pinskia at gcc dot gnu.org
2023-07-07  0:39 ` pinskia at gcc dot gnu.org
2024-03-08 15:28 ` law at gcc dot gnu.org
2024-03-09  7:13 ` law at gcc dot gnu.org
2024-05-07  7:41 ` [Bug tree-optimization/110538] [14/15 " rguenth 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).