This fixes PR49018, ifcombine looks for side-effects but instead asks only gimple_has_volatile_ops. And gimple_has_side_effects disregards that volatile asms have side-effects. The function also doesn't handle all stmts gracefully so I fixed it as well as turning the asserts to checking asserts. Fixed as follows.
Bootstrap / regtest pending on x86_64-unknown-linux-gnu. Richard. 2011-05-18 Richard Guenther <rguent...@suse.de> PR tree-optimization/49018 * gimple.c (gimple_has_side_effects): Volatile asms have side-effects. * tree-ssa-ifcombine.c (bb_no_side_effects_p): Use gimple_has_side_effects. Index: gcc/gimple.c =================================================================== --- gcc/gimple.c (revision 173854) +++ gcc/gimple.c (working copy) @@ -2354,6 +2354,10 @@ gimple_has_side_effects (const_gimple s) if (gimple_has_volatile_ops (s)) return true; + if (gimple_code (s) == GIMPLE_ASM + && gimple_asm_volatile_p (s)) + return true; + if (is_gimple_call (s)) { unsigned nargs = gimple_call_num_args (s); @@ -2368,7 +2372,7 @@ gimple_has_side_effects (const_gimple s) if (gimple_call_lhs (s) && TREE_SIDE_EFFECTS (gimple_call_lhs (s))) { - gcc_assert (gimple_has_volatile_ops (s)); + gcc_checking_assert (gimple_has_volatile_ops (s)); return true; } @@ -2379,7 +2383,7 @@ gimple_has_side_effects (const_gimple s) for (i = 0; i < nargs; i++) if (TREE_SIDE_EFFECTS (gimple_call_arg (s, i))) { - gcc_assert (gimple_has_volatile_ops (s)); + gcc_checking_assert (gimple_has_volatile_ops (s)); return true; } @@ -2388,11 +2392,14 @@ gimple_has_side_effects (const_gimple s) else { for (i = 0; i < gimple_num_ops (s); i++) - if (TREE_SIDE_EFFECTS (gimple_op (s, i))) - { - gcc_assert (gimple_has_volatile_ops (s)); - return true; - } + { + tree op = gimple_op (s, i); + if (op && TREE_SIDE_EFFECTS (op)) + { + gcc_checking_assert (gimple_has_volatile_ops (s)); + return true; + } + } } return false; Index: gcc/tree-ssa-ifcombine.c =================================================================== --- gcc/tree-ssa-ifcombine.c (revision 173854) +++ gcc/tree-ssa-ifcombine.c (working copy) @@ -107,7 +107,7 @@ bb_no_side_effects_p (basic_block bb) { gimple stmt = gsi_stmt (gsi); - if (gimple_has_volatile_ops (stmt) + if (gimple_has_side_effects (stmt) || gimple_vuse (stmt)) return false; }