[PATCH] no lowering of &a.b (and &a->b) in the C front-end
Andrew Pinski
pinskia@physics.uc.edu
Mon Aug 23 00:37:00 GMT 2004
On Aug 22, 2004, at 5:07 PM, Zack Weinberg wrote:
> Andrew Pinski <pinskia@physics.uc.edu> writes:
>
>> I found that both the C and C++ front-ends do lower &a.b into a +
>> offsetof(b,a) which is really not good for some optimizations which
>> can change the struct a into scaler values.
>>
>> This patch changes the C front-end so there is no lowering and fixes
>> a bug found in c_finish_return with the no lowering turned on.
>> Warning about returning a temporary which is true for &a->b.
>
> Can you give an example of code which is optimized better with your
> patch?
Yes, http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15262 which contains an
example where we miscompile at this point with -O3 before this patch
we would not optimize anything away in main but with it we can optimize
everything away and only have a return left. There are most likely
a huge number of C++ examples where this can help too because a huge
number of the C++ code usually returns references to fields in the
classes.
>
>> + addr2 = build1 (ADDR_EXPR, argtype, arg);
>> +
>> + if (!TREE_CONSTANT (addr) || TREE_CONSTANT (addr2))
>> + addr = addr2;
>
> Why isn't this
>
> if (!TREE_CONSTANT (addr))
> addr = build1 (ADDR_EXPR, argtype, arg);
>
> That avoids constructing a junk tree node in the majority of cases.
That is much better and I will test the patch with that fixed.
I was thinking about doing that but I got sidetracked on other stuff
so I could not test it.
Thanks,
Andrew Pinski
More information about the Gcc-patches
mailing list