From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 51CB53858D1E; Tue, 20 Jun 2023 17:11:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 51CB53858D1E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1687281098; bh=CdQV3CKJpKfLQzLrmNBZwrF2UDh+GKlSUG7H2B1aBKw=; h=From:To:Subject:Date:From; b=jhn5hDNVozsgQkerF7ZQ0lkuoh4B5GZJL8N1jZCSHmhxxlgqElIpOg9L9rY7zvZZq 4lce1mpB7oeLsi/zK3qh7U7efAv1mEukhNI7/tsTXCI4bvrujIagldGQfWVkVAkITs jpuCxlaCEpSASKTk5UH0HRblgi5ELEnYOsT0FvHE= From: "theodort at inf dot ethz.ch" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/110327] New: [12/13/14 Regression] Missed Dead Code Elimination when using __builtin_unreachable since r12-4790-g4b3a325f07a Date: Tue, 20 Jun 2023 17:11:37 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 14.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: theodort at inf dot ethz.ch X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D110327 Bug ID: 110327 Summary: [12/13/14 Regression] Missed Dead Code Elimination when using __builtin_unreachable since r12-4790-g4b3a325f07a 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/eT1jqzrT5 Given the following code: void foo(void); static int a, c; static int *d, *e =3D &a; static int **f =3D &d, **g =3D &e; static int ***h =3D &g; static int ****i =3D &h; static short j; static char(k)(char b) { if (!(((b) >=3D -28) && ((b) <=3D -28))) { __builtin_unreachable(); } return 0; } static int l() { a =3D -28; for (; a !=3D 2; a++) { j =3D c; c =3D 0; for (; c !=3D 2; c =3D j) if (a) break; k(****i); if (****i >=3D 5 ^ 1) { ***i =3D *f; if (c < 1) return 1; if (a) foo(); ; } } return a; } int main() { l(); } gcc-trunk -O2 does not eliminate the call to foo: main: subq $8, %rsp movl $-28, %eax movl $-28, a(%rip) .p2align 4,,10 .p2align 3 .L10: movl c(%rip), %edx testl %eax, %eax jne .L19 cmpw $2, %dx je .L4 .L5: jmp .L5 .p2align 4,,10 .p2align 3 .L4: movl $2, c(%rip) movl $2, %esi .L3: movq h(%rip), %rdx movq (%rdx), %rdx movq (%rdx), %rcx cmpl $4, (%rcx) jg .L7 movq d(%rip), %rcx movq %rcx, (%rdx) testl %esi, %esi je .L16 testl %eax, %eax jne .L20 .L7: movl a(%rip), %eax addl $1, %eax movl %eax, a(%rip) cmpl $2, %eax jne .L10 .L16: xorl %eax, %eax addq $8, %rsp ret .p2align 4,,10 .p2align 3 .L20: call foo jmp .L7 .L19: xorl %edx, %edx xorl %esi, %esi movl %edx, c(%rip) jmp .L3 gcc-11.4.0 -O2 eliminates the call to foo: main: movl $-28, a(%rip) movq h(%rip), %rcx movl $-28, %edx .p2align 4,,10 .p2align 3 .L8: movzwl c(%rip), %eax movl $0, c(%rip) testl %edx, %edx jne .L2 .p2align 4,,10 .p2align 3 .L3: cmpw $2, %ax jne .L3 movl $2, c(%rip) movq (%rcx), %rax movq (%rax), %rdx cmpl $4, (%rdx) jg .L5 movq d(%rip), %rdx movq %rdx, (%rax) .L5: movl a(%rip), %eax leal 1(%rax), %edx movl %edx, a(%rip) cmpl $2, %edx jne .L8 .L13: xorl %eax, %eax ret .L2: movq (%rcx), %rax movq (%rax), %rdx cmpl $4, (%rdx) jg .L5 movq d(%rip), %rdx movq %rdx, (%rax) jmp .L13 Bisects to r12-4790-g4b3a325f07a=