https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106078
Bug ID: 106078 Summary: Invalid loop invariant motion with non-call-exceptions Product: gcc Version: 13.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: middle-end Assignee: unassigned at gcc dot gnu.org Reporter: hubicka at gcc dot gnu.org Target Milestone: --- Here I think it is invalid to move *b out of the loop with -fnon-call-exceptions: int array[10000]; int test(short *b,int e, int f) { for (int i = 0; i<10000;i++) { e/=f; array[i]+=*b+e; } } jan@localhost:~> more t.s .text .file "t.c" .globl _Z4testPsii # -- Begin function _Z4testPsii .p2align 4, 0x90 .type _Z4testPsii,@function _Z4testPsii: # @_Z4testPsii .cfi_startproc # %bb.0: movl %edx, %ecx movl %esi, %eax movswl (%rdi), %esi xorl %edi, %edi .p2align 4, 0x90 .LBB0_1: # =>This Inner Loop Header: Depth=1 cltd idivl %ecx movl %eax, %edx addl %esi, %edx addl %edx, array(,%rdi,4) addq $1, %rdi jmp .LBB0_1 .Lfunc_end0: compiled code will segfault instead dividing by zero.