This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Fold (10.0 - x) > 4.0 as x < 6.0


Roger Sayle <roger at www dot eyesopen dot com> writes:

> The following patch performs constant folding of floating
> point comparisons of the form (c1 - x) op c2, where c1 and c2
> are real constants as x swap(op) c1-c2, where swap(op) swaps
> the sense of relational operator op.  For example, we now
> convert (10.0 - x) == 2.0 into the equivalent x == 8.0.
> 
> This change has more than a passing similarity to the hunk
> immediately before, which I submited in June of last year:
> http://gcc.gnu.org/ml/gcc-patches/2002-06/msg00494.html
> 
> The following patch has been tested on i686-pc-linux-gnu with
> a full "make bootstrap", all languages except Ada and treelang,
> and regression tested with a top-level "make -k check" with no
> new failures (except for libjava due to timeouts).

Can you try to generalise these hunks a bit?  A recurring problem with
GCC is that one day someone writes an optimisation for PLUS, some months
later it's MINUS_EXPR, and then MULT, and so on, and we end up with a
compiler that's larger and slower than if the second author had tried
generalise.

Perhaps you could go for an expression simplifier which transforms
f(x) cmp1 c into x cmp2 f'(c)?  Initially, it would be limited to 'easy'
expressions where f is of the form +/-x OP c1 for a few values of OP, but
obviously it would be capable of infinite expansion...

-- 
- Geoffrey Keating <geoffk at geoffk dot org>


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]