[backport from gcc-4.7/trunk ] gcc/ 2011-11-07 Sergey Ostanevich PR rtl-optimization/47698 * ifcvt.c (noce_operand_ok): Return false for mems with side effects. gcc/testsuite/ 2011-11-07 Sergey Ostanevich PR rtl-optimization/47698 * gcc.target/i386/47698.c: New test. --- gcc-4.6.2/gcc/ifcvt.c.~1~ 2010-12-14 01:23:40.000000000 +0100 +++ gcc-4.6.2/gcc/ifcvt.c 2011-11-19 15:32:00.000000000 +0100 @@ -2311,12 +2311,12 @@ noce_operand_ok (const_rtx op) { /* We special-case memories, so handle any of them with no address side effects. */ - if (MEM_P (op)) - return ! side_effects_p (XEXP (op, 0)); - if (side_effects_p (op)) return FALSE; + if (MEM_P (op)) + return ! side_effects_p (XEXP (op, 0)); + return ! may_trap_p (op); } --- gcc-4.6.2/gcc/testsuite/gcc.target/i386/47698.c.~1~ 1970-01-01 01:00:00.000000000 +0100 +++ gcc-4.6.2/gcc/testsuite/gcc.target/i386/47698.c 2011-11-19 15:32:00.000000000 +0100 @@ -0,0 +1,10 @@ +/* { dg-options "-Os" } */ +/* { dg-final { scan-assembler-not "cmov" } } */ + +extern volatile unsigned long mmio; +unsigned long foo(int cond) +{ + if (cond) + return mmio; + return 0; +}