This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Fix PR optimization/11381
- From: Eric Botcazou <ebotcazou at libertysurf dot fr>
- To: gcc-patches at gcc dot gnu dot org
- Date: Wed, 2 Jul 2003 10:04:39 +0200
- Subject: [PATCH] Fix PR optimization/11381
Hi,
This is a regression from GCC 3.2.3, present on 3.3 branch and mainline.
The optimizer (more precisely, the RTL simplifier) may discard volatile
comparisons in some cases, because it forgets to check that the operands
have no side-effects. The fix is then straightforward.
Bootstrapped/regtested on i586-redhat-linux-gnu (3.3 branch except Ada). Ok
for mainline and 3.3 branch?
--
Eric Botcazou
2003-07-02 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 Eric Botcazou <ebotcazou@libertysurf.fr>
* gcc.dg/i386-volatile-1.c: New test.
Index: simplify-rtx.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/simplify-rtx.c,v
retrieving revision 1.126.4.2
diff -c -p -r1.126.4.2 simplify-rtx.c
*** simplify-rtx.c 11 Feb 2003 22:26:30 -0000 1.126.4.2
--- simplify-rtx.c 1 Jul 2003 18:15:33 -0000
*************** simplify_relational_operation (code, mod
*** 1973,1980 ****
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))
equal = 1, op0lt = 0, op0ltu = 0, op1lt = 0, op1ltu = 0;
/* If the operands are floating-point constants, see if we can fold
--- 1973,1982 ----
return const0_rtx;
/* For modes without NaNs, if the two operands are equal, we know the
! 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
/* 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" } } */