On 08/30/2017 11:18 AM, Richard Biener wrote: > On Wed, Aug 30, 2017 at 11:12 AM, Martin Liška <mli...@suse.cz> wrote: >> Hi. >> >> Following patch compares also constraints of input and output operands of >> ASM statements. >> Patch can bootstrap on ppc64le-redhat-linux and survives regression tests. >> >> Ready to be installed? > > It's now no longer "compare_tree_list_operand" but compare_asm_constraint > where there's no need to walk TREE_CHAIN either.
Yep, it desires a refactoring. Is it fine for trunk? Martin > > So can you refactor this a bit? > >> Martin >> >> gcc/ChangeLog: >> >> 2017-08-28 Martin Liska <mli...@suse.cz> >> >> PR inline-asm/82001 >> * ipa-icf-gimple.c (func_checker::compare_tree_list_operand): >> Compare TREE_PURPOSE of asm inputs and outputs. >> >> gcc/testsuite/ChangeLog: >> >> 2017-08-28 Martin Liska <mli...@suse.cz> >> >> PR inline-asm/82001 >> * gcc.dg/ipa/pr82001.c: New test. >> --- >> gcc/ipa-icf-gimple.c | 10 ++++++++++ >> gcc/testsuite/gcc.dg/ipa/pr82001.c | 21 +++++++++++++++++++++ >> 2 files changed, 31 insertions(+) >> create mode 100644 gcc/testsuite/gcc.dg/ipa/pr82001.c >> >>
>From dbbbf807a5721cb14da95fddbfe9afc32cd60ce7 Mon Sep 17 00:00:00 2001 From: marxin <mli...@suse.cz> Date: Mon, 28 Aug 2017 13:57:07 +0200 Subject: [PATCH] Fix IPA ICF with ASM statements (PR inline-asm/82001). gcc/ChangeLog: 2017-08-28 Martin Liska <mli...@suse.cz> PR inline-asm/82001 * ipa-icf-gimple.c (func_checker::compare_tree_list_operand): Rename to ... (func_checker::compare_asm_inputs_outputs): ... this function. (func_checker::compare_gimple_asm): Use the function to compare also ASM constrains. * ipa-icf-gimple.h: Rename the function. gcc/testsuite/ChangeLog: 2017-08-28 Martin Liska <mli...@suse.cz> PR inline-asm/82001 * gcc.dg/ipa/pr82001.c: New test. --- gcc/ipa-icf-gimple.c | 19 +++++++++++++------ gcc/ipa-icf-gimple.h | 6 +++--- gcc/testsuite/gcc.dg/ipa/pr82001.c | 21 +++++++++++++++++++++ 3 files changed, 37 insertions(+), 9 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/ipa/pr82001.c diff --git a/gcc/ipa-icf-gimple.c b/gcc/ipa-icf-gimple.c index f44a995f580..b40dd8653b4 100644 --- a/gcc/ipa-icf-gimple.c +++ b/gcc/ipa-icf-gimple.c @@ -543,11 +543,8 @@ func_checker::compare_operand (tree t1, tree t2) } } -/* Compares two tree list operands T1 and T2 and returns true if these - two trees are semantically equivalent. */ - bool -func_checker::compare_tree_list_operand (tree t1, tree t2) +func_checker::compare_asm_inputs_outputs (tree t1, tree t2) { gcc_assert (TREE_CODE (t1) == TREE_LIST); gcc_assert (TREE_CODE (t2) == TREE_LIST); @@ -560,6 +557,16 @@ func_checker::compare_tree_list_operand (tree t1, tree t2) if (!compare_operand (TREE_VALUE (t1), TREE_VALUE (t2))) return return_false (); + tree p1 = TREE_PURPOSE (t1); + tree p2 = TREE_PURPOSE (t2); + + gcc_assert (TREE_CODE (p1) == TREE_LIST); + gcc_assert (TREE_CODE (p2) == TREE_LIST); + + if (strcmp (TREE_STRING_POINTER (TREE_VALUE (p1)), + TREE_STRING_POINTER (TREE_VALUE (p2))) != 0) + return return_false (); + t2 = TREE_CHAIN (t2); } @@ -1008,7 +1015,7 @@ func_checker::compare_gimple_asm (const gasm *g1, const gasm *g2) tree input1 = gimple_asm_input_op (g1, i); tree input2 = gimple_asm_input_op (g2, i); - if (!compare_tree_list_operand (input1, input2)) + if (!compare_asm_inputs_outputs (input1, input2)) return return_false_with_msg ("ASM input is different"); } @@ -1017,7 +1024,7 @@ func_checker::compare_gimple_asm (const gasm *g1, const gasm *g2) tree output1 = gimple_asm_output_op (g1, i); tree output2 = gimple_asm_output_op (g2, i); - if (!compare_tree_list_operand (output1, output2)) + if (!compare_asm_inputs_outputs (output1, output2)) return return_false_with_msg ("ASM output is different"); } diff --git a/gcc/ipa-icf-gimple.h b/gcc/ipa-icf-gimple.h index da904b5897e..7e69024165f 100644 --- a/gcc/ipa-icf-gimple.h +++ b/gcc/ipa-icf-gimple.h @@ -215,9 +215,9 @@ public: is returned. */ bool compare_operand (tree t1, tree t2); - /* Compares two tree list operands T1 and T2 and returns true if these - two trees are semantically equivalent. */ - bool compare_tree_list_operand (tree t1, tree t2); + /* Compares GIMPLE ASM inputs (or outputs) where we iterate tree chain + and compare both TREE_PURPOSEs and TREE_VALUEs. */ + bool compare_asm_inputs_outputs (tree t1, tree t2); /* Verifies that trees T1 and T2, representing function declarations are equivalent from perspective of ICF. */ diff --git a/gcc/testsuite/gcc.dg/ipa/pr82001.c b/gcc/testsuite/gcc.dg/ipa/pr82001.c new file mode 100644 index 00000000000..05e32b10ef5 --- /dev/null +++ b/gcc/testsuite/gcc.dg/ipa/pr82001.c @@ -0,0 +1,21 @@ +/* { dg-do compile { target i?86-*-* x86_64-*-* } } */ +/* { dg-options "-O2 -fdump-ipa-icf-details" } */ + +int +mullo (int a, int b) +{ + asm("mul %%edx # %%1 was %1" + : "+" + "a"(a), + "+d"(b)); + return a; +} + +int +mulhi (int a, int b) +{ + asm("mul %%edx # %%1 was %1" : "+d"(a), "+a"(b)); + return a; +} + +/* { dg-final { scan-ipa-dump "Equal symbols: 0" "icf" } } */ -- 2.14.1