public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/110177] New: [12/13/14 Regression] Missed Dead Code Elimination when using __builtin_unreachable since r12-2305-g398572c1544
@ 2023-06-08 14:52 theodort at inf dot ethz.ch
  2023-06-08 20:21 ` [Bug tree-optimization/110177] " 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-06-08 14:52 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 110177
           Summary: [12/13/14 Regression] Missed Dead Code Elimination
                    when using __builtin_unreachable since
                    r12-2305-g398572c1544
           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/d6zscbYYh

void foo(void);
static int c, *d = &c, *f, *i;
static unsigned e;
static int **g = &d, **j = &f,***h = &g;
static short k;
void __assert_fail() __attribute__((__noreturn__));
static short(a)(short b) {
    if (b != 0) {
        __builtin_unreachable();
    }
    return 0;
}
int main() {
    c = 0;
    for (; c <= 20; c = c + 9) {
        k = c << e;
        c &&a(c >> k);
        i = **h;
        *j = i;
        if (f)
            ;
        else
            __assert_fail();
    }
    e = 0;
    if (f);
    else
        foo();
}

gcc-11.4 -Os generates:

main:
        movq    g(%rip), %rax
        movl    $0, c(%rip)
        movq    (%rax), %rdx
        movq    %rdx, f(%rip)
        testq   %rdx, %rdx
        je      .L2
        movq    (%rax), %rax
        movq    %rax, f(%rip)
        testq   %rax, %rax
        jne     .L8
        movl    $9, c(%rip)
.L2:
        pushq   %rax
        xorl    %eax, %eax
        call    __assert_fail
.L8:
        movl    $27, c(%rip)
        xorl    %eax, %eax
        movl    $0, e(%rip)
        ret

gcc-trunk -Os generates:

main:
        xorl    %edi, %edi
        pushq   %rsi
        movq    g(%rip), %r8
        xorl    %eax, %eax
        movl    %edi, c(%rip)
        movl    e(%rip), %edi
        xorl    %edx, %edx
.L2:
        movl    %eax, %esi
        cmpl    $27, %eax
        je      .L23
        testl   %eax, %eax
        je      .L3
        movl    %edi, %ecx
        movl    %eax, %r9d
        movl    %eax, %r10d
        sall    %cl, %r9d
        movl    %r9d, %ecx
        sarl    %cl, %r10d
        testl   %r10d, %r10d
        je      .L3
        movl    %eax, c(%rip)
.L3:
        movq    (%r8), %rcx
        addl    $9, %eax
        movq    %rcx, f(%rip)
        testq   %rcx, %rcx
        jne     .L8
        testb   %dl, %dl
        je      .L4
        movl    %esi, c(%rip)
.L4:
        xorl    %eax, %eax
        call    __assert_fail
.L8:
        movb    $1, %dl
        jmp     .L2
.L23:
        testb   %dl, %dl
        je      .L6
        movl    $27, c(%rip)
.L6:
        xorl    %ecx, %ecx
        cmpq    $0, f(%rip)
        movl    %ecx, e(%rip)
        jne     .L7
        call    foo
.L7:
        xorl    %eax, %eax
        popq    %rdx
        ret

Bisects to r12-2305-g398572c1544

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

* [Bug tree-optimization/110177] [12/13/14 Regression] Missed Dead Code Elimination when using __builtin_unreachable since r12-2305-g398572c1544
  2023-06-08 14:52 [Bug tree-optimization/110177] New: [12/13/14 Regression] Missed Dead Code Elimination when using __builtin_unreachable since r12-2305-g398572c1544 theodort at inf dot ethz.ch
@ 2023-06-08 20:21 ` pinskia at gcc dot gnu.org
  2023-06-08 20:31 ` 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-06-08 20:21 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

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

* [Bug tree-optimization/110177] [12/13/14 Regression] Missed Dead Code Elimination when using __builtin_unreachable since r12-2305-g398572c1544
  2023-06-08 14:52 [Bug tree-optimization/110177] New: [12/13/14 Regression] Missed Dead Code Elimination when using __builtin_unreachable since r12-2305-g398572c1544 theodort at inf dot ethz.ch
  2023-06-08 20:21 ` [Bug tree-optimization/110177] " pinskia at gcc dot gnu.org
@ 2023-06-08 20:31 ` pinskia at gcc dot gnu.org
  2023-06-08 22:27 ` pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-06-08 20:31 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Hmm, in ccp1, GCC 11.3 does:
Visiting statement:
# RANGE [0, 0] NONZERO 0
b_33 = (short intD.25) _11;
which is likely CONSTANT
Applying pattern match.pd:3405, gimple-match.c:27041
Applying pattern match.pd:3322, gimple-match.c:26980
Match-and-simplified (short int) _11 to _10
Lattice value changed to CONSTANT 0.  Adding SSA edges to worklist.
marking stmt to be not simulated again

Visiting statement:
if (b_33 != 0)
which is likely CONSTANT
Adding destination of edge (4 -> 6) to worklist
marking stmt to be not simulated again



While in GCC 12+ does:
Visiting statement:
b_33 = (short intD.25) _11;
which is likely CONSTANT
Applying pattern match.pd:3730, gimple-match.cc:69683
Applying pattern match.pd:3647, gimple-match.cc:69622
Match-and-simplified (short int) _11 to _10
Lattice value changed to CONSTANT _10.  Adding SSA edges to worklist.
marking stmt to be not simulated again

Visiting statement:
if (b_33 != 0)
which is likely CONSTANT
Matching expression match.pd:2118, generic-match.cc:693
Matching expression match.pd:2121, generic-match.cc:753
Matching expression match.pd:2128, generic-match.cc:776
Adding destination of edge (4 -> 5) to worklist
Adding destination of edge (4 -> 6) to worklist

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

* [Bug tree-optimization/110177] [12/13/14 Regression] Missed Dead Code Elimination when using __builtin_unreachable since r12-2305-g398572c1544
  2023-06-08 14:52 [Bug tree-optimization/110177] New: [12/13/14 Regression] Missed Dead Code Elimination when using __builtin_unreachable since r12-2305-g398572c1544 theodort at inf dot ethz.ch
  2023-06-08 20:21 ` [Bug tree-optimization/110177] " pinskia at gcc dot gnu.org
  2023-06-08 20:31 ` pinskia at gcc dot gnu.org
@ 2023-06-08 22:27 ` pinskia at gcc dot gnu.org
  2023-06-20 11:17 ` theodort at inf dot ethz.ch
  2024-03-08 15:34 ` law at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-06-08 22:27 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed. But I don't think  r12-2305-g398572c1544 caused it ...

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

* [Bug tree-optimization/110177] [12/13/14 Regression] Missed Dead Code Elimination when using __builtin_unreachable since r12-2305-g398572c1544
  2023-06-08 14:52 [Bug tree-optimization/110177] New: [12/13/14 Regression] Missed Dead Code Elimination when using __builtin_unreachable since r12-2305-g398572c1544 theodort at inf dot ethz.ch
                   ` (2 preceding siblings ...)
  2023-06-08 22:27 ` pinskia at gcc dot gnu.org
@ 2023-06-20 11:17 ` theodort at inf dot ethz.ch
  2024-03-08 15:34 ` law at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: theodort at inf dot ethz.ch @ 2023-06-20 11:17 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Theodoros Theodoridis <theodort at inf dot ethz.ch> ---
I think the correct bisection is: r11-3063-gfcae5121154 (or its parent
r11-3062-g90e88fd376b)
I can't build its parent but with its grandparent r11-3061-g1644d7f4c1c the
call to foo is eliminated:

gcc-1644d7f4c1c4f99231d7de5e35fa7ce2d2e2c4c6 -Os test.c -S -o /dev/stdout

main:
        movq    g(%rip), %rax
        movl    $0, c(%rip)
        movq    (%rax), %rdx
        movq    %rdx, f(%rip)
        testq   %rdx, %rdx
        je      .L2
        movq    (%rax), %rax
        movq    %rax, f(%rip)
        testq   %rax, %rax
        jne     .L8
        movl    $9, c(%rip)
.L2:
        pushq   %rax
        xorl    %eax, %eax
        call    __assert_fail
.L8:
        movl    $27, c(%rip)
        xorl    %eax, %eax
        movl    $0, e(%rip)
        ret


r11-3063-gfcae5121154 with ranger disabled generates the same code

gcc-fcae5121154d1c3382b056bcc2c563cedac28e74 -Os test.c -S -o /dev/stdout:

main:
        movq    g(%rip), %rax
        movl    $0, c(%rip)
        movq    (%rax), %rdx
        movq    %rdx, f(%rip)
        testq   %rdx, %rdx
        je      .L2
        movq    (%rax), %rax
        movq    %rax, f(%rip)
        testq   %rax, %rax
        jne     .L8
        movl    $9, c(%rip)
.L2:
        pushq   %rax
        xorl    %eax, %eax
        call    __assert_fail
.L8:
        movl    $27, c(%rip)
        xorl    %eax, %eax
        movl    $0, e(%rip)
        ret

with ranger enabled it doesn't eliminate the call and generates mode code:
gcc-fcae5121154d1c3382b056bcc2c563cedac28e74 -Os -fevrp-mode=ranger test.c -S
-o /dev/stdout:

main:
        pushq   %rcx
        movl    e(%rip), %edi
        xorl    %eax, %eax
        xorl    %edx, %edx
        movl    $0, c(%rip)
        movq    g(%rip), %r8
.L2:
        movl    %eax, %esi
        cmpl    $27, %eax
        je      .L20
        testl   %eax, %eax
        je      .L3
        movl    %edi, %ecx
        movl    %eax, %r9d
        movl    %eax, %r10d
        sall    %cl, %r9d
        movl    %r9d, %ecx
        sarl    %cl, %r10d
        testw   %r10w, %r10w
        je      .L3
        movl    %eax, c(%rip)
.L3:
        movq    (%r8), %rcx
        addl    $9, %eax
        movq    %rcx, f(%rip)
        testq   %rcx, %rcx
        jne     .L8
        testb   %dl, %dl
        je      .L4
        movl    %esi, c(%rip)
.L4:
        xorl    %eax, %eax
        call    __assert_fail
.L8:
        movb    $1, %dl
        jmp     .L2
.L20:
        testb   %dl, %dl
        je      .L6
        movl    $27, c(%rip)
.L6:
        cmpq    $0, f(%rip)
        movl    $0, e(%rip)
        jne     .L7
        call    foo
.L7:
        xorl    %eax, %eax
        popq    %rdx
        ret

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

* [Bug tree-optimization/110177] [12/13/14 Regression] Missed Dead Code Elimination when using __builtin_unreachable since r12-2305-g398572c1544
  2023-06-08 14:52 [Bug tree-optimization/110177] New: [12/13/14 Regression] Missed Dead Code Elimination when using __builtin_unreachable since r12-2305-g398572c1544 theodort at inf dot ethz.ch
                   ` (3 preceding siblings ...)
  2023-06-20 11:17 ` theodort at inf dot ethz.ch
@ 2024-03-08 15:34 ` law at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: law at gcc dot gnu.org @ 2024-03-08 15:34 UTC (permalink / raw)
  To: gcc-bugs

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

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

end of thread, other threads:[~2024-03-08 15:34 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-08 14:52 [Bug tree-optimization/110177] New: [12/13/14 Regression] Missed Dead Code Elimination when using __builtin_unreachable since r12-2305-g398572c1544 theodort at inf dot ethz.ch
2023-06-08 20:21 ` [Bug tree-optimization/110177] " pinskia at gcc dot gnu.org
2023-06-08 20:31 ` pinskia at gcc dot gnu.org
2023-06-08 22:27 ` pinskia at gcc dot gnu.org
2023-06-20 11:17 ` theodort at inf dot ethz.ch
2024-03-08 15:34 ` law 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).