re PR rtl-optimization/11381 (volatile memory access optimized away)
authorEric Botcazou <ebotcazou@libertysurf.fr>
Thu, 3 Jul 2003 07:30:03 +0000 (09:30 +0200)
committerEric Botcazou <ebotcazou@gcc.gnu.org>
Thu, 3 Jul 2003 07:30:03 +0000 (07:30 +0000)
PR optimization/11381
* simplify-rtx.c (simplify_relational_operation): Check that
two equal operands have no side-effects before simplifying
the comparison.

From-SVN: r68869

gcc/ChangeLog
gcc/simplify-rtx.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/i386-volatile-1.c [new file with mode: 0644]

index 7a29f36a60e391fe449cd14375904d68b04a21d2..b96942d042d144a316e1cbb33fed9b66b1562435 100644 (file)
@@ -1,3 +1,10 @@
+2003-07-03  Eric Botcazou  <ebotcazou@libertysurf.fr>
+
+       PR optimization/11381
+       * simplify-rtx.c (simplify_relational_operation): Check that
+       two equal operands have no side-effects before simplifying
+       the comparison.
+
 2003-07-02  Jeff Law  <law@redhat.com>
 
        * expr.c (do_store_flag): Remove special case folding for
index 132b3aba37555b679ac8c673868a9ee7677802ae..f49f53d66d8e54ccf69694fcbf2be3121c2ebfb6 100644 (file)
@@ -2220,8 +2220,10 @@ simplify_relational_operation (code, mode, op0, op1)
     return const0_rtx;
 
   /* For modes without NaNs, if the two operands are equal, we know the
-     result.  */
-  if (!HONOR_NANS (GET_MODE (trueop0)) && rtx_equal_p (trueop0, trueop1))
+     result except if they have side-effects.  */
+  if (! HONOR_NANS (GET_MODE (trueop0))
+      && rtx_equal_p (trueop0, trueop1)
+      && ! side_effects_p (trueop0))
     equal = 1, op0lt = 0, op0ltu = 0, op1lt = 0, op1ltu = 0;
 
   /* If the operands are floating-point constants, see if we can fold
index 78f0f595c6d35d271ac0178935dc6f94e1110ad7..e598f212e7d841825c9bc7b5eb01581a46a7e67e 100644 (file)
@@ -1,3 +1,7 @@
+2003-07-03  Eric Botcazou  <ebotcazou@libertysurf.fr>
+
+       * gcc.dg/i386-volatile-1.c: New test.
+
 2003-07-02  Nathan Sidwell  <nathan@codesourcery.com>
 
        PR c++/11072
diff --git a/gcc/testsuite/gcc.dg/i386-volatile-1.c b/gcc/testsuite/gcc.dg/i386-volatile-1.c
new file mode 100644 (file)
index 0000000..633ea50
--- /dev/null
@@ -0,0 +1,14 @@
+/* PR optimization/11381 */
+/* Originator: <tobias@ringstrom.mine.nu> */
+/* { dg-do compile { target i?86-*-* } } */
+/* { dg-options "-O" } */
+
+/* Verify that the comparison is not optimized away. */
+
+void foo(volatile unsigned int *vaddr)
+{
+  while (*vaddr != *vaddr)
+    ;
+}
+
+/* { dg-final { scan-assembler "cmp" } } */