public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "652023330028 at smail dot nju.edu.cn" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/113271] New: [Regression] Wrong code at -O1/2/3 since GCC-9 (could be due to wrong optimization) Date: Mon, 08 Jan 2024 12:08:35 +0000 [thread overview] Message-ID: <bug-113271-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113271 Bug ID: 113271 Summary: [Regression] Wrong code at -O1/2/3 since GCC-9 (could be due to wrong optimization) Product: gcc Version: 14.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: 652023330028 at smail dot nju.edu.cn Target Milestone: --- Hello, we note that gcc may introduce erroneous code due to optimization: https://godbolt.org/z/8vbn3KdqP #include <iostream> int a, b, c; void func() { a=-b; //std::cout<<-a<<std::endl; //Line 5 c=(a)/(-2147483647-1); } int main(){ b= -2147483647 - 1; func(); std::cout<<c; } The output of GCC-O0 is: 1 The output of GCC-O3 is: 0 If we uncomment the fifth line: #include <iostream> int a, b, c; void func() { a=-b; std::cout<<-a<<std::endl; //Line 5 c=(a)/(-2147483647-1); } int main(){ b= -2147483647 - 1; func(); std::cout<<c; } we get the correct output (GCC-O3): -2147483648 1 This issue is probably due to a bad optimization of "func" by gcc -O3: func(): mov DWORD PTR c[rip], 0 mov eax, DWORD PTR b[rip] neg eax mov DWORD PTR a[rip], eax ret Thank you very much for your time and effort! We look forward to hearing from you.
next reply other threads:[~2024-01-08 12:08 UTC|newest] Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top 2024-01-08 12:08 652023330028 at smail dot nju.edu.cn [this message] 2024-01-08 12:16 ` [Bug tree-optimization/113271] " jakub at gcc dot gnu.org 2024-01-09 6:14 ` xry111 at gcc dot gnu.org 2024-01-09 6:27 ` 652023330028 at smail dot nju.edu.cn
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-113271-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).