From 8821d0914c6c0679a76995f95e7b7cc38d258da3 Mon Sep 17 00:00:00 2001 From: Eric Botcazou Date: Thu, 3 Jul 2003 09:30:03 +0200 Subject: [PATCH] re PR rtl-optimization/11381 (volatile memory access optimized away) 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 | 7 +++++++ gcc/simplify-rtx.c | 6 ++++-- gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/gcc.dg/i386-volatile-1.c | 14 ++++++++++++++ 4 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/i386-volatile-1.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 7a29f36a60e3..b96942d042d1 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2003-07-03 Eric Botcazou + + 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 * expr.c (do_store_flag): Remove special case folding for diff --git a/gcc/simplify-rtx.c b/gcc/simplify-rtx.c index 132b3aba3755..f49f53d66d8e 100644 --- a/gcc/simplify-rtx.c +++ b/gcc/simplify-rtx.c @@ -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 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 78f0f595c6d3..e598f212e7d8 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2003-07-03 Eric Botcazou + + * gcc.dg/i386-volatile-1.c: New test. + 2003-07-02 Nathan Sidwell 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 index 000000000000..633ea5022ec9 --- /dev/null +++ b/gcc/testsuite/gcc.dg/i386-volatile-1.c @@ -0,0 +1,14 @@ +/* PR optimization/11381 */ +/* Originator: */ +/* { 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" } } */