public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: Reassociation
@ 1998-12-19  5:30 Stephen L Moshier
  1998-12-20 15:36 ` Reassociation Richard Henderson
  0 siblings, 1 reply; 13+ messages in thread
From: Stephen L Moshier @ 1998-12-19  5:30 UTC (permalink / raw)
  To: law, egcs

    Some languages (ie fortran) allow reassociation as long as we honor
    paren boundaries.  We need some way to find those boundaries.  How do
    you suggest we find them?

By looking at the rtl.  For example, in the rtl for a*b*c*d all the
set destinations are the same, a giveaway that the parentheses were
omitted.  I suggest asking Wilson about this; he would probably know
whether this is a feasible plan in general.


    See fold-const.c  It does most of the same transformations on trees
    that cse.c is doing on RTL.

That's fine, but the optimizations in point are now being squelched
specifically in cse.c.

^ permalink raw reply	[flat|nested] 13+ messages in thread
* RE: REASSOCIATION
@ 1998-12-17 14:26 tprince
  1998-12-17 18:26 ` REASSOCIATION Joern Rennecke
  0 siblings, 1 reply; 13+ messages in thread
From: tprince @ 1998-12-17 14:26 UTC (permalink / raw)
  To: bosch, burley, egcs, hjstein, jbuck, law, moshier

>>While I agree that the front end needs a way to tell the
backend
about what it can and can't optimize, I'm not sure parens in the
tree are the best way to do this.  (I've not been able to think this
completely through, and so it may be bunk, but I wanted to say
something
before I forgot.)<<

Not that I care about implementation details, but it probably
doesn't need a new mechanism.  The same code generation
should come about whether it's written

(a*b)*c)*d

or (too clumsily for normal source code, but the way it was done
in K&R C)

temp= a * b
temp *= c
temp * d

with the reassociation being permitted only when neither
parentheses nor assignments intervene.

>>  Do we need separate flags
for each kind of side effect (care-about-overflow,
dont-care-about-underflow)?<<

Not AFAIK for C or Fortran based languages.  What we're talking
about is the ability to let the programmer choose between
specifying the order of evaluation, without the translator caring
why, or letting the translator exploit the usual associativity rules
to come up with more efficient scheduling.

 We're not even giving the translator the option of saying we know
that we're running on a target with extra exponent range, so the
over/under-flow which the programmer must have been
guarding against can't happen here.
Dr. Timothy C. Prince
Consulting Engineer
Solar Turbines, a Caterpillar Company
alternate e-mail: tprince@computer.org

           To:                                              INTERNET - IBMMAIL
                                                            N7683011 - IBMMAIL

^ permalink raw reply	[flat|nested] 13+ messages in thread
* RE: Reassociation
@ 1998-12-17  8:29 tprince
  1998-12-17 20:03 ` Reassociation Jeffrey A Law
  0 siblings, 1 reply; 13+ messages in thread
From: tprince @ 1998-12-17  8:29 UTC (permalink / raw)
  To: bosch, burley, egcs, hjstein, law, moshier, tim

         Date: 12/17/98
         From: Tim Prince                                   PRINCTC3 - SOLARDEC
      Subject: RE: Reassociation

Date:  12/17/1998  08:12 am  (Thursday)
From:  Tim Prince
To:  MRG41."RALPH:MRS:SN_L=IBMMAIL:SN_U=N4244063",
     A1.MRS_RALPH.SN_U=INTERNET|SN_L=IBMMAIL
Subject:  RE: Reassociation


While I have only the summary articles of the IEEE P754 and
P854 standards, I am convinced that these standards deal only
with single operations, not with groupings where reassociation
is possible.  Except that the reason for choosing exponents
which increase by 3 bits with each increase in format width is to
assure that the wider format will protect against intermediate
over/under-flow when 3 operands (of the next smaller format) are
multiplied together.  If the multiplication of 4 operands produces
over or under-flow in spite of the width increase, it will happen
regardless of reassociation.  Clearly, this was done to relieve the
programmer of concerns about intermediate over/under-flow.

Fortran compilers always have been expected to perform
reassociations such as Jeff mentioned, with parentheses and
assignments being treated as barriers to reassociation.  As I
pointed out yesterday, there are reputable compilers which go
beyond that, but I side with those who say that shouldn't happen
without a specific additional option selection.

I am no C expert, but my copy of draft C9X standard touches on
this:

"Except as indicated by the syntax [operator precedence,
parentheses] or [when function call, && || ?: , operators
intervene], the order of evaluation of subexpressions and the
order in which side effects take place are both unspecified".

So I understand the C9X rules on this to be consistent with what
we have been accustomed to in Fortran, and I would go so far as
to suggest that C9X be taken as a guide.  Certainly that draft
standard shows evidence of incorporation of some expert
experience.

In view of the fact that left-to-right evaluation has been expected
from C compilers and that most current Fortran compilers follow
that scheme, I have tended to take that into account when setting
up expressions where the compiler may apply Common
Sub-expression Evaluation.  I don't see that as anything more
than a mild suggestion as to how the compiler should treat my
code.

From: Joe Buck <jbuck@Synopsys.COM>
> I believe the example you were talking about yesterday violates
IEEE,
> since the reordering you suggested can change the value of
the result
> (by causing an intermediate (c*d) to overflow, when left to right
> evaluation would not cause an overflow):

Does IEEE require left-to-right evaluation of y = a * b * c * d;
when there are no parentheses present?

Dr. Timothy C. Prince
Consulting Engineer
Solar Turbines, a Caterpillar Company
alternate e-mail: tprince@computer.org

           To:                                              INTERNET - IBMMAIL
                                                            N4244063 - IBMMAIL

^ permalink raw reply	[flat|nested] 13+ messages in thread
* Re: Reassociation
@ 1998-12-16 19:37 tprince
  1998-12-16 20:08 ` Reassociation Jeffrey A Law
  0 siblings, 1 reply; 13+ messages in thread
From: tprince @ 1998-12-16 19:37 UTC (permalink / raw)
  To: bosch, burley, egcs, hjstein, jbuck, law, moshier

Fortunately, we're not facing the dilemma of needing something
for g77 which is not wanted otherwise.  What Jeff has proposed
is in accordance with the excerpts from C9X which I quoted
earlier, as well as being in accordance with Fortran.  I doubt that
the C9X people really intended to help out egcs/g77, but they
may have done so in this case.

I suppose the next comment we'll see is "they're trying to make C
look more like Fortran."  But, I think there is a sufficient body of
experts who have taken a satisfactory position on what the
proper level of reassociation should be for normal optimization.

 gcc and g77 could become examples of this, and provide an
alternative to "all-or-nothing" compilers which try to give a choice
of going too far or not far enough, with a poorly documented
group of options unlike those used for benchmarks needed to
approximate correct behavior.  No matter if another flag or two
come into egcs, as long as we don't need to use them to get
reasonable behavior.

 >>>
Date: Wed, 16 Dec 1998 12:37:01 -0500 (EST)
From: Craig Burley <>

>There has been general agreement that gcc is not supposed to
make
>optimizations that could change the value of an expression.
>Associative law optimizations of floating-point expressions
certainly
>can change the value and they should continue to be
disallowed.  Users
>should not have to fear that gcc is going to take arbitrary
liberties
>and rewrite their programs for them without very explicit
permission.

Even if this was true -- and IMO it isn't -- it doesn't apply to well-
designed numerical-processing languages like Fortran, in which
it
is quite clear that A*B*C*D can be evaluated as (D*A)*(C*B), for
example.

Therefore, we should make the *back end* work properly in a
language-
independent sense.  If people want the gcc to produce slower
code
than g77, that's okay -- they can have gcc explicitly group the
operations for consumption by the back end, something Fortran
doesn't
generally need to do.

        tq vm, (burley)

Dr. Timothy C. Prince
Consulting Engineer
Solar Turbines, a Caterpillar Company
alternate e-mail: tprince@computer.org

           To:                                              INTERNET - IBMMAIL
                                                            N3356140 - IBMMAIL

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

end of thread, other threads:[~1998-12-20 16:22 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-12-19  5:30 Reassociation Stephen L Moshier
1998-12-20 15:36 ` Reassociation Richard Henderson
1998-12-20 16:22   ` Reassociation Stephen L Moshier
  -- strict thread matches above, loose matches on Subject: below --
1998-12-17 14:26 REASSOCIATION tprince
1998-12-17 18:26 ` REASSOCIATION Joern Rennecke
1998-12-17  8:29 Reassociation tprince
1998-12-17 20:03 ` Reassociation Jeffrey A Law
1998-12-16 19:37 Reassociation tprince
1998-12-16 20:08 ` Reassociation Jeffrey A Law
1998-12-17  9:24   ` Reassociation Gavin Romig-Koch
1998-12-17 10:45     ` Reassociation Stephen L Moshier
1998-12-17 19:56       ` Reassociation Jeffrey A Law
1998-12-17 20:00     ` Reassociation Jeffrey A Law

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).