From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id C4AC83858401; Thu, 1 Jun 2023 13:54:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C4AC83858401 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1685627683; bh=gMSRu2nYqpJZFqDvI5X0kcBMWsIlUGW739+N1Z+/wtk=; h=From:To:Subject:Date:From; b=Vq361uzec5HRAGnW/ON4JZWwhvTBTVzM7hYjpTf1Wy/u9ZpSVToUEyyqfB/bWdqpP KIfSv4xA9jqmHKvTs7gxhoZHrIRCj1b0byMcgcEJPl9Qesr9lSGfl/C1AimY08IvxC QljI9qJ+rfjvLjBrO9ngaqfmBi8zo3ENk9cqJTVk= From: "theodort at inf dot ethz.ch" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/110080] New: [13/14 Regression] Missed Dead Code Elimination at -Os when using __builtin_unreachable since r13-6945-g429a7a88438 Date: Thu, 01 Jun 2023 13:54:43 +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=3D110080 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:=20 void foo(void); static unsigned char a =3D 131; static int *b; static int **c =3D &b; static void d(int e, unsigned f) { int *g; if (e){ for (; a; ++a) for (e =3D 0; 0;) ; g =3D &e; int **h =3D &g; if (**h) { foo(); } } *c =3D &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 =3D 131; static int *b; static int **c =3D &b; static void d(int e, unsigned f) { int *g; if (f !=3D 131) { __builtin_unreachable(); // <- THIS } if (!e){ for (; a; ++a) for (e =3D 0; 0;) ; g =3D &e; int **h =3D &g; if (**h) { foo(); } } *c =3D &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=