This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Fix PR84190
- From: Richard Biener <rguenther at suse dot de>
- To: gcc-patches at gcc dot gnu dot org
- Date: Fri, 16 Feb 2018 08:55:16 +0100 (CET)
- Subject: [PATCH] Fix PR84190
- Authentication-results: sourceware.org; auth=none
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" } }