From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 47A1C3858D37; Thu, 22 Jun 2023 11:40:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 47A1C3858D37 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1687434041; bh=yN5sf9GKRWtqHyceL2WYIQnIEdIqCOy8bzYpzaIAGUw=; h=From:To:Subject:Date:From; b=bDVNCuVjtvEavM2QIABzTI0cmUOCKC7OlsXLiFDNmZpCh3MncMUQdNdVDhig3ONCr 9JLBbGv/htezSRWeInfbugea2xNXd8tYCsIVixI3U+uDFJ/uVNFWtkaU2oc+0L5YhE nCjXrsoif7Ji9O7GW9c1xx8e668WvSzEiTp5jAoQ= From: "theodort at inf dot ethz.ch" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/110361] New: [13/14 Regression] Missed Dead Code Elimination when using __builtin_unreachable since r13-2020-g16b013c9d9b Date: Thu, 22 Jun 2023 11:40:40 +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=3D110361 Bug ID: 110361 Summary: [13/14 Regression] Missed Dead Code Elimination when using __builtin_unreachable since r13-2020-g16b013c9d9b 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/qab3679sq Given the following code: void foo(void); static int a, b, d, p, k; static int *c, *e, *g; static short f; static unsigned h; static int **i =3D &c, **o =3D &g; void __assert_fail() __attribute__((__noreturn__)); static void j(char, unsigned r) { h =3D r =3D=3D 0 ?: 2 % r; int l =3D h; if (!(((l) >=3D 1) && ((l) <=3D 1))) { __builtin_unreachable(); } int m; *i =3D &m; } static int *n(); static short q(short t) { *o =3D &p; return t; } static unsigned s() { int *j =3D n(); if (e =3D=3D 0 || e =3D=3D &a || e =3D=3D &d) ; else __assert_fail(); return *j; } static int *n() { if (b) { if (c) __assert_fail(); e =3D 0; } return &k; } int main() { j(q(s()), f); if (e =3D=3D 0 || e =3D=3D &a || e =3D=3D &d) ; else foo(); f =3D 0; } gcc-trunk -O2 does not eliminate the call to foo: main: subq $24, %rsp movq e(%rip), %rax movswl f(%rip), %edx testq %rax, %rax je .L2 cmpq $a, %rax je .L4 cmpq $d, %rax jne .L17 .L4: movq $p, g(%rip) testl %edx, %edx je .L18 leaq 12(%rsp), %rdx movq %rdx, c(%rip) cmpq $a, %rax je .L5 cmpq $d, %rax je .L5 call foo .L5: xorl %eax, %eax movw %ax, f(%rip) xorl %eax, %eax addq $24, %rsp ret .L18: leaq 12(%rsp), %rax movq %rax, c(%rip) jmp .L5 .L2: movq $p, g(%rip) leaq 12(%rsp), %rax movq %rax, c(%rip) jmp .L5 .L17: xorl %eax, %eax call __assert_fail gcc-12.3.0 -O2 eliminates the call to foo: main: subq $24, %rsp movq e(%rip), %rax testq %rax, %rax je .L2 cmpq $a, %rax je .L2 cmpq $d, %rax jne .L14 .L2: movq $p, g(%rip) leaq 12(%rsp), %rax movq %rax, c(%rip) xorl %eax, %eax movw %ax, f(%rip) xorl %eax, %eax addq $24, %rsp ret .L14: xorl %eax, %eax call __assert_fail Bisects to r13-2020-g16b013c9d9b=