public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [4.9] PR 62146
@ 2014-08-25 22:42 Easwaran Raman
  2014-08-27 23:00 ` Easwaran Raman
  2014-08-29 20:06 ` Jeff Law
  0 siblings, 2 replies; 7+ messages in thread
From: Easwaran Raman @ 2014-08-25 22:42 UTC (permalink / raw)
  To: GCC Patches; +Cc: Brooks Moses

[-- Attachment #1: Type: text/plain, Size: 1085 bytes --]

This patch deletes REG_EQUAL note when a src register is replaced by a
constant in an assignment. This is to prevent spurious equivalences
between the constant and the expression in the REG_EQUAL note. In the
bug reported in PR 62146, an assignment in one branch (which is
actually dead) of an IF statement has a REG_EQUAL note equating a
register with an expression. Conditional copy propagation replaces the
register with 0. The instruction is hoisted above the branch
subsequently and then the value 0 is equated with the expression in
the REG_EQUAL. Is this ok for 4.9 branch if all tests pass?

This patch looks applicable to trunk as well, but I don't have a test
case to reproduce the issue in trunk.


ChangeLog:

2014-08-25  Easwaran Raman  <eraman@google.com>

        PR rtl-optimization/62146
        * cprop.c (try_replace_reg): Remove REG_EQUAL note when a constant is
        propagated into the src of an assignment.

testsuite/ChangeLog

2014-08-25  Easwaran Raman  <eraman@google.com>

        PR rtl-optimization/62146
        * testsuite/g++.dg/opt/pr62146.C: New.

[-- Attachment #2: pr62146.patch --]
[-- Type: text/x-patch, Size: 1983 bytes --]

Index: gcc/testsuite/g++.dg/opt/pr62146.C
===================================================================
--- gcc/testsuite/g++.dg/opt/pr62146.C	(revision 0)
+++ gcc/testsuite/g++.dg/opt/pr62146.C	(revision 0)
@@ -0,0 +1,51 @@
+/* PR rtl-optimization/62146 */
+/* { dg-do compile } */
+/* { dg-options "-O2 " } */
+class F
+{
+public:
+    virtual ~ F ();
+};
+template < class CL > class G:public F
+{
+    int *member_;
+public:
+    G ( int *b): member_ (0)
+    {
+    }
+};
+
+class D
+{
+public:
+    template < class CL > void RegisterNonTagCallback (int,
+            void (CL::
+                  *p3) ())
+    {
+        InternalRegisterNonTag (p3 ? new G < CL > ( 0) : 0);
+    } void InternalRegisterNonTag (F *);
+};
+
+void fn1 ();
+class C1
+{
+    void  foo();
+    class TokenType
+    {
+    public:
+        void AddToken ()
+        {
+        }
+    };
+    C1::TokenType bar_t;
+};
+D a;
+void C1::foo()
+{
+    if (&bar_t)
+        fn1 ();
+    for (int i = 0; i < sizeof 0; ++i)
+        a.RegisterNonTagCallback (0, &TokenType::AddToken);
+}
+
+/* { dg-final { scan-assembler-not "mov.*_ZN2C19TokenType8AddTokenEv, .\\\(" } } */
Index: gcc/cprop.c
===================================================================
--- gcc/cprop.c	(revision 214472)
+++ gcc/cprop.c	(working copy)
@@ -790,8 +790,11 @@ try_replace_reg (rtx from, rtx to, rtx insn)
   /* REG_EQUAL may get simplified into register.
      We don't allow that. Remove that note. This code ought
      not to happen, because previous code ought to synthesize
-     reg-reg move, but be on the safe side.  */
-  if (note && REG_NOTE_KIND (note) == REG_EQUAL && REG_P (XEXP (note, 0)))
+     reg-reg move, but be on the safe side. The REG_EQUAL note is
+     also removed when the source is a constant.  */
+  if (note && REG_NOTE_KIND (note) == REG_EQUAL
+      && (REG_P (XEXP (note, 0))
+          || (set && CONSTANT_P (SET_SRC (set)))))
     remove_note (insn, note);
 
   return success;

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2014-09-05  2:35 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-08-25 22:42 [4.9] PR 62146 Easwaran Raman
2014-08-27 23:00 ` Easwaran Raman
2014-08-29 20:06 ` Jeff Law
2014-09-02 18:52   ` Easwaran Raman
2014-09-03 18:37     ` Jeff Law
2014-09-05  1:28       ` Easwaran Raman
2014-09-05  2:35         ` Jeff Law

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).