summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Liska <mliska@suse.cz>2020-11-09 14:26:04 +0100
committerMartin Liska <mliska@suse.cz>2020-11-16 10:54:29 +0100
commit5e303cdee1ff01e4b302ef2f913c0bdd84ab967e (patch)
tree3ecf62b09717cbf9318e2a62da0d74ca85cca855
parentd12603b746986554981f5ee220926a36a6cb6baf (diff)
downloadgcc-5e303cdee1ff01e4b302ef2f913c0bdd84ab967e.tar.gz
Prefer bit-test over the jump table.
gcc/ChangeLog: PR tree-optimization/97736 * tree-switch-conversion.c (switch_decision_tree::analyze_switch_statement): Prefer bit tests. gcc/testsuite/ChangeLog: PR tree-optimization/97736 * gcc.dg/tree-ssa/switch-1.c: Prefer bit tests. * g++.dg/tree-ssa/pr97736.C: New test.
-rw-r--r--gcc/testsuite/g++.dg/tree-ssa/pr97736.C12
-rw-r--r--gcc/testsuite/gcc.dg/tree-ssa/switch-1.c6
-rw-r--r--gcc/tree-switch-conversion.c10
3 files changed, 20 insertions, 8 deletions
diff --git a/gcc/testsuite/g++.dg/tree-ssa/pr97736.C b/gcc/testsuite/g++.dg/tree-ssa/pr97736.C
new file mode 100644
index 00000000000..bda77e7e165
--- /dev/null
+++ b/gcc/testsuite/g++.dg/tree-ssa/pr97736.C
@@ -0,0 +1,12 @@
+/* PR tree-optimization/97736 */
+/* { dg-do compile { target { { x86_64-*-* aarch64-*-* ia64-*-* powerpc64-*-* } && lp64 } } } */
+/* { dg-options "-O2 -fdump-tree-switchlower1" } */
+
+bool is_vowel(char c) {
+ switch (c)
+ case'a':case'e':case'i':case'o':case'u':
+ return true;
+ return false;
+}
+
+/* { dg-final { scan-tree-dump ";; GIMPLE switch case clusters: BT:97-117" "switchlower1" } } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/switch-1.c b/gcc/testsuite/gcc.dg/tree-ssa/switch-1.c
index 149687ca2bb..6f70c9de0c1 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/switch-1.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/switch-1.c
@@ -54,7 +54,7 @@ int foo3 (int x)
}
}
-/* { dg-final { scan-tree-dump ";; GIMPLE switch case clusters: JT:0-62" "switchlower1" } } */
+/* { dg-final { scan-tree-dump ";; GIMPLE switch case clusters: BT:0-62" "switchlower1" } } */
int foo4 (int x)
{
@@ -77,7 +77,7 @@ int foo4 (int x)
}
}
-/* { dg-final { scan-tree-dump ";; GIMPLE switch case clusters: -100 JT:10-62 600-700" "switchlower1" } } */
+/* { dg-final { scan-tree-dump ";; GIMPLE switch case clusters: -100 BT:10-62 600-700" "switchlower1" } } */
int foo5 (int x)
{
@@ -107,4 +107,4 @@ int foo5 (int x)
}
}
-/* { dg-final { scan-tree-dump ";; GIMPLE switch case clusters: JT:10-62 600-700 JT:1000-1021 111111" "switchlower1" } } */
+/* { dg-final { scan-tree-dump ";; GIMPLE switch case clusters: BT:10-62 600-700 JT:1000-1021 111111" "switchlower1" } } */
diff --git a/gcc/tree-switch-conversion.c b/gcc/tree-switch-conversion.c
index 426462e856b..a87a2a3cd15 100644
--- a/gcc/tree-switch-conversion.c
+++ b/gcc/tree-switch-conversion.c
@@ -1743,10 +1743,10 @@ switch_decision_tree::analyze_switch_statement ()
reset_out_edges_aux (m_switch);
- /* Find jump table clusters. */
- vec<cluster *> output = jump_table_cluster::find_jump_tables (clusters);
+ /* Find bit-test clusters. */
+ vec<cluster *> output = bit_test_cluster::find_bit_tests (clusters);
- /* Find bit test clusters. */
+ /* Find jump table clusters. */
vec<cluster *> output2;
auto_vec<cluster *> tmp;
output2.create (1);
@@ -1759,7 +1759,7 @@ switch_decision_tree::analyze_switch_statement ()
{
if (!tmp.is_empty ())
{
- vec<cluster *> n = bit_test_cluster::find_bit_tests (tmp);
+ vec<cluster *> n = jump_table_cluster::find_jump_tables (tmp);
output2.safe_splice (n);
n.release ();
tmp.truncate (0);
@@ -1773,7 +1773,7 @@ switch_decision_tree::analyze_switch_statement ()
/* We still can have a temporary vector to test. */
if (!tmp.is_empty ())
{
- vec<cluster *> n = bit_test_cluster::find_bit_tests (tmp);
+ vec<cluster *> n = jump_table_cluster::find_jump_tables (tmp);
output2.safe_splice (n);
n.release ();
}