diff mbox series

if-to-switch: Support chain with 2 BBs.

Message ID a82e5f44-3b80-f4ae-046a-1c0bb752cbea@suse.cz
State New
Headers show
Series if-to-switch: Support chain with 2 BBs. | expand

Commit Message

Martin Liška Dec. 1, 2020, 1:57 p.m. UTC
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

Comments

Jeff Law Dec. 1, 2020, 10:14 p.m. UTC | #1
On 12/1/20 6:57 AM, Martin Liška wrote:
> 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
>
> 0001-if-to-switch-Support-chain-with-2-BBs.patch
>
> 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.
OK
jeff
diff mbox series

Patch

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