public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "jakub at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/99091] constexpr variable evaluated at runtime Date: Sun, 14 Feb 2021 09:27:44 +0000 [thread overview] Message-ID: <bug-99091-4-jmuKl0oeYh@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-99091-4@http.gcc.gnu.org/bugzilla/> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99091 Jakub Jelinek <jakub at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |jakub at gcc dot gnu.org Component|c++ |tree-optimization --- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> --- I don't see anything wrong on that, the constexpr var is not evaluated at runtime, it has a constant initializer. So in the end it is static const int doy1[] = { 306, 337, 31, 61, 92, 122, 153, 184, 214, 245, 275 }; int foo1(int m) { return doy1[m]; } int foo2(int m) { static const int doy2[] = { 306, 337, 31, 61, 92, 122, 153, 184, 214, 245, 275 }; return doy2[m]; } int foo3(int m) { const int doy3[] = { 306, 337, 31, 61, 92, 122, 153, 184, 214, 245, 275 }; return doy3[m]; } and there is nothing C++ specific on it. The compiler may promote the doy3 variable from automatic variable into static variable if it can prove it is safe to do so (it would be unsafe e.g. if foo3 could be called recursively and compare the addresses of the var between the recursive invocations). GCC does that early (during gimplification) if the variable is not address taken, but the array reference implies address taking. And, especially for the original testcase where operator[] is overloaded, it really can't do better early, so we'd need an optimization that would promote automatic vars to static when possible later (e.g. after inlining) if it can prove it is safe to do so.
next prev parent reply other threads:[~2021-02-14 9:27 UTC|newest] Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-02-13 21:55 [Bug c++/99091] New: " barry.revzin at gmail dot com 2021-02-14 9:27 ` jakub at gcc dot gnu.org [this message] 2021-02-15 10:31 ` [Bug tree-optimization/99091] " jakub at gcc dot gnu.org 2021-08-28 22:56 ` [Bug tree-optimization/99091] local array not prompted to static pinskia at gcc dot gnu.org 2024-03-15 0:07 ` 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-99091-4-jmuKl0oeYh@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).