From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 4FB243858C53; Sat, 26 Aug 2023 19:39:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4FB243858C53 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1693078792; bh=0MGs1jb+PApVMu34gB/vDI1wjSEf1EVbDmHbU7NKVwA=; h=From:To:Subject:Date:From; b=s5d4FZCcUzwP8H5B2FAlA5zPulS44djrcTj9fr5wcWKn24lC0DAbf6eXNhmoHABI7 h6qjXss+OhNvu4GlLxDdvH/XBdlifzNunq1CLbdtE0FNAgSTr0NSECG89uSfAR89G6 UOECp2K9n9EfMA327VdPKLouyvpaPjrUQ8ce6yb4= From: "pinskia at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/111167] New: swapping around duplicated conditionals can produce better code Date: Sat, 26 Aug 2023 19:39:51 +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: missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: pinskia at gcc dot gnu.org 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 keywords 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=3D111167 Bug ID: 111167 Summary: swapping around duplicated conditionals can produce better code Product: gcc Version: 14.0 Status: UNCONFIRMED Keywords: missed-optimization Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: pinskia at gcc dot gnu.org Target Milestone: --- Take reduced from GCC's sources for lookup_attribute: ``` void f(int); inline void canonicalize_attr_name(const char *&s, int l) { if (l > 4 && s[0] =3D=3D '_' && s[l - 1] =3D=3D '_' )=20 s +=3D 2; } void lookup_attribute(const char *attr_ns, int list, int t) { if (attr_ns && attr_ns[0] !=3D '_') { canonicalize_attr_name(attr_ns, 5); } if (list =3D=3D 0) { short attr_ns_len =3D attr_ns ? t : 0; f(attr_ns_len); } } ``` In optimized we have: ``` if (attr_ns_25(D) !=3D 0B) goto ; [70.00%] else goto ; [30.00%] [local count: 322122543]: if (list_10(D) =3D=3D 0) goto ; [50.00%] else goto ; [50.00%] [local count: 751619279]: if (list_10(D) =3D=3D 0) goto ; [50.00%] else goto ; [50.00%] ``` But we should really just have: if (list_10(D) =3D=3D 0) goto bb7; if (attr_ns_25(D) !=3D 0B) goto bb5; else bb6;=