public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Martin Liška" <mliska@suse.cz>
To: Richard Biener <richard.guenther@gmail.com>
Cc: David Malcolm <dmalcolm@redhat.com>,
	Jakub Jelinek <jakub@redhat.com>,
	GCC Patches <gcc-patches@gcc.gnu.org>,
	Jan Hubicka <hubicka@ucw.cz>
Subject: [PATCH] if-to-switch: Support chain with 2 BBs.
Date: Tue, 1 Dec 2020 14:57:19 +0100	[thread overview]
Message-ID: <a82e5f44-3b80-f4ae-046a-1c0bb752cbea@suse.cz> (raw)
In-Reply-To: <CAFiYyc1x_7toHZEFYzD15ixso9KZ84yne2a+HaUVMAvYgKxwMg@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 340 bytes --]

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

[-- Attachment #2: 0001-if-to-switch-Support-chain-with-2-BBs.patch --]
[-- Type: text/x-patch, Size: 2574 bytes --]

From a27dca2d5ef87b493d1ab50da68d0b24dc9fdd93 Mon Sep 17 00:00:00 2001
From: Martin Liska <mliska@suse.cz>
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


  reply	other threads:[~2020-12-01 13:57 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-04 14:23 [PATCH] Add if-chain to switch conversion pass Martin Liška
2019-11-04 14:49 ` Jakub Jelinek
2019-11-05 12:38   ` Richard Biener
2019-11-06 21:03     ` Bernhard Reutner-Fischer
2019-11-14  9:44       ` Martin Liška
2019-11-14 12:35         ` Bernhard Reutner-Fischer
2019-11-14  9:41     ` Martin Liška
2019-11-14 10:48       ` Richard Biener
2019-11-15 13:56         ` Martin Liška
2020-09-01 11:47           ` Martin Liška
2020-09-01 14:50             ` David Malcolm
2020-09-02 11:53               ` Martin Liška
2020-09-21  8:55                 ` Martin Liška
2020-09-24 12:41                 ` Richard Biener
2020-09-25 14:05                   ` Martin Liška
2020-09-29  8:46                     ` Richard Biener
2020-10-02 13:26                       ` Martin Liška
2020-10-02 14:19                         ` Andrew MacLeod
2020-10-06 12:09                           ` Martin Liška
2020-10-06 12:56                             ` Andrew MacLeod
2020-10-06 13:09                               ` Martin Liška
2020-10-06 13:23                                 ` Andrew MacLeod
2020-10-06 13:41                                 ` Richard Biener
2020-10-02 13:23                   ` Martin Liška
2020-10-06  7:47                     ` Richard Biener
2020-10-06 13:48                       ` Martin Liška
2020-10-06 14:12                         ` Jakub Jelinek
2020-10-12 12:39                           ` Martin Liška
2020-10-12 13:00                             ` Jakub Jelinek
2020-10-14 18:09                             ` Andrew MacLeod
2020-10-07  8:00                         ` Richard Biener
2020-10-12 12:44                           ` Martin Liška
2020-10-12 13:01                             ` Martin Liška
2020-10-15 12:38                               ` Richard Biener
2020-10-16 14:04                             ` [PATCH v2] " Martin Liška
2020-11-06 12:31                               ` Richard Biener
2020-11-09 12:26                                 ` Martin Liška
2020-11-16 12:21                                   ` Richard Biener
2020-11-18 12:25                                     ` Martin Liška
2020-11-19 14:46                                       ` Richard Biener
2020-11-20  8:57                                         ` Martin Liška
2020-11-20 14:37                                           ` Richard Biener
2020-11-27 15:07                                             ` Martin Liška
2020-12-01 10:34                                               ` Richard Biener
2020-12-01 13:57                                                 ` Martin Liška [this message]
2020-12-01 22:14                                                   ` [PATCH] if-to-switch: Support chain with 2 BBs Jeff Law
2019-11-13 11:32   ` [PATCH] Add if-chain to switch conversion pass Martin Liška
2019-11-13 16:14     ` Michael Matz
2019-11-14 10:07       ` Martin Liška

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a82e5f44-3b80-f4ae-046a-1c0bb752cbea@suse.cz \
    --to=mliska@suse.cz \
    --cc=dmalcolm@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=hubicka@ucw.cz \
    --cc=jakub@redhat.com \
    --cc=richard.guenther@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).