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
@@ -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 ())
{
new file mode 100644
@@ -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