From mboxrd@z Thu Jan 1 00:00:00 1970 From: dalej@apple.com To: gcc@gcc.gnu.org Subject: how to fix anti-optimization? Date: Wed, 12 Sep 2001 11:34:00 -0000 Message-id: <200109121834.LAA21595@scv1.apple.com> X-SW-Source: 2001-09/msg00478.html const double Prescale[] = { 3.0, 5.0 }; extern void bar(double, double); void foo () { bar(Prescale[0], Prescale[1]); } With -O1 or higher, gcc substitutes constants 3.0 and 5.0 for the array references. This isn't a win on targets where the extra copies of these constants have to go in memory; you get an extra copy of the constants in data space. Furthermore, on many targets, loading two FP constants individually requires computing two addresses, while loading them from the array requires only one address computation. I see that this substitution would gain if some other optimizations happened to be doable as a result, e.g. constant folding, but I don't know how to determine that. The substitution is done in the ARRAY_REF case of expr.c:expand_expr(). It looks like I could hack this by setting TREE_SIDE_EFFECTS on FP constants, but surely that's not the right way to do it. Any better ideas?