[PATCH] Implement malloc/free hoisting from loops (PR21046 and friends)
Paolo Bonzini
bonzini@gnu.org
Fri May 14 11:55:00 GMT 2010
On 05/14/2010 01:32 PM, Richard Guenther wrote:
> I wouldn't be totally against something alongside -funsafe-math-optimizations
> for non-math code - like -fno-preserve-side-effects (with -fpreserve-
> side-effects being the default).
I think that at least for now -fno-builtin-malloc is enough (and
-fno-builtin-free too maybe in the case of this particular optimization).
"Preserving side effects" anyway is ill-defined: for example, how is
printf->puts "less side effecting" than hoisting malloc/free? The only
sensible definition for me is "disable all optimizations of
non-const/non-pure builtins", and in this case you most certainly want
the default to be -fno-preserve-side-effects.
> This would for example
> allow us to even remove pairs of malloc/free calls that are unused,
> removing the side-effect of eventually setting errno.
Whether malloc (1 << 40) fails is not defined, so the user cannot expect
setting errno to ENOMEM. They could of course expect errno to be set if
malloc returns NULL; however, if you can remove the pair then the user
never looked at the return code of malloc and the as-if rule can be
applied. So there is no need for a new switch, -fno-builtin-malloc
suffices.
Paolo
More information about the Gcc-patches
mailing list