This is the mail archive of the gcc-bugs@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]

[Bug tree-optimization/29145] unsafe use of restrict qualifier



------- Comment #8 from dorit at il dot ibm dot com  2007-01-07 20:22 -------
I'm testing this patch, that makes us more conservative, and concludes that two
pointers don't overlap only if both are "based on" restricted pointers, with
"based on" trivially implemented as the pointer used in the reference itself.
In addition, we check that the declarations of both pointers are in the
parameter list of the same function (to be safe w.r.t the scope of the pointer
declarations). Looks like this should be safe enough?

Most of the vectorizer testcases still get vectorized with this patch. Two
testcases that don't, however, are - vect-[74,80].c, for which we need a bit
less trivial implementation of "based on". We can start with this conservative
implementation, switch this PR to a "missed optimization", and gradually work
on relaxing the restrictions as much as we can.


Index: tree-data-ref.c
===================================================================
--- tree-data-ref.c     (revision 120551)
+++ tree-data-ref.c     (working copy)
@@ -490,6 +490,7 @@
   tree addr_a = DR_BASE_ADDRESS (dra);
   tree addr_b = DR_BASE_ADDRESS (drb);
   tree type_a, type_b;
+  tree decl_a, decl_b;
   bool aliased;

   if (!addr_a || !addr_b)
@@ -547,14 +548,25 @@
     }

   /* An instruction writing through a restricted pointer is "independent" of
any
-     instruction reading or writing through a different pointer, in the same 
-     block/scope.  */
-  else if ((TYPE_RESTRICT (type_a) && !DR_IS_READ (dra))
-      || (TYPE_RESTRICT (type_b) && !DR_IS_READ (drb)))
+     instruction reading or writing through a different restricted pointer, 
+     in the same block/scope.  */
+  else if (TYPE_RESTRICT (type_a)
+          &&  TYPE_RESTRICT (type_b) 
+          && (!DR_IS_READ (drb) || !DR_IS_READ (dra))
+          && TREE_CODE (DR_BASE_ADDRESS (dra)) == SSA_NAME
+          && (decl_a = SSA_NAME_VAR (DR_BASE_ADDRESS (dra)))
+          && TREE_CODE (decl_a) == PARM_DECL
+          && TREE_CODE (DECL_CONTEXT (decl_a)) == FUNCTION_DECL
+          && TREE_CODE (DR_BASE_ADDRESS (drb)) == SSA_NAME
+          && (decl_b = SSA_NAME_VAR (DR_BASE_ADDRESS (drb)))
+          && TREE_CODE (decl_b) == PARM_DECL
+          && TREE_CODE (DECL_CONTEXT (decl_b)) == FUNCTION_DECL
+          && DECL_CONTEXT (decl_a) == DECL_CONTEXT (decl_b)) 
     { 
       *differ_p = true;
       return true;
     }
+
   return false;
 }


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29145


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