From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 6D53D3858C27; Tue, 23 May 2023 13:30:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6D53D3858C27 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1684848632; bh=iLuIjwiwMBS4HZIi2iB2Ng09JydHjB/l+3FjVMd8eI8=; h=From:To:Subject:Date:From; b=tl1fqWOv+W1jHfh48eae3e0OA1FEK4esjVgcCSDWKzCA5Xh/XPBMXS+V7/UWB+JfH d7INJI2dNs8c/qY7KYFEFL+GC3njqDAQxFJsp6vrO6jISBgsKFUCPauB0l7iCzuZdN L9DwxAoDGhpSYepdCUAbdZ1mDbPnSbaEk6fOjoJ4= From: "theodort at inf dot ethz.ch" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/109943] New: [13/14 Regression] Missed Dead Code Elimination when using __builtin_unreachable since r13-6834-g41ade3399bd Date: Tue, 23 May 2023 13:30:32 +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=3D109943 Bug ID: 109943 Summary: [13/14 Regression] Missed Dead Code Elimination when using __builtin_unreachable since r13-6834-g41ade3399bd 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); static int b =3D 5; static int *c =3D &b; static char(a)(char d, char g) { ; return d % g; } static void e(unsigned char d, unsigned g) { char h =3D a(g, d); if (h) if ((d) >=3D 0) { foo(); }; } static void f(int d) { e(b, d); } int main() { f(*c); *c =3D 0; } gcc-trunk -O3 generates: main: movl $0, b(%rip) xorl %eax, %eax ret However, including additional info via __builtin_unreachable results to wor= se code: void foo(void); static int b =3D 5; static int *c =3D &b; static char(a)(char d, char g) { if ((g) <=3D 0) { __builtin_unreachable(); } return d % g; } static void e(unsigned char d, unsigned g) { char h =3D a(g, d); if (h) if ((d) >=3D 0) { foo(); }; } static void f(int d) { e(b, d); } int main() { f(*c); *c =3D 0; } gcc-trunk (and 13) -O3 generates: main: movl b(%rip), %ecx movsbl %cl, %eax movzbl %cl, %ecx cltd idivl %ecx testl %edx, %edx jne .L11 movl $0, b(%rip) xorl %eax, %eax ret .L11: pushq %rax call foo xorl %edx, %edx xorl %eax, %eax movl %edx, b(%rip) popq %rcx ret https://godbolt.org/z/n34Tsr3vq gcc-12 can generate optimized code for both cases Started with r13-6834-g41ade3399bd=