This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: GCC aliasing rules: more aggressive than C99?
This optimization is usually done with whole program analysis (WPA) or
with function cloning or inlining -- e.g., 'i' is an address of a
local variable in inlined/cloned callsite ...
David
On Sun, Jan 3, 2010 at 3:19 PM, Joshua Haberman <jhaberman@gmail.com> wrote:
> By the way, here is one case I tested where I was surprised GCC was not
> more aggressive:
>
> ?extern void bar();
> ?int foo(int *i) {
> ? ?if(*i) bar();
> ? ?return *i;
> ?}
>
> With GCC 4.4.1 -O3 (Ubuntu, x86-64) this reloads *i if bar is called. ?I
> suppose you have to allow that either "i" or "*i" is accessible as a
> global. ?But this is a pretty big bummer, because it means that any
> function call forces reloads of any data that was read from a pointer.
> "restrict" doesn't help here, nor does "const". ?The only way to prevent
> these reloads is to manually read the data into stack variable(s):
>
> ?extern void bar();
> ?int foo(int *i) {
> ? ?int i_val = *i;
> ? ?if(i_val) bar();
> ? ?return i_val;
> ?}
>
> Josh
>
>