[Bug tree-optimization/82991] memcpy and strcpy return value can be assumed to be equal to first argument

rguenth at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Tue Nov 21 15:33:00 GMT 2017


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82991

--- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> ---
Found it (old tree):

Index: tree-ssa-sccvn.c
===================================================================
--- tree-ssa-sccvn.c    (revision 254072)
+++ tree-ssa-sccvn.c    (working copy)
@@ -4123,6 +4234,25 @@ visit_use (tree use)
              changed = defs_to_varying (call_stmt);
              goto done;
            }
+
+         int rflags = gimple_call_return_flags (call_stmt);
+         if (rflags & ERF_RETURNS_ARG)
+           {
+             unsigned argnum = rflags & ERF_RETURN_ARG_MASK;
+             if (argnum < gimple_call_num_args (call_stmt))
+               {
+                 tree arg = gimple_call_arg (call_stmt, argnum);
+                 if (TREE_CODE (arg) == SSA_NAME
+                     /*|| is_gimple_min_invariant (arg)*/)
+                   {
+                     changed = visit_copy (lhs, arg);
+                     if (gimple_vdef (call_stmt))
+                       changed |= set_ssa_val_to (gimple_vdef (call_stmt),
+                                                  gimple_vdef (call_stmt));
+                     goto done;
+                   }
+               }
+           }
        }

       /* Pick up flags from a devirtualization target.  */
Index: tree-ssa-pre.c
===================================================================
--- tree-ssa-pre.c      (revision 254072)
+++ tree-ssa-pre.c      (working copy)
@@ -4309,6 +4369,14 @@ eliminate_dom_walker::before_dom_childre
                eliminate_push_avail (sprime);
            }

+         /* While we might have value numbered a call return value to
+            one of its arguments the call itself might not be solely
+            represented by its return value.  Thus do not ignore
+            side-effects indicated by a VARYING vdef.  */
+         if (gimple_vdef (stmt)
+             && VN_INFO (gimple_vdef (stmt))->valnum == gimple_vdef (stmt))
+           sprime = NULL_TREE;
+
          /* If this now constitutes a copy duplicate points-to
             and range info appropriately.  This is especially
             important for inserted code.  See tree-ssa-copy.c


More information about the Gcc-bugs mailing list