[PATCH] strlen: Return TODO_update_address_taken when memcmp has been optimized [PR96271]

Jakub Jelinek jakub@redhat.com
Fri Jan 15 21:02:41 GMT 2021


On Fri, Jan 15, 2021 at 09:31:10PM +0100, Jakub Jelinek via Gcc-patches wrote:
> On Fri, Jan 15, 2021 at 09:16:31PM +0100, Richard Biener wrote:
> > >Apparently not.  The passes after strlen1 are:
> > >pr96271.c.191t.thread4
> > >pr96271.c.192t.vrp2
> > >pr96271.c.193t.copyprop5
> > >pr96271.c.194t.wrestrict
> > >pr96271.c.195t.dse4
> > >pr96271.c.196t.cddce3
> > >pr96271.c.197t.forwprop4
> > >pr96271.c.198t.phiopt4
> > >pr96271.c.199t.fab1
> > >pr96271.c.200t.widening_mul
> > >pr96271.c.201t.store-merging
> > >pr96271.c.202t.tailc
> > >pr96271.c.203t.dce7
> > >pr96271.c.204t.crited1
> > >pr96271.c.206t.uncprop1
> > >pr96271.c.207t.local-pure-const2
> > >pr96271.c.208t.modref2
> > >pr96271.c.242t.nrv
> > >pr96271.c.243t.isel
> > >pr96271.c.244t.optimized
> > >and TODO_update_address_taken is used by the inliner, sra, ccp, loop
> > >and
> > >sccvn, so maybe in fre5 in 187.
> > 
> > OK, I think it makes sense to delay until before forwprop4 so can you instead arrange for an unconditional run there? 
> 
> At the end of forwprop4 or start (i.e. end of previous pass)?

Like this?

2021-01-15  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.
	(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.

--- gcc/passes.def.jj	2021-01-04 10:25:38.826233904 +0100
+++ gcc/passes.def	2021-01-15 21:55:24.431629359 +0100
@@ -90,7 +90,7 @@ along with GCC; see the file COPYING3.
 	  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.
 	  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.
       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);
--- gcc/tree-ssa-dce.c.jj	2021-01-12 11:01:51.283385011 +0100
+++ gcc/tree-ssa-dce.c	2021-01-15 21:54:19.016368431 +0100
@@ -1787,14 +1787,25 @@ class pass_cd_dce : public gimple_opt_pa
 {
 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
--- gcc/testsuite/gcc.target/i386/pr96271.c.jj	2021-01-15 21:56:03.067192848 +0100
+++ gcc/testsuite/gcc.target/i386/pr96271.c	2021-01-15 21:56:03.067192848 +0100
@@ -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;
+}


	Jakub



More information about the Gcc-patches mailing list