This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Fw: Possible missed optimization opportunity with const?
- From: Florian Weimer <fweimer at redhat dot com>
- To: Toshi Morita <tm314159 at yahoo dot com>
- Cc: "gcc-help at gcc dot gnu dot org" <gcc-help at gcc dot gnu dot org>
- Date: Thu, 1 Sep 2016 11:10:33 +0200
- Subject: Re: Fw: Possible missed optimization opportunity with const?
- Authentication-results: sourceware.org; auth=none
- References: <848378447.3130483.1472699334626.ref@mail.yahoo.com> <848378447.3130483.1472699334626@mail.yahoo.com>
On 09/01/2016 05:08 AM, Toshi Morita wrote:
Florian Weimer wrote:
On 08/31/2016 10:57 AM, Toshi Morita wrote:
However, if the definition of pfoo is changed to: const int * const pfoo = (const int * const 0x1234);
the optimization seems to fail:
The optimization is not valid in this case because the compiler cannot know that the object was declared const.
It could well be mutable.
Sorry, that should be:
const int * const pfoo = (const int * const)0x1234;
Yes, I assumed so, it does not make a difference.
So assuming this is still wrong, what is the correct way to define a pointer to a hardware register at 0x1234 which contains immutable data? I'm missing something here.
You need to use the original code, with the declaration of foo, and tell
the assembler or linker to place foo at an absolute address. This is
rather target-dependent.
Florian