public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/109893] New: [14 Regression]  Missed Dead Code Elimination when using __builtin_unreachable since  r14-160-gf828503eeb79ad1f1ada6db7deccc5abcc2f3ca3
@ 2023-05-17 15:15 theodort at inf dot ethz.ch
  2023-05-17 15:29 ` [Bug tree-optimization/109893] " pinskia at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: theodort at inf dot ethz.ch @ 2023-05-17 15:15 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 109893
           Summary: [14 Regression]  Missed Dead Code Elimination when
                    using __builtin_unreachable since
                    r14-160-gf828503eeb79ad1f1ada6db7deccc5abcc2f3ca3
           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: ---

void foo(void);
void bar(void);
static char a;
static int b, e, f;
static int *c = &b, *g;
int main() {
    int *j = 0;
    if (a) {
        g = 0;
        if (c)
            bar();
    } else {
        j = &e;
        c = 0;
    }
    if (c == &f == b || c == &e)
        ;
    else
        __builtin_unreachable();
    if (g || e) {
        if (j == &e || j == 0)
            ;
        else
            foo();
    }
    a = 4;
}

gcc -O3: 

main:
        cmpb    $0, a(%rip)
        je      .L2
        xorl    %esi, %esi
        cmpq    $0, c(%rip)
        movq    %rsi, g(%rip)
        je      .L7
        pushq   %rdx
        call    bar
        movb    $4, a(%rip)
        xorl    %eax, %eax
        popq    %rcx
        ret
.L2:
        xorl    %eax, %eax
        movq    %rax, c(%rip)
.L7:
        movb    $4, a(%rip)
        xorl    %eax, %eax
        ret
c:
        .quad   b

gcc-trunk -O3 

main:
        subq    $8, %rsp
        cmpb    $0, a(%rip)
        je      .L2
        xorl    %edx, %edx
        cmpq    $0, c(%rip)
        movq    %rdx, g(%rip)
        je      .L6
        call    bar
        xorl    %eax, %eax
.L4:
        cmpq    $0, g(%rip)
        je      .L9
.L6:
        movb    $4, a(%rip)
        xorl    %eax, %eax
        addq    $8, %rsp
        ret
.L2:
        xorl    %eax, %eax
        movq    %rax, c(%rip)
        movl    $e, %eax
        jmp     .L4
.L9:
        cmpl    $0, e(%rip)
        je      .L6
        testq   %rax, %rax
        je      .L6
        cmpq    $e, %rax
        je      .L6
        call    foo
        jmp     .L6
c:
        .quad   b

Bisects to:
https://gcc.gnu.org/git/gitweb.cgi?p=gcc.git;h=f828503eeb79ad1f1ada6db7deccc5abcc2f3ca3

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

* [Bug tree-optimization/109893] [14 Regression]  Missed Dead Code Elimination when using __builtin_unreachable since  r14-160-gf828503eeb79ad1f1ada6db7deccc5abcc2f3ca3
  2023-05-17 15:15 [Bug tree-optimization/109893] New: [14 Regression] Missed Dead Code Elimination when using __builtin_unreachable since r14-160-gf828503eeb79ad1f1ada6db7deccc5abcc2f3ca3 theodort at inf dot ethz.ch
@ 2023-05-17 15:29 ` pinskia at gcc dot gnu.org
  2023-08-09  6:33 ` pinskia at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-05-17 15:29 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
           Keywords|                            |missed-optimization
   Last reconfirmed|                            |2023-05-17
             Status|UNCONFIRMED                 |NEW
   Target Milestone|---                         |14.0

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

A minor regression I suspect.

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

* [Bug tree-optimization/109893] [14 Regression]  Missed Dead Code Elimination when using __builtin_unreachable since  r14-160-gf828503eeb79ad1f1ada6db7deccc5abcc2f3ca3
  2023-05-17 15:15 [Bug tree-optimization/109893] New: [14 Regression] Missed Dead Code Elimination when using __builtin_unreachable since r14-160-gf828503eeb79ad1f1ada6db7deccc5abcc2f3ca3 theodort at inf dot ethz.ch
  2023-05-17 15:29 ` [Bug tree-optimization/109893] " pinskia at gcc dot gnu.org
@ 2023-08-09  6:33 ` pinskia at gcc dot gnu.org
  2024-01-12 12:53 ` rguenth at gcc dot gnu.org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-08-09  6:33 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
  # j_10 = PHI <0B(4), &e(6)>
...
  _21 = j_10 == 0B;
  _22 = j_10 == &e;
  _23 = _21 | _22;


The only pass which is able to optmize the above is pre.

That is take:
```
int e;

void g();

int f(int a, int b)
{
  int *t;
  if (a)
    t = 0;
  else
    t = &e;
  if (b)
    g();
  int t1 = t == 0;
  int t2 = t == &e;
  return t1|t2;
}
```

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

* [Bug tree-optimization/109893] [14 Regression]  Missed Dead Code Elimination when using __builtin_unreachable since  r14-160-gf828503eeb79ad1f1ada6db7deccc5abcc2f3ca3
  2023-05-17 15:15 [Bug tree-optimization/109893] New: [14 Regression] Missed Dead Code Elimination when using __builtin_unreachable since r14-160-gf828503eeb79ad1f1ada6db7deccc5abcc2f3ca3 theodort at inf dot ethz.ch
  2023-05-17 15:29 ` [Bug tree-optimization/109893] " pinskia at gcc dot gnu.org
  2023-08-09  6:33 ` pinskia at gcc dot gnu.org
@ 2024-01-12 12:53 ` rguenth at gcc dot gnu.org
  2024-03-08 15:36 ` law at gcc dot gnu.org
  2024-05-07  7:40 ` [Bug tree-optimization/109893] [14/15 " rguenth at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu.org @ 2024-01-12 12:53 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
           Assignee|unassigned at gcc dot gnu.org      |rguenth at gcc dot gnu.org

--- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> ---
This is a failure to jump-thread because of size limits.  If we'd limit
the backward threader the same way as the forward threader we'd optimize this
(--param fsm-scale-path-stmts=1).

--param max-jump-thread-duplication-stmts is 15
--param fsm-scale-path-stmts is 2

but for "true" FSM paths we allow --param max-fsm-thread-path-insns == 100

For non-loop FSM threads we only allow 7 stmts (and we lack the forward
thread estimation of the number of stmts we likely eliminate).

Increasing --param max-jump-thread-duplication-stmts to 17 also works to
resolve the regression.

But IMHO the scale param should simply go - we have the other limit for
paths across a backedge when threading multi-way branches.  The argument
for the scaling is

  /* The generic copier used by the backthreader does not re-use an
     existing threading path to reduce code duplication.  So for that
     case, drastically reduce the number of statements we are allowed
     to copy.  */

that sounds more like limiting overall threading rather than individual
ones.  I'll adjust fsm-scale-path-stmts to be more finely tunable.

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

* [Bug tree-optimization/109893] [14 Regression]  Missed Dead Code Elimination when using __builtin_unreachable since  r14-160-gf828503eeb79ad1f1ada6db7deccc5abcc2f3ca3
  2023-05-17 15:15 [Bug tree-optimization/109893] New: [14 Regression] Missed Dead Code Elimination when using __builtin_unreachable since r14-160-gf828503eeb79ad1f1ada6db7deccc5abcc2f3ca3 theodort at inf dot ethz.ch
                   ` (2 preceding siblings ...)
  2024-01-12 12:53 ` rguenth at gcc dot gnu.org
@ 2024-03-08 15:36 ` law at gcc dot gnu.org
  2024-05-07  7:40 ` [Bug tree-optimization/109893] [14/15 " rguenth at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: law at gcc dot gnu.org @ 2024-03-08 15:36 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

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

* [Bug tree-optimization/109893] [14/15 Regression]  Missed Dead Code Elimination when using __builtin_unreachable since  r14-160-gf828503eeb79ad1f1ada6db7deccc5abcc2f3ca3
  2023-05-17 15:15 [Bug tree-optimization/109893] New: [14 Regression] Missed Dead Code Elimination when using __builtin_unreachable since r14-160-gf828503eeb79ad1f1ada6db7deccc5abcc2f3ca3 theodort at inf dot ethz.ch
                   ` (3 preceding siblings ...)
  2024-03-08 15:36 ` law at gcc dot gnu.org
@ 2024-05-07  7:40 ` rguenth at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu.org @ 2024-05-07  7:40 UTC (permalink / raw)
  To: gcc-bugs

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

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] 6+ messages in thread

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

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-17 15:15 [Bug tree-optimization/109893] New: [14 Regression] Missed Dead Code Elimination when using __builtin_unreachable since r14-160-gf828503eeb79ad1f1ada6db7deccc5abcc2f3ca3 theodort at inf dot ethz.ch
2023-05-17 15:29 ` [Bug tree-optimization/109893] " pinskia at gcc dot gnu.org
2023-08-09  6:33 ` pinskia at gcc dot gnu.org
2024-01-12 12:53 ` rguenth at gcc dot gnu.org
2024-03-08 15:36 ` law at gcc dot gnu.org
2024-05-07  7:40 ` [Bug tree-optimization/109893] [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).