https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85859
Richard Biener <rguenth at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |NEW Last reconfirmed| |2018-05-22 Target Milestone|--- |6.5 Ever confirmed|0 |1 --- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> --- Confirmed. foo is discovered as 'const', it is nothrow anyways (-fno-exceptions) and thus overall it is considered not having side-effects (in particular not trap). Quoting tree-ssa-ifcombine.c: /* Verify if the basic block BB does not have side-effects. Return true in this case, else false. */ static bool bb_no_side_effects_p (basic_block bb) { gimple_stmt_iterator gsi; for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi)) { gimple *stmt = gsi_stmt (gsi); if (is_gimple_debug (stmt)) continue; if (gimple_has_side_effects (stmt) || gimple_uses_undefined_value_p (stmt) || gimple_could_trap_p (stmt) || gimple_vuse (stmt) /* const calls don't match any of the above, yet they could still have some side-effects - they could contain gimple_could_trap_p statements, like floating point exceptions or integer division by zero. See PR70586. FIXME: perhaps gimple_has_side_effects or gimple_could_trap_p should handle this. */ || is_gimple_call (stmt)) and it is ifcombine pulling the call out of conditional context.