This is a follow-up from PR38819 which partially fixes this problem. The problem remains in RTL optimization passes, and can be triggered on targets that implement modulo instruction in the hardware (i.e. moxie-elf).
The testcase from PR38819 compiles with -O2 to: main: push $sp, $r6 push $sp, $r7 push $sp, $r8 push $sp, $r9 push $sp, $r10 push $sp, $r11 dec $sp, 24 lda.l $r7, a lda.l $r0, b xor $r6, $r6 ldi.l $r11, foo > mod.l $r7, $r0 ldi.l $r10, 8 ldi.l $r8, 99 jmpa .L4 .L3: ... Since b is initialized to zero, mod.l instruction traps. -- Summary: RTL PRE GCSE pass hoists trapping insn out of loop Product: gcc Version: 4.5.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: rtl-optimization AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: ubizjak at gmail dot com GCC target triplet: moxie-elf http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45223