From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id E0C013896C14; Tue, 3 Aug 2021 09:25:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E0C013896C14 From: "marxin 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: Tue, 03 Aug 2021 09:25:00 +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: marxin 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: cc 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: Tue, 03 Aug 2021 09:25:01 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D101701 Martin Li=C5=A1ka changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |jakub at gcc dot gnu.org --- Comment #5 from Martin Li=C5=A1ka --- (In reply to Andrew Pinski from comment #2) > So the problem here is iftoswitch should ignore if it is profitable to > convert the ifs to a switch statement (unless there are only two ifs) and > then allow the switchlower pass to lower the switch again. This was my original intention, but Jakub wanted to make the if-to-switch transformation only conditionally based on the ability to make a jump table or a bit-test. Reason is that some optimization passes work only on series of gimple conditions. >=20 > 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 > into a switch statement. In my case, it's not transformed as we do JT at least for 5 cases: unsigned int default_case_values_threshold (void) { return (targetm.have_casesi () ? 4 : 5); } That's why you see a different codegen on ARM target.=