http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53049
--- Comment #5 from Richard Guenther <rguenth at gcc dot gnu.org> 2012-04-20 09:20:44 UTC --- It's not easy to restrict movement in this case (and no other tree transform would bother). Consider sinking and void test2 (unsigned val, bool flag) { val = 65535U / val; __builtin_avr_cli(); if (flag) ivar = val; else ivar = 0; __builtin_avr_sei(); } then you'd get val = 65535U / val; sunk into the if() arm beause its unused on the else arm. On the GIMPLE leven we don't have something like a "scheduling barrier", we only have barriers for loads/stores. A "scheduling barrier" would need to be implemented by means of providing abnormal entry / exit to a basic-block, not sure if we'd want to go that way (but this is the only way that would make it "magically" work). So - you certainly could "fix" TER, but that would not fix the underlying problem of GIMPLE lacking a scheduling barrier which is what you appearantly are after at.