This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH, PR 42704] Do not remove scalar assignments in SRA


Hi,

SRA sometimes removes assignment statements when it knows that on the
RHS all live data (ranges that have stores to) have scalar
replacements.  This caused a verification issue PR 42704 when a
removal of a scalar load from uninitialized memory (and therefore
without any live data) resulted in an SSA_NAME without a definition.
(This actually happened in in dead code.)

This happens only in very rare cases (scalar accesses with
sub-accesses) and the statements are most likely to be eliminated
later on anyway so I believe the solution is simply not to do this if
the type of the assignment is is_gimple_reg_type.

Bootstrapped and tested on x86_64-linux.  OK for trunk?

Thanks,

Martin


2010-01-13  Martin Jambor  <mjambor@suse.cz>

	PR tree-optimization/42704
	* tree-sra.c (sra_modify_assign): Do not delete assignments of
	gimple register types.

	* testsuite/g++.dg/torture/pr42704.C: New test.

Index: mine/gcc/testsuite/g++.dg/torture/pr42704.C
===================================================================
--- /dev/null
+++ mine/gcc/testsuite/g++.dg/torture/pr42704.C
@@ -0,0 +1,44 @@
+/* { dg-do compile } */
+
+typedef int PRInt32;
+class nsTreeRows {
+    class Subtree { };
+    enum { kMaxDepth = 32 };
+    struct Link {
+        Subtree* mParent;
+        PRInt32 mChildIndex;
+        Link&         operator=(const Link& aLink) {
+            mParent = aLink.mParent;
+            mChildIndex = aLink.mChildIndex;
+        }
+    };
+    class iterator {
+        PRInt32 mTop;
+        PRInt32 mRowIndex;
+        Link mLink[kMaxDepth];
+    public:
+        iterator() : mTop(-1), mRowIndex(-1) { }
+        iterator& operator=(const iterator& aIterator);
+    };
+    Subtree*     EnsureSubtreeFor(Subtree* aParent, PRInt32 aChildIndex);
+    Subtree*     GetSubtreeFor(const Subtree* aParent,                  
+PRInt32 aChildIndex,                   PRInt32* aSubtreeSize = 0);
+    void     InvalidateCachedRow() {
+        mLastRow = iterator();
+    }
+    iterator mLastRow;
+};
+nsTreeRows::Subtree* nsTreeRows::EnsureSubtreeFor(Subtree* aParent,            
+                     PRInt32 aChildIndex) {
+    Subtree* subtree = GetSubtreeFor(aParent, aChildIndex);
+    if (! subtree) {
+        InvalidateCachedRow();
+    }
+}
+nsTreeRows::iterator& nsTreeRows::iterator::operator=(const iterator&
+aIterator) {
+    mTop = aIterator.mTop;
+    for (PRInt32 i = mTop;
+         i >= 0;
+         --i)         mLink[i] = aIterator.mLink[i];
+}
Index: mine/gcc/tree-sra.c
===================================================================
--- mine.orig/gcc/tree-sra.c
+++ mine/gcc/tree-sra.c
@@ -2533,7 +2533,11 @@ sra_modify_assign (gimple *stmt, gimple_
 	{
 	  if (access_has_children_p (racc))
 	    {
-	      if (!racc->grp_unscalarized_data)
+	      if (!racc->grp_unscalarized_data
+		  /* When this is a register-type assignment, the LHS is an
+		     SSA_NAME definition that we have to keep even when loading
+		     uninitialized data (PR 42704).  */
+		  && !is_gimple_reg_type (TREE_TYPE (lhs)))
 		{
 		  generate_subtree_copies (racc->first_child, lhs,
 					   racc->offset, 0, 0, gsi,


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]