From patchwork Tue Dec 1 13:57:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Martin_Li=C5=A1ka?= X-Patchwork-Id: 1408855 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.cz Received: from sourceware.org (unknown [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4ClkF36xZ3z9sVq for ; Wed, 2 Dec 2020 00:57:26 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9515F3850430; Tue, 1 Dec 2020 13:57:23 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by sourceware.org (Postfix) with ESMTPS id 0F17C3949D80 for ; Tue, 1 Dec 2020 13:57:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 0F17C3949D80 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mliska@suse.cz X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id B6DD4AC90; Tue, 1 Dec 2020 13:57:19 +0000 (UTC) Subject: [PATCH] if-to-switch: Support chain with 2 BBs. To: Richard Biener References: <2c3db526-cac6-4eeb-4afb-12024f8d5af2@suse.cz> <46e9e574-80f8-3cce-3fcf-dbc8205e74ae@suse.cz> <0f418e79-d46b-5577-ebdf-dbc29eed8057@suse.cz> <1f725789-559f-e91f-dec3-352ab42e92d8@suse.cz> From: =?utf-8?q?Martin_Li=C5=A1ka?= Message-ID: Date: Tue, 1 Dec 2020 14:57:19 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.5.0 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US X-Spam-Status: No, score=-10.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jakub Jelinek , GCC Patches , Jan Hubicka Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" Hello. The following patch is a small tweak than enables more opportunities. It fixes bug in PR88702 and I see 54 transformations to happen in SPEC 2006. Apart from that, I fixed a minor issues which I spotted during bootstrap. Patch can bootstrap on x86_64-linux-gnu and survives regression tests. Ready to be installed? Thanks, Martin From a27dca2d5ef87b493d1ab50da68d0b24dc9fdd93 Mon Sep 17 00:00:00 2001 From: Martin Liska Date: Tue, 1 Dec 2020 12:18:46 +0100 Subject: [PATCH] if-to-switch: Support chain with 2 BBs. As seen in the test-case, even 2 BBs can handle interesting cases covered by a jump table or a bit-test. gcc/ChangeLog: PR tree-optimization/88702 * gimple-if-to-switch.cc (pass_if_to_switch::execute): Require at least 2 BBs. * gimple-if-to-switch.cc (find_conditions): Require equal precision for low and high of a range. gcc/testsuite/ChangeLog: PR tree-optimization/88702 * gcc.dg/tree-ssa/if-to-switch-9.c: New test. --- gcc/gimple-if-to-switch.cc | 6 ++++-- gcc/testsuite/gcc.dg/tree-ssa/if-to-switch-9.c | 11 +++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/if-to-switch-9.c diff --git a/gcc/gimple-if-to-switch.cc b/gcc/gimple-if-to-switch.cc index d132064fb9b..19ec6318229 100644 --- a/gcc/gimple-if-to-switch.cc +++ b/gcc/gimple-if-to-switch.cc @@ -430,7 +430,9 @@ find_conditions (basic_block bb, for (unsigned i = 0; i < info.m_ranges.length (); ++i) if (info.m_ranges[i].exp == NULL_TREE || info.m_ranges[i].low == NULL_TREE - || info.m_ranges[i].high == NULL_TREE) + || info.m_ranges[i].high == NULL_TREE + || (TYPE_PRECISION (TREE_TYPE (info.m_ranges[i].low)) + != TYPE_PRECISION (TREE_TYPE (info.m_ranges[i].high)))) return; for (unsigned i = 1; i < info.m_ranges.length (); ++i) @@ -525,7 +527,7 @@ pass_if_to_switch::execute (function *fun) } chain->m_entries.reverse (); - if (chain->m_entries.length () >= 3 + if (chain->m_entries.length () >= 2 && chain->check_non_overlapping_cases () && chain->is_beneficial ()) { diff --git a/gcc/testsuite/gcc.dg/tree-ssa/if-to-switch-9.c b/gcc/testsuite/gcc.dg/tree-ssa/if-to-switch-9.c new file mode 100644 index 00000000000..d0e9df75f55 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/if-to-switch-9.c @@ -0,0 +1,11 @@ +/* PR tree-optimization/88702 */ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-iftoswitch-optimized" } */ + +int IsHTMLWhitespace(int aChar) { + return aChar == 0x0009 || aChar == 0x000A || + aChar == 0x000C || aChar == 0x000D || + aChar == 0x0020; +} + +/* { dg-final { scan-tree-dump "Condition chain with 2 BBs transformed into a switch statement." "iftoswitch" } } */ -- 2.29.2