public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "gcc at breakpoint dot cc" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug rtl-optimization/64294] New: invalid code, zero check gets optimized away Date: Fri, 12 Dec 2014 22:25:00 -0000 [thread overview] Message-ID: <bug-64294-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64294 Bug ID: 64294 Summary: invalid code, zero check gets optimized away Product: gcc Version: 4.9.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: rtl-optimization Assignee: unassigned at gcc dot gnu.org Reporter: gcc at breakpoint dot cc Created attachment 34272 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=34272&action=edit the testcase The testcase is a minimized / cut-out of some code which basically does: if (!backsize) exit(11); while(backsize--) { *ddst=*(ddst+backbytes); ddst++; } gcc somehow assumes that backsize can't get zero which it can. I added an 'asm volatile("labele:");' statement so the check can be easy spotted. At -O2 gcc produces: 0000020a <labele>: 20a: 8b 44 24 20 mov 0x20(%esp),%eax 20e: 66 90 xchg %ax,%ax 210: 0f b6 54 0d 00 movzbl 0x0(%ebp,%ecx,1),%edx 215: 83 c5 01 add $0x1,%ebp 218: 88 55 ff mov %dl,-0x1(%ebp) 21b: 39 e8 cmp %ebp,%eax 21d: 75 f1 jne 210 <labele+0x6> So it copies the first byte before checking for equal/zero. With -O1 instead: 0000028a <labele>: 28a: 85 f6 test %esi,%esi 28c: 75 0a jne 298 <labele+0xe> 28e: 83 ec 0c sub $0xc,%esp 291: 6a 0b push $0xb 293: e8 fc ff ff ff call 294 <labele+0xa> 294: R_386_PC32 exit 298: 8b 5c 24 10 mov 0x10(%esp),%ebx 29c: 8b 54 24 2c mov 0x2c(%esp),%edx 2a0: 0f b6 0c 13 movzbl (%ebx,%edx,1),%ecx 2a4: 88 0b mov %cl,(%ebx) 2a6: 83 c3 01 add $0x1,%ebx 2a9: 39 d8 cmp %ebx,%eax 2ab: 75 f3 jne 2a0 <labele+0x16> There is the 0 check withint the first two opcodes including the exit(0) statement.
next reply other threads:[~2014-12-12 22:25 UTC|newest] Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top 2014-12-12 22:25 gcc at breakpoint dot cc [this message] 2014-12-12 22:43 ` [Bug rtl-optimization/64294] " schwab@linux-m68k.org 2014-12-12 22:54 ` gcc at breakpoint dot cc 2014-12-13 20:58 ` gcc at breakpoint dot cc 2014-12-13 20:59 ` gcc at breakpoint dot cc 2014-12-13 21:12 ` gcc at breakpoint dot cc 2014-12-20 11:53 ` mikpelinux at gmail dot com 2014-12-20 14:30 ` gcc at breakpoint dot cc 2014-12-20 14:35 ` gcc at breakpoint dot cc 2014-12-20 15:24 ` mikpelinux at gmail dot com 2014-12-20 21:21 ` gcc at breakpoint dot cc
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-64294-4@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).