From: Martin Liska Date: Tue, 1 Dec 2020 11:18:46 +0000 (+0100) Subject: if-to-switch: Support chain with 2 BBs. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=c961e94901eb793b1a18d431a1acf7f682eaf04f;p=gcc.git 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. --- diff --git a/gcc/gimple-if-to-switch.cc b/gcc/gimple-if-to-switch.cc index 0aa1b0e4e7e..8e1043ae7c4 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 00000000000..e67198bf8c3 --- /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" } } */