aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorMartin Liska <mliska@suse.cz>2020-12-01 12:18:46 +0100
committerMartin Liska <mliska@suse.cz>2020-12-02 08:18:18 +0100
commitc961e94901eb793b1a18d431a1acf7f682eaf04f (patch)
treec29fc24b169c2851cc98e6dab952e02a116fd681 /gcc
parente4c02ce4ab6fce1148f4025360096f18764deadf (diff)
downloadgcc-c961e94901eb793b1a18d431a1acf7f682eaf04f.zip
gcc-c961e94901eb793b1a18d431a1acf7f682eaf04f.tar.gz
gcc-c961e94901eb793b1a18d431a1acf7f682eaf04f.tar.bz2
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.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/gimple-if-to-switch.cc6
-rw-r--r--gcc/testsuite/gcc.dg/tree-ssa/if-to-switch-9.c11
2 files changed, 15 insertions, 2 deletions
diff --git a/gcc/gimple-if-to-switch.cc b/gcc/gimple-if-to-switch.cc
index 0aa1b0e..8e1043a 100644
--- a/gcc/gimple-if-to-switch.cc
+++ b/gcc/gimple-if-to-switch.cc
@@ -431,7 +431,9 @@ find_conditions (basic_block bb,
if (info.m_ranges[i].exp == NULL_TREE
|| !INTEGRAL_TYPE_P (TREE_TYPE (info.m_ranges[i].exp))
|| 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)
@@ -526,7 +528,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 0000000..e67198b
--- /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 \[^\n\r]\* BBs transformed into a switch statement." "iftoswitch" } } */