public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-3916] tree-optimization/111397 - missed copy propagation involving abnormal dest
@ 2023-09-13  8:22 Richard Biener
  0 siblings, 0 replies; only message in thread
From: Richard Biener @ 2023-09-13  8:22 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:92ea12ea99fce546772a40b7bbc2ea850db9b1be

commit r14-3916-g92ea12ea99fce546772a40b7bbc2ea850db9b1be
Author: Richard Biener <rguenther@suse.de>
Date:   Wed Sep 13 09:28:34 2023 +0200

    tree-optimization/111397 - missed copy propagation involving abnormal dest
    
    The following extends the previous enhancement to copy propagation
    involving abnormals.  We can easily replace abnormal uses by not
    abnormal uses and only need to preserve the abnormals in PHI arguments
    flowing in from abnormal edges.  This changes the may_propagate_copy
    argument indicating we are not propagating into a PHI node to indicate
    whether we know we are not propagating into a PHI argument from an
    abnormal PHI instead.
    
            PR tree-optimization/111397
            * tree-ssa-propagate.cc (may_propagate_copy): Change optional
            argument to specify whether the PHI destination doesn't flow in
            from an abnormal PHI.
            (propagate_value): Adjust.
            * tree-ssa-forwprop.cc (pass_forwprop::execute): Indicate abnormal
            PHI dest.
            * tree-ssa-sccvn.cc (eliminate_dom_walker::before_dom_children):
            Likewise.
            (process_bb): Likewise.
    
            * gcc.dg/uninit-pr111397.c: New testcase.

Diff:
---
 gcc/testsuite/gcc.dg/uninit-pr111397.c | 15 +++++++++++++++
 gcc/tree-ssa-forwprop.cc               |  2 +-
 gcc/tree-ssa-propagate.cc              | 20 +++++++++++++-------
 gcc/tree-ssa-sccvn.cc                  |  5 +++--
 4 files changed, 32 insertions(+), 10 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/uninit-pr111397.c b/gcc/testsuite/gcc.dg/uninit-pr111397.c
new file mode 100644
index 000000000000..ec12f9d642a6
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/uninit-pr111397.c
@@ -0,0 +1,15 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -Wuninitialized" } */
+
+int globalVar = 1;
+int __attribute__ ((__returns_twice__)) test_setjmpex(void *context);
+
+void testfn()
+{
+  int localVar = globalVar;
+  while (!localVar) {
+      test_setjmpex(__builtin_frame_address (0)); // { dg-bogus "uninitialized" }
+      if (globalVar)
+	break;
+  }
+}
diff --git a/gcc/tree-ssa-forwprop.cc b/gcc/tree-ssa-forwprop.cc
index 047f9237dd41..94ca47a9726d 100644
--- a/gcc/tree-ssa-forwprop.cc
+++ b/gcc/tree-ssa-forwprop.cc
@@ -4070,7 +4070,7 @@ pass_forwprop::execute (function *fun)
 	      continue;
 	    tree val = fwprop_ssa_val (arg);
 	    if (val != arg
-		&& may_propagate_copy (arg, val))
+		&& may_propagate_copy (arg, val, !(e->flags & EDGE_ABNORMAL)))
 	      propagate_value (use_p, val);
 	  }
 
diff --git a/gcc/tree-ssa-propagate.cc b/gcc/tree-ssa-propagate.cc
index cb68b419b8ce..a29c49328ad1 100644
--- a/gcc/tree-ssa-propagate.cc
+++ b/gcc/tree-ssa-propagate.cc
@@ -1032,11 +1032,12 @@ substitute_and_fold_engine::substitute_and_fold (basic_block block)
 
 
 /* Return true if we may propagate ORIG into DEST, false otherwise.
-   If DEST_NOT_PHI_ARG_P is true then assume the propagation does
-   not happen into a PHI argument which relaxes some constraints.  */
+   If DEST_NOT_ABNORMAL_PHI_EDGE_P is true then assume the propagation does
+   not happen into a PHI argument which flows in from an abnormal edge
+   which relaxes some constraints.  */
 
 bool
-may_propagate_copy (tree dest, tree orig, bool dest_not_phi_arg_p)
+may_propagate_copy (tree dest, tree orig, bool dest_not_abnormal_phi_edge_p)
 {
   tree type_d = TREE_TYPE (dest);
   tree type_o = TREE_TYPE (orig);
@@ -1056,9 +1057,9 @@ may_propagate_copy (tree dest, tree orig, bool dest_not_phi_arg_p)
 	   && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (orig))
     return false;
   /* Similarly if DEST flows in from an abnormal edge then the copy cannot be
-     propagated.  If we know we do not propagate into a PHI argument this
+     propagated.  If we know we do not propagate into such a PHI argument this
      does not apply.  */
-  else if (!dest_not_phi_arg_p
+  else if (!dest_not_abnormal_phi_edge_p
 	   && TREE_CODE (dest) == SSA_NAME
 	   && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (dest))
     return false;
@@ -1162,8 +1163,13 @@ void
 propagate_value (use_operand_p op_p, tree val)
 {
   if (flag_checking)
-    gcc_assert (may_propagate_copy (USE_FROM_PTR (op_p), val,
-				    !is_a <gphi *> (USE_STMT (op_p))));
+    {
+      bool ab = (is_a <gphi *> (USE_STMT (op_p))
+		 && (gimple_phi_arg_edge (as_a <gphi *> (USE_STMT (op_p)),
+					  PHI_ARG_INDEX_FROM_USE (op_p))
+		     ->flags & EDGE_ABNORMAL));
+      gcc_assert (may_propagate_copy (USE_FROM_PTR (op_p), val, !ab));
+    }
   replace_exp (op_p, val);
 }
 
diff --git a/gcc/tree-ssa-sccvn.cc b/gcc/tree-ssa-sccvn.cc
index d9487be302b8..1eaf5f6a3633 100644
--- a/gcc/tree-ssa-sccvn.cc
+++ b/gcc/tree-ssa-sccvn.cc
@@ -7399,7 +7399,8 @@ eliminate_dom_walker::before_dom_children (basic_block b)
 	      || virtual_operand_p (arg))
 	    continue;
 	  tree sprime = eliminate_avail (b, arg);
-	  if (sprime && may_propagate_copy (arg, sprime))
+	  if (sprime && may_propagate_copy (arg, sprime,
+					    !(e->flags & EDGE_ABNORMAL)))
 	    propagate_value (use_p, sprime);
 	}
 
@@ -8192,7 +8193,7 @@ process_bb (rpo_elim &avail, basic_block bb,
 					    arg);
 	  if (sprime
 	      && sprime != arg
-	      && may_propagate_copy (arg, sprime))
+	      && may_propagate_copy (arg, sprime, !(e->flags & EDGE_ABNORMAL)))
 	    propagate_value (use_p, sprime);
 	}

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-09-13  8:22 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-13  8:22 [gcc r14-3916] tree-optimization/111397 - missed copy propagation involving abnormal dest Richard Biener

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).