From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id C1489385783D; Fri, 30 Jul 2021 23:48:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C1489385783D From: "pinskia at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/101701] GCC optimization and code generation for if-else chains vs ternary chains vs a switch Date: Fri, 30 Jul 2021 23:48:33 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 12.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: enhancement X-Bugzilla-Who: pinskia at gcc dot gnu.org X-Bugzilla-Status: NEW 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: everconfirmed cf_reconfirmed_on bug_status bug_severity Message-ID: In-Reply-To: References: 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: Fri, 30 Jul 2021 23:48:33 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D101701 Andrew Pinski changed: What |Removed |Added ---------------------------------------------------------------------------- Ever confirmed|0 |1 Last reconfirmed| |2021-07-30 Status|UNCONFIRMED |NEW Severity|normal |enhancement --- Comment #2 from Andrew Pinski --- So the problem here is iftoswitch should ignore if it is profitable to conv= ert the ifs to a switch statement (unless there are only two ifs) and then allow the switchlower pass to lower the switch again. I thought there was a bug about this already too. What is interesting is that the cost for ifs are so high on arm target (compared to a switch), we end up with the best code already: foo(int): subs r3, r0, #1 cmp r3, #3 it hi movhi r0, #-1 bx lr bar(int): subs r3, r0, #1 cmp r3, #3 it hi movhi r0, #-1 bx lr baz(int): subs r3, r0, #1 cmp r3, #4 it cs movcs r0, #-1 bx lr :) So x86 we get: ;; Canonical GIMPLE case clusters: 1 2 3 4=20 For foo and then for bar: ;; Canonical GIMPLE case clusters: 1 2 3 4=20 ;; BT can be built: BT(values:4 comparisons:8 range:4 density: 200.00%):1-4= =20 /app/example.cpp:10:21: optimized: Condition chain with 4 BBs transformed i= nto a switch statement.=