From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id BD3A0385772E; Tue, 18 Apr 2023 15:07:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BD3A0385772E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1681830449; bh=YwStv7LlgOf6hRT67sXV7Sqcv+kyF1CUzNdHWVxRx34=; h=From:To:Subject:Date:From; b=xiEHHetEajGo3C1nsSjwBaYDkhbynDviS+IzA/+hKEvdj0564PTW3EB6LtopMGwYv Ge+sC10ayb4ONm51choSs9i9yX0qMvwhn9zUvZPKf6Fg8cdiR1+zeoM6e1p/4CFPsq MigIBsPdiwjtx6xcgTwwn2mSdgU3ksV5BdmtyV+A= From: "theodort at inf dot ethz.ch" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/109546] New: [13 Regression] Missed Dead Code Elimination when using __builtin_unreachable Date: Tue, 18 Apr 2023 15:07:29 +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: 13.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=3D109546 Bug ID: 109546 Summary: [13 Regression] Missed Dead Code Elimination when using __builtin_unreachable Product: gcc Version: 13.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: --- cat input.c=20 void foo(void); static int a, c; static int *b =3D &a; static int **d =3D &b; void __assert_fail() __attribute__((__noreturn__)); int main() { int *e =3D *d; if (e =3D=3D &a || e =3D=3D &c); else { __assert_fail(); } if (e =3D=3D &a || e =3D=3D &c); else foo(); } both gcc 12 and trunk at -O3 generate the following code: main: movq b(%rip), %rax cmpq $c, %rax je .L2 cmpq $a, %rax jne .L7 .L2: xorl %eax, %eax ret .L7: pushq %rax xorl %eax, %eax call __assert_fail b: .quad a the call to foo is eliminated but the call to __assert_fail is missed, even though=20 both if statement conditions are identical.=20 If add a __builtin_unreachable before the call to __assert_fail the opposite happens: void foo(void); static int a, c; static int *b =3D &a; static int **d =3D &b; void assert_fail() __attribute__((__noreturn__)); int main() { int *e =3D *d; if (e =3D=3D &a || e =3D=3D &c); else { __builtin_unreachable();=20 assert_fail(); } if (e =3D=3D &a || e =3D=3D &c); else foo(); } gcc-trunk -O3 generates: main: movq b(%rip), %rax cmpq $c, %rax je .L4 cmpq $a, %rax je .L4 pushq %rax call foo xorl %eax, %eax popq %rdx ret .L4: xorl %eax, %eax ret b: .quad a the call to __assert_fail is now properly eliminated but now the call to fo= o is missed.=20 This is a regression as gcc-12 generates:=20 main: xorl %eax, %eax ret=