public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "marc@nieper-wisskirchen.de" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/104574] New: GCC misses basic optimization for restricted pointers Date: Wed, 16 Feb 2022 18:54:59 +0000 [thread overview] Message-ID: <bug-104574-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104574 Bug ID: 104574 Summary: GCC misses basic optimization for restricted pointers Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: marc@nieper-wisskirchen.de Target Milestone: --- The following TU void g (void); int f (int *restrict p) { p[0] = 7; g (); return p[0]; } is compiled by GCC at -O3 to f: pushq %rbx movq %rdi, %rbx movl $7, (%rdi) call g movl (%rbx), %eax popq %rbx ret Obviously, GCC seems to think that g may modify the data reachable through p. However, if g did that it would cause undefined behavior anyway. So GCC misses a simple optimization opportunity here; it doesn't have to reload the memory contents after the call to g; in fact, the function will always return 7. For comparison, Clang compiles the TU to f: pushq %rax movl $7, (%rdi) callq g movl $7, %eax popq %rcx retq
next reply other threads:[~2022-02-16 18:54 UTC|newest] Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-02-16 18:54 marc@nieper-wisskirchen.de [this message] 2022-02-16 21:35 ` [Bug tree-optimization/104574] " pinskia at gcc dot gnu.org 2022-02-16 21:37 ` pinskia at gcc dot gnu.org
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-104574-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).