re PR tree-optimization/91812 (GCC ignores volatile modifier)
authorRichard Biener <rguenther@suse.de>
Thu, 19 Sep 2019 12:49:45 +0000 (12:49 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Thu, 19 Sep 2019 12:49:45 +0000 (12:49 +0000)
2019-09-19  Richard Biener  <rguenther@suse.de>

PR tree-optimization/91812
* tree-ssa-phiprop.c (propagate_with_phi): Do not replace
volatile loads.

* gcc.dg/torture/pr91812.c: New testcase.

From-SVN: r275960

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/torture/pr91812.c [new file with mode: 0644]
gcc/tree-ssa-phiprop.c

index c51b6f65720bb24d52ebf713c05b8d711f3e3d2e..1810fe92af02b5c2fa7fed0f3dc4018435517a65 100644 (file)
@@ -1,3 +1,9 @@
+2019-09-19  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/91812
+       * tree-ssa-phiprop.c (propagate_with_phi): Do not replace
+       volatile loads.
+
 2019-09-19  Richard Sandiford  <richard.sandiford@arm.com>
 
        * defaults.h (TARGET_UNIT): New macro.
index 07adb119850ba0d9d85833ad7993f272b7216629..c5854bd363dc77a629b362d98a8f78f19bcd6ea8 100644 (file)
@@ -1,3 +1,8 @@
+2019-09-19  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/91812
+       * gcc.dg/torture/pr91812.c: New testcase.
+
 2019-09-19  Tom Tromey  <tromey@adacore.com>
 
        * gnat.dg/bias1.adb: New testcase.
diff --git a/gcc/testsuite/gcc.dg/torture/pr91812.c b/gcc/testsuite/gcc.dg/torture/pr91812.c
new file mode 100644 (file)
index 0000000..ebc67a0
--- /dev/null
@@ -0,0 +1,26 @@
+/* { dg-do compile } */
+/* { dg-skip-if "" { *-*-* } { "-fno-fat-lto-objects" } { "" } } */
+/* { dg-options "-fdump-tree-optimized-blocks" } */
+
+unsigned register1;
+unsigned register2;
+
+void busy_wait_for_register (int x)
+{
+  volatile unsigned* ptr;
+  switch(x) {
+    case 0x1111:
+    ptr = &register1;
+    break;
+
+    case 0x2222:
+    ptr = &register2;
+    break;
+
+    default:
+    return;
+  }
+  while (*ptr) {}
+}
+
+/* { dg-final { scan-tree-dump "loop depth 1" "optimized" } } */
index d710582a915e417e6d6ee698076942dae3babca6..e90ae6a89cb5196267f3836f85a46311aa2c6e06 100644 (file)
@@ -338,8 +338,15 @@ propagate_with_phi (basic_block bb, gphi *phi, struct phiprop_d *phivn,
            && (!type
                || types_compatible_p
                     (TREE_TYPE (gimple_assign_lhs (use_stmt)), type))
-           /* We cannot replace a load that may throw or is volatile.  */
-           && !stmt_can_throw_internal (cfun, use_stmt)))
+           /* We cannot replace a load that may throw or is volatile.
+              For volatiles the transform can change the number of
+              executions if the load is inside a loop but the address
+              computations outside (PR91812).  We could relax this
+              if we guard against that appropriately.  For loads that can
+              throw we could relax things if the moved loads all are
+              known to not throw.  */
+           && !stmt_can_throw_internal (cfun, use_stmt)
+           && !gimple_has_volatile_ops (use_stmt)))
        continue;
 
       /* Check if we can move the loads.  The def stmt of the virtual use