From c961e94901eb793b1a18d431a1acf7f682eaf04f Mon Sep 17 00:00:00 2001 From: Martin Liska Date: Tue, 1 Dec 2020 12:18:46 +0100 Subject: 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 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'gcc/gimple-if-to-switch.cc') 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 ()) { -- cgit v1.1