[Bug c/99693] -O2 not move 'if' checks on const data outside the loops
rafal at bursig dot org
gcc-bugzilla@gcc.gnu.org
Mon Mar 22 09:43:33 GMT 2021
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99693
--- Comment #5 from rafal at bursig dot org ---
Additional when I use c++ variant of this code and throw exception in else then
in -O2 level the 'if' is removed outside loop:
typedef struct Update {
int m_update;
//...
} Update;
extern void antagonizer( Update * );
void antagonize(Update *data, unsigned int n)
{
int _update = data->m_update;
while(--n)
{
if (_update)
{
antagonizer( data );
} else throw std::runtime_error("error");
}
}
The asm looks like:
.LC0:
.string "error"
antagonize(Update*, unsigned int):
mov eax, DWORD PTR [rdi]
sub esi, 1
je .L12
push r12
push rbp
mov rbp, rdi
push rbx
mov ebx, esi
test eax, eax
je .L3
.L4:
mov rdi, rbp
call antagonizer(Update*)
sub ebx, 1
jne .L4
pop rbx
pop rbp
pop r12
ret
.L12:
ret
antagonize(Update*, unsigned int) [clone .cold]:
.L3:
mov edi, 16
call __cxa_allocate_exception
mov esi, OFFSET FLAT:.LC0
mov rdi, rax
mov rbp, rax
call std::runtime_error::runtime_error(char const*) [complete object
constructor]
mov edx, OFFSET FLAT:_ZNSt13runtime_errorD1Ev
mov esi, OFFSET FLAT:_ZTISt13runtime_error
mov rdi, rbp
call __cxa_throw
mov r12, rax
mov rdi, rbp
call __cxa_free_exception
mov rdi, r12
call _Unwind_Resume
when I comment the "else throw ..." then the if check return int loop
More information about the Gcc-bugs
mailing list