From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id DFAC23860C08; Thu, 26 May 2022 11:26:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DFAC23860C08 From: "b.buschinski at googlemail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/105740] New: missed optimization switch transformation for conditions with duplicate conditions Date: Thu, 26 May 2022 11:26:46 +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: 12.1.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: b.buschinski at googlemail dot com 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 attachments.created 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 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 26 May 2022 11:26:47 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D105740 Bug ID: 105740 Summary: missed optimization switch transformation for conditions with duplicate conditions Product: gcc Version: 12.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: b.buschinski at googlemail dot com Target Milestone: --- Created attachment 53037 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=3D53037&action=3Dedit Attached code + asm from the compiler explorer link Compiler Explorer Link: https://godbolt.org/z/q76s99Gj9 The code on the left does not generate a switch statement. The code on the right does generate a switch statement. The code works similar, the only difference is that the duplicate "f->len >= 3" check is moved to the top for the "right" version. The compiler explorer code is actually a minimized version of the code I wo= rk on (with way more conditions in a hot code path), where I can not easily mo= ve the length check to the top, because the "f-> len > 3 && ..." is done in a = very complicated macro, but that's just details. I expected both code versions to generate the same assembler. Tested with GCC-12.1 and 11.3. 10.3 does not generate a switch version for = both versions, as only 11 got this nice feature. On x86_64 Linux. Please let me know if you need any additional details or if this report was useful at all.=