]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-optimization/115278 - fix DSE in if-conversion wrt volatiles
authorRichard Biener <rguenther@suse.de>
Fri, 31 May 2024 08:14:25 +0000 (10:14 +0200)
committerRichard Biener <rguenther@suse.de>
Fri, 31 May 2024 12:12:35 +0000 (14:12 +0200)
The following adds the missing guard for volatile stores to the
embedded DSE in the loop if-conversion pass.

PR tree-optimization/115278
* tree-if-conv.cc (ifcvt_local_dce): Do not DSE volatile stores.

* g++.dg/vect/pr115278.cc: New testcase.

gcc/testsuite/g++.dg/vect/pr115278.cc [new file with mode: 0644]
gcc/tree-if-conv.cc

diff --git a/gcc/testsuite/g++.dg/vect/pr115278.cc b/gcc/testsuite/g++.dg/vect/pr115278.cc
new file mode 100644 (file)
index 0000000..331075f
--- /dev/null
@@ -0,0 +1,38 @@
+// { dg-do compile }
+// { dg-require-effective-target c++11 }
+// { dg-additional-options "-fdump-tree-optimized" }
+
+#include <cstdint>
+
+const int runs = 92;
+
+union BitfieldStructUnion {
+        struct {
+                uint64_t a : 17;
+        uint64_t padding: 39;
+                uint64_t b : 8;
+        } __attribute__((packed));
+
+        struct {
+                uint32_t value_low;
+                uint32_t value_high;
+        } __attribute__((packed));
+
+        BitfieldStructUnion(uint32_t value_low, uint32_t value_high) : value_low(value_low), value_high(value_high) {}
+};
+
+volatile uint32_t *WRITE = (volatile unsigned*)0x42;
+
+void buggy() {
+        for (int i = 0; i < runs; i++) {
+                BitfieldStructUnion rt{*WRITE, *WRITE};
+
+                rt.a = 99;
+                rt.b = 1;
+
+                *WRITE = rt.value_low;
+                *WRITE = rt.value_high;
+        }
+}
+
+// { dg-final { scan-tree-dump-times "\\\*WRITE\[^\r\n\]* ={v} " 2 "optimized" } }
index 09d99fb9ddac09006eb60a7408996306315d7abe..c4c3ed41a44708f10a2b60ef8280aa4f2019e8a9 100644 (file)
@@ -3381,7 +3381,9 @@ ifcvt_local_dce (class loop *loop)
       gimple_stmt_iterator gsiprev = gsi;
       gsi_prev (&gsiprev);
       stmt = gsi_stmt (gsi);
-      if (gimple_store_p (stmt) && gimple_vdef (stmt))
+      if (!gimple_has_volatile_ops (stmt)
+         && gimple_store_p (stmt)
+         && gimple_vdef (stmt))
        {
          tree lhs = gimple_get_lhs (stmt);
          ao_ref write;