From d81e058f5ed20929bfee40fd281e39c80d7fd9e0 Mon Sep 17 00:00:00 2001 From: Martin Liska Date: Tue, 8 Aug 2017 13:59:23 +0200 Subject: [PATCH] ICF: properly handle LABEL_DECLs (PR tree-opt/81696). 2017-08-08 Martin Liska PR tree-opt/81696 * ipa-icf-gimple.c (func_checker::compare_cst_or_decl): Consider LABEL_DECLs that can be from a different function. 2017-08-08 Martin Liska PR tree-opt/81696 * gcc.dg/ipa/pr81696.c: New test. From-SVN: r250951 --- gcc/ChangeLog | 6 ++++++ gcc/ipa-icf-gimple.c | 6 +++++- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.dg/ipa/pr81696.c | 26 ++++++++++++++++++++++++++ 4 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/ipa/pr81696.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index d830fd65c12..a5dd5029f87 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2017-08-08 Martin Liska + + PR tree-opt/81696 + * ipa-icf-gimple.c (func_checker::compare_cst_or_decl): Consider + LABEL_DECLs that can be from a different function. + 2017-08-08 Bin Cheng PR tree-optimization/81744 diff --git a/gcc/ipa-icf-gimple.c b/gcc/ipa-icf-gimple.c index 08dd980fdf3..f44a995f580 100644 --- a/gcc/ipa-icf-gimple.c +++ b/gcc/ipa-icf-gimple.c @@ -361,10 +361,14 @@ func_checker::compare_cst_or_decl (tree t1, tree t2) } case LABEL_DECL: { + if (t1 == t2) + return true; + int *bb1 = m_label_bb_map.get (t1); int *bb2 = m_label_bb_map.get (t2); - return return_with_debug (*bb1 == *bb2); + /* Labels can point to another function (non-local GOTOs). */ + return return_with_debug (bb1 != NULL && bb2 != NULL && *bb1 == *bb2); } case PARM_DECL: case RESULT_DECL: diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 211e629fda3..360bb030d66 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2017-08-08 Martin Liska + + PR tree-opt/81696 + * gcc.dg/ipa/pr81696.c: New test. + 2017-08-08 Bin Cheng PR tree-optimization/81744 diff --git a/gcc/testsuite/gcc.dg/ipa/pr81696.c b/gcc/testsuite/gcc.dg/ipa/pr81696.c new file mode 100644 index 00000000000..2d3d63ff0bb --- /dev/null +++ b/gcc/testsuite/gcc.dg/ipa/pr81696.c @@ -0,0 +1,26 @@ +/* { dg-options "-O2 -fdump-ipa-icf-details" } */ + +int +main (int argc, char **argv) +{ + __label__ lab4, lab5, lab6; + + void foo (void) { goto lab4; } + void foo2 (void) { goto lab4; } + void bar (void) { goto lab5; } + void baz (void) { goto lab6; } + + if (argc) + foo (); + else + foo2 (); + + lab4:; + bar (); + lab5:; + baz (); + lab6:; + return 0; +} + +/* { dg-final { scan-ipa-dump "Equal symbols: 1" "icf" } } */ -- 2.30.2