public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* how to fix anti-optimization?
@ 2001-09-12 11:34 dalej
  2001-09-12 15:14 ` Richard Henderson
  2001-09-13 10:50 ` David Edelsohn
  0 siblings, 2 replies; 8+ messages in thread
From: dalej @ 2001-09-12 11:34 UTC (permalink / raw)
  To: gcc

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?

^ permalink raw reply	[flat|nested] 8+ messages in thread
* Re:  how to fix anti-optimization?
@ 2001-09-14 15:27 Richard Kenner
  0 siblings, 0 replies; 8+ messages in thread
From: Richard Kenner @ 2001-09-14 15:27 UTC (permalink / raw)
  To: dalej; +Cc: gcc

    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.

Only if it's no more complex an expression.  Consider Prescale[0]*Prescale[1].
It's *much* faster to do the folding in that case.

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2001-09-14 15:27 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-09-12 11:34 how to fix anti-optimization? dalej
2001-09-12 15:14 ` Richard Henderson
2001-09-14 12:50   ` Dale Johannesen
2001-09-14 13:02     ` David Edelsohn
2001-09-14 13:36     ` Richard Henderson
2001-09-13 10:50 ` David Edelsohn
2001-09-13 11:03   ` Dale Johannesen
2001-09-14 15:27 Richard Kenner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).