Fix PR84190

Message ID alpine.LSU.2.20.1802160854290.18265@zhemvz.fhfr.qr
State New
Headers show
Series
  • Fix PR84190
Related show

Commit Message

Richard Biener Feb. 16, 2018, 7:55 a.m.
The following restores behavior of GCC 6 for volatile accesses of
automatic vars that do not have their address taken.

Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to trunk
and branch.

Richard.

2018-02-16  Richard Biener  <rguenther@suse.de>

	PR tree-optimization/84190
	* tree-ssa.c (non_rewritable_mem_ref_base): Do not touch
	volatile accesses if the decl isn't volatile.

	* g++.dg/torture/pr84190.C: New testcase.

Patch

Index: gcc/tree-ssa.c
===================================================================
--- gcc/tree-ssa.c	(revision 257620)
+++ gcc/tree-ssa.c	(working copy)
@@ -1427,7 +1427,8 @@  non_rewritable_mem_ref_base (tree ref)
       if (! DECL_P (decl))
 	return NULL_TREE;
       if (! is_gimple_reg_type (TREE_TYPE (base))
-	  || VOID_TYPE_P (TREE_TYPE (base)))
+	  || VOID_TYPE_P (TREE_TYPE (base))
+	  || TREE_THIS_VOLATILE (decl) != TREE_THIS_VOLATILE (base))
 	return decl;
       if ((TREE_CODE (TREE_TYPE (decl)) == VECTOR_TYPE
 	   || TREE_CODE (TREE_TYPE (decl)) == COMPLEX_TYPE)
Index: gcc/testsuite/g++.dg/torture/pr84190.C
===================================================================
--- gcc/testsuite/g++.dg/torture/pr84190.C	(nonexistent)
+++ gcc/testsuite/g++.dg/torture/pr84190.C	(working copy)
@@ -0,0 +1,20 @@ 
+// { dg-do compile }
+// For slim LTO there's no optimized dump
+// { dg-skip-if "" { *-*-* } { "-flto" } { "" } }
+// { dg-additional-options "-fdump-tree-optimized" }
+
+typedef double T;
+static int equalfn (volatile T* x, volatile T* y);
+T gx, gy;
+int main ()
+{
+  T x = gx, y = gy;
+  return equalfn (&x, &y);
+}
+static int equalfn (volatile T* x, volatile T* y)
+{
+  return (*x == *y);
+}
+
+// There should be exactly two volatile accesses (ignoring clobbers).
+// { dg-final { scan-tree-dump-times " ={v} \[^\{\]" 2 "optimized" } }