public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "glisse at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/64601] Missed PRE on std::vector move assignment
Date: Fri, 16 Jan 2015 09:52:00 -0000	[thread overview]
Message-ID: <bug-64601-4-573aTzsDYW@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-64601-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #7 from Marc Glisse <glisse at gcc dot gnu.org> ---
I am testing the following hack, I hope there will be at least 1 failure in the
testsuite that will help me understand why it is wrong. It bootstraps and gives
accesses like MEM[(struct _Vector_impl *)v_4(D)]._M_start.

> struct B { int i; int j; };
> struct B b;
> int *p = &((struct A *)&b)->i;
> *p = 0;

Hmmm, yeah, that's ugly... I wish it weren't legal... I'll have to play with it
to see exactly how bad it is... Thanks for the example.

--- tree-ssa-forwprop.c    (revision 219694)
+++ tree-ssa-forwprop.c    (working copy)
@@ -777,20 +777,41 @@ forward_propagate_addr_expr_1 (tree name
                     new_def_rhs);
       else if (is_gimple_min_invariant (new_def_rhs))
     gimple_assign_set_rhs_with_ops (use_stmt_gsi, NOP_EXPR, new_def_rhs);
       else
     return false;
       gcc_assert (gsi_stmt (*use_stmt_gsi) == use_stmt);
       update_stmt (use_stmt);
       return true;
     }

+  /* *&X -> X.  */
+  if (TREE_CODE (lhs) == MEM_REF
+      && TREE_OPERAND (lhs, 0) == name
+      && integer_zerop (TREE_OPERAND (lhs, 1))
+      && useless_type_conversion_p (TREE_TYPE (lhs),
+                    TREE_TYPE (TREE_OPERAND (def_rhs, 0))))
+    {
+      gimple_assign_set_lhs (use_stmt, unshare_expr (TREE_OPERAND (def_rhs,
0)));
+      tidy_after_forward_propagate_addr (use_stmt);
+      return true;
+    }
+  else if (TREE_CODE (rhs) == MEM_REF
+      && TREE_OPERAND (rhs, 0) == name
+      && integer_zerop (TREE_OPERAND (rhs, 1))
+      && useless_type_conversion_p (TREE_TYPE (rhs),
+                    TREE_TYPE (TREE_OPERAND (def_rhs, 0))))
+    {
+      gimple_assign_set_rhs1 (use_stmt, unshare_expr (TREE_OPERAND (def_rhs,
0)));
+      tidy_after_forward_propagate_addr (use_stmt);
+      return true;
+    }
   /* Now strip away any outer COMPONENT_REF/ARRAY_REF nodes from the LHS.
      ADDR_EXPR will not appear on the LHS.  */
   tree *lhsp = gimple_assign_lhs_ptr (use_stmt);
   while (handled_component_p (*lhsp))
     lhsp = &TREE_OPERAND (*lhsp, 0);
   lhs = *lhsp;

   /* Now see if the LHS node is a MEM_REF using NAME.  If so,
      propagate the ADDR_EXPR into the use of NAME and fold the result.  */
   if (TREE_CODE (lhs) == MEM_REF


  parent reply	other threads:[~2015-01-16  9:52 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-14 20:12 [Bug tree-optimization/64601] New: " glisse at gcc dot gnu.org
2015-01-15  9:44 ` [Bug tree-optimization/64601] " rguenth at gcc dot gnu.org
2015-01-15 19:53 ` glisse at gcc dot gnu.org
2015-01-15 22:37 ` glisse at gcc dot gnu.org
2015-01-16  9:25 ` rguenth at gcc dot gnu.org
2015-01-16  9:26 ` rguenth at gcc dot gnu.org
2015-01-16  9:39 ` rguenth at gcc dot gnu.org
2015-01-16  9:52 ` glisse at gcc dot gnu.org [this message]
2015-01-16 15:30 ` glisse at gcc dot gnu.org
2015-01-17 13:04 ` glisse at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-64601-4-573aTzsDYW@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).