From e6c5d9f0f586b303a4d292b42e1e8d705651f86c Mon Sep 17 00:00:00 2001 From: Martin Liska Date: Wed, 5 Sep 2018 13:28:49 +0200 Subject: [PATCH] Group switch cases in switch lowering (PR tree-optimization/87205). 2018-09-05 Martin Liska PR tree-optimization/87205 * tree-switch-conversion.c (pass_lower_switch::execute): Group cases for switch statements. 2018-09-05 Martin Liska PR tree-optimization/87205 * gcc.dg/tree-ssa/pr87205-2.c: New test. * gcc.dg/tree-ssa/pr87205.c: New test. From-SVN: r264124 --- gcc/ChangeLog | 6 ++++++ gcc/testsuite/ChangeLog | 6 ++++++ gcc/testsuite/gcc.dg/tree-ssa/pr87205-2.c | 18 ++++++++++++++++++ gcc/testsuite/gcc.dg/tree-ssa/pr87205.c | 21 +++++++++++++++++++++ gcc/tree-switch-conversion.c | 9 +++++++-- 5 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr87205-2.c create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr87205.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 47bc612b820..8386829287d 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2018-09-05 Martin Liska + + PR tree-optimization/87205 + * tree-switch-conversion.c (pass_lower_switch::execute): + Group cases for switch statements. + 2018-09-05 Richard Biener PR tree-optimization/87217 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 12bb8a29d89..fc40df045f4 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2018-09-05 Martin Liska + + PR tree-optimization/87205 + * gcc.dg/tree-ssa/pr87205-2.c: New test. + * gcc.dg/tree-ssa/pr87205.c: New test. + 2018-09-05 Richard Biener PR tree-optimization/87217 diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr87205-2.c b/gcc/testsuite/gcc.dg/tree-ssa/pr87205-2.c new file mode 100644 index 00000000000..fb1879ed71b --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr87205-2.c @@ -0,0 +1,18 @@ +/* { dg-options "-O2 -fdump-tree-optimized" } */ + +void f(int); +void h(unsigned i) +{ + switch (i) { + default: __builtin_unreachable(); + case 0: f(42); break; + case 1: f(42); break; + case 2: f(42); break; + case 3: f(42); break; + case 4: f(42); break; + case 5: f(42); break; + } +} + +/* { dg-final { scan-tree-dump-not "if" "optimized" } } */ +/* { dg-final { scan-tree-dump-not "switch" "optimized" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr87205.c b/gcc/testsuite/gcc.dg/tree-ssa/pr87205.c new file mode 100644 index 00000000000..129e60747e2 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr87205.c @@ -0,0 +1,21 @@ +/* { dg-options "-O2 -fdump-tree-optimized" } */ + +void f( int x ); + +void h( unsigned ix ) +{ + switch( ix ) + { + case 0: f(42); break; + case 1: f(42); break; + case 2: f(42); break; + case 3: f(42); break; + case 4: f(42); break; + case 5: f(42); break; + default: __builtin_unreachable(); + } +} + + +/* { dg-final { scan-tree-dump-not "if" "optimized" } } */ +/* { dg-final { scan-tree-dump-not "switch" "optimized" } } */ diff --git a/gcc/tree-switch-conversion.c b/gcc/tree-switch-conversion.c index 1f543b2ecc8..64169a6cd3d 100644 --- a/gcc/tree-switch-conversion.c +++ b/gcc/tree-switch-conversion.c @@ -2419,8 +2419,13 @@ pass_lower_switch::execute (function *fun) FOR_EACH_BB_FN (bb, fun) { gimple *stmt = last_stmt (bb); - if (stmt && gimple_code (stmt) == GIMPLE_SWITCH) - switch_statements.safe_push (stmt); + gswitch *swtch; + if (stmt && (swtch = dyn_cast (stmt))) + { + if (!O0) + group_case_labels_stmt (swtch); + switch_statements.safe_push (swtch); + } } for (unsigned i = 0; i < switch_statements.length (); i++) -- 2.30.2