public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/110080] New: [13/14 Regression] Missed Dead Code Elimination at -Os when using __builtin_unreachable since r13-6945-g429a7a88438
@ 2023-06-01 13:54 theodort at inf dot ethz.ch
  2023-06-01 14:02 ` [Bug tree-optimization/110080] " theodort at inf dot ethz.ch
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: theodort at inf dot ethz.ch @ 2023-06-01 13:54 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 110080
           Summary: [13/14 Regression] Missed Dead Code Elimination at -Os
                    when using __builtin_unreachable since
                    r13-6945-g429a7a88438
           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: ---

Given: 

void foo(void);
static unsigned char a = 131;
static int *b;
static int **c = &b;
static void d(int e, unsigned f) {
    int *g;
    if (e){
        for (; a; ++a)
            for (e = 0; 0;)
                ;
        g = &e;
        int **h = &g;
        if (**h) {
            foo();
        }
    }
    *c = &e;
}
int main() { d(4 & a, a); }


gcc trunk/13.1/12.3 at -Os generate:

main:
        testb   $4, a(%rip)
        je      .L3
        movb    $0, a(%rip)
.L3:
        leaq    -4(%rsp), %rax
        movq    %rax, b(%rip)
        xorl    %eax, %eax
        ret
a:
        .byte   -125

If I include a __builtin_unreachable() to help the compiler:

void foo(void);
static unsigned char a = 131;
static int *b;
static int **c = &b;
static void d(int e, unsigned f) {
    int *g;
    if (f != 131) {
        __builtin_unreachable(); // <- THIS
    }
    if (!e){
        for (; a; ++a)
            for (e = 0; 0;)
                ;
        g = &e;
        int **h = &g;
        if (**h) {
            foo();
        }
    }
    *c = &e;
}
int main() { d(4 & a, a); }

gcc-12.3 at -Os generates better code:

main:
        leaq    -4(%rsp), %rax
        movb    $0, a(%rip)
        movq    %rax, b(%rip)
        xorl    %eax, %eax
        ret
a:
        .byte   -125

But gcc-13.1/trunk at -Os generate worse code:

main:
        subq    $24, %rsp
        movb    a(%rip), %al
        movl    %eax, %edx
        andl    $4, %edx
        movl    %edx, 12(%rsp)
        xorl    %edx, %edx
.L2:
        testb   %al, %al
        je      .L8
        incl    %eax
        movb    $1, %dl
        jmp     .L2
.L8:
        testb   %dl, %dl
        je      .L4
        movb    $0, a(%rip)
        jmp     .L5
.L4:
        cmpl    $0, 12(%rsp)
        je      .L5
        call    foo
.L5:
        leaq    12(%rsp), %rax
        movq    %rax, b(%rip)
        xorl    %eax, %eax
        addq    $24, %rsp
        ret
a:
        .byte   -125

https://godbolt.org/z/zvqshjEj3


Started with r13-6945-g429a7a88438

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

end of thread, other threads:[~2023-09-19 15:03 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-01 13:54 [Bug tree-optimization/110080] New: [13/14 Regression] Missed Dead Code Elimination at -Os when using __builtin_unreachable since r13-6945-g429a7a88438 theodort at inf dot ethz.ch
2023-06-01 14:02 ` [Bug tree-optimization/110080] " theodort at inf dot ethz.ch
2023-06-02  7:53 ` rguenth at gcc dot gnu.org
2023-07-27  9:26 ` rguenth at gcc dot gnu.org
2023-08-21 23:20 ` pinskia at gcc dot gnu.org
2023-08-21 23:21 ` pinskia at gcc dot gnu.org
2023-09-19 14:30 ` cvs-commit at gcc dot gnu.org
2023-09-19 15:03 ` amacleod at redhat dot com

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).