diff options
author | Jakub Jelinek <jakub@redhat.com> | 2021-01-16 09:17:38 +0100 |
---|---|---|
committer | Jakub Jelinek <jakub@redhat.com> | 2021-01-16 09:20:29 +0100 |
commit | b673e7547fb95d1f0d5cd17ae9e3874742cade66 (patch) | |
tree | 902a5f562ddc765c1e4788ea54154f00aba50733 /gcc | |
parent | 2c356f221bbab29bf4d1626d161e0f584dddd600 (diff) | |
download | gcc-b673e7547fb95d1f0d5cd17ae9e3874742cade66.zip gcc-b673e7547fb95d1f0d5cd17ae9e3874742cade66.tar.gz gcc-b673e7547fb95d1f0d5cd17ae9e3874742cade66.tar.bz2 |
cd_dce: Return TODO_update_address_taken from last cd_dce [PR96271]
On the following testcase, handle_builtin_memcmp in the strlen pass folds
the memcmp into comparison of two MEM_REFs. But nothing triggers updating
of addressable vars afterwards, so even when the parameters are no longer
address taken, we force the parameters to stack and back anyway.
This patch causes TODO_update_address_taken to happen right before last forwprop
pass (at the end of last cd_dce), so after strlen1 too.
2021-01-16 Jakub Jelinek <jakub@redhat.com>
PR tree-optimization/96271
* passes.def: Pass false argument to first two pass_cd_dce
instances and true to last instance. Add comment that
last instance rewrites no longer addressed locals.
* tree-ssa-dce.c (pass_cd_dce): Add update_address_taken_p member and
initialize it.
(pass_cd_dce::set_pass_param): New method.
(pass_cd_dce::execute): Return TODO_update_address_taken from
last cd_dce instance.
* gcc.target/i386/pr96271.c: New test.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/passes.def | 8 | ||||
-rw-r--r-- | gcc/testsuite/gcc.target/i386/pr96271.c | 11 | ||||
-rw-r--r-- | gcc/tree-ssa-dce.c | 15 |
3 files changed, 29 insertions, 5 deletions
diff --git a/gcc/passes.def b/gcc/passes.def index c8e01ae..e9ed3c7 100644 --- a/gcc/passes.def +++ b/gcc/passes.def @@ -90,7 +90,7 @@ along with GCC; see the file COPYING3. If not see NEXT_PASS (pass_early_vrp); NEXT_PASS (pass_merge_phi); NEXT_PASS (pass_dse); - NEXT_PASS (pass_cd_dce); + NEXT_PASS (pass_cd_dce, false /* update_address_taken_p */); NEXT_PASS (pass_phiopt, true /* early_p */); NEXT_PASS (pass_modref); NEXT_PASS (pass_tail_recursion); @@ -272,7 +272,7 @@ along with GCC; see the file COPYING3. If not see NEXT_PASS (pass_loop_jam); /* All unswitching, final value replacement and splitting can expose empty loops. Remove them now. */ - NEXT_PASS (pass_cd_dce); + NEXT_PASS (pass_cd_dce, false /* update_address_taken_p */); NEXT_PASS (pass_iv_canon); NEXT_PASS (pass_loop_distribution); NEXT_PASS (pass_linterchange); @@ -336,7 +336,9 @@ along with GCC; see the file COPYING3. If not see NEXT_PASS (pass_copy_prop); NEXT_PASS (pass_warn_restrict); NEXT_PASS (pass_dse); - NEXT_PASS (pass_cd_dce); + NEXT_PASS (pass_cd_dce, true /* update_address_taken_p */); + /* After late CD DCE we rewrite no longer addressed locals into SSA + form if possible. */ NEXT_PASS (pass_forwprop); NEXT_PASS (pass_phiopt, false /* early_p */); NEXT_PASS (pass_fold_builtins); diff --git a/gcc/testsuite/gcc.target/i386/pr96271.c b/gcc/testsuite/gcc.target/i386/pr96271.c new file mode 100644 index 0000000..b916bd1 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr96271.c @@ -0,0 +1,11 @@ +/* PR tree-optimization/96271 */ +/* { dg-do compile } */ +/* { dg-options "-O2 -mtune=intel -msse2 -masm=att" } */ +/* { dg-final { scan-assembler "movq\t%xmm0, %r" { target { ! ia32 } } } } */ +/* { dg-final { scan-assembler "movq\t%xmm1, %r" { target { ! ia32 } } } } */ + +int +foo (double a, double b) +{ + return __builtin_memcmp (&a, &b, sizeof (double)) == 0; +} diff --git a/gcc/tree-ssa-dce.c b/gcc/tree-ssa-dce.c index 51d4fcb..c027230 100644 --- a/gcc/tree-ssa-dce.c +++ b/gcc/tree-ssa-dce.c @@ -1787,14 +1787,25 @@ class pass_cd_dce : public gimple_opt_pass { public: pass_cd_dce (gcc::context *ctxt) - : gimple_opt_pass (pass_data_cd_dce, ctxt) + : gimple_opt_pass (pass_data_cd_dce, ctxt), update_address_taken_p (false) {} /* opt_pass methods: */ opt_pass * clone () { return new pass_cd_dce (m_ctxt); } + void set_pass_param (unsigned n, bool param) + { + gcc_assert (n == 0); + update_address_taken_p = param; + } virtual bool gate (function *) { return flag_tree_dce != 0; } - virtual unsigned int execute (function *) { return tree_ssa_cd_dce (); } + virtual unsigned int execute (function *) + { + return (tree_ssa_cd_dce () + | (update_address_taken_p ? TODO_update_address_taken : 0)); + } +private: + bool update_address_taken_p; }; // class pass_cd_dce } // anon namespace |