public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Fix PR84190
@ 2018-02-16  7:55 Richard Biener
  0 siblings, 0 replies; only message in thread
From: Richard Biener @ 2018-02-16  7:55 UTC (permalink / raw)
  To: gcc-patches


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.

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" } }

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2018-02-16  7:55 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-16  7:55 [PATCH] Fix PR84190 Richard Biener

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