public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "rafal at bursig dot org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c/99693] -O2 not move 'if' checks on const data outside the loops Date: Mon, 22 Mar 2021 09:43:33 +0000 [thread overview] Message-ID: <bug-99693-4-OHvE6DMBkM@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-99693-4@http.gcc.gnu.org/bugzilla/> 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
prev parent reply other threads:[~2021-03-22 9:43 UTC|newest] Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-03-21 12:07 [Bug c/99693] New: " rafal at bursig dot org 2021-03-21 12:28 ` [Bug c/99693] " rafal at bursig dot org 2021-03-21 16:41 ` pinskia at gcc dot gnu.org 2021-03-22 9:04 ` rguenth at gcc dot gnu.org 2021-03-22 9:23 ` rafal at bursig dot org 2021-03-22 9:43 ` rafal at bursig dot org [this message]
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-99693-4-OHvE6DMBkM@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).