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]: Handle COMPLEX_EXPR in negate_expr_p/fold_negate_expr


On Fri, 2 Feb 2007, Richard Guenther wrote:

> On 2/2/07, Paolo Bonzini <paolo.bonzini@lu.unisi.ch> wrote:
> >
> > > +    case COMPLEX_EXPR:
> > > +      return negate_expr_p (TREE_OPERAND (t, 0))
> > > +          && negate_expr_p (TREE_OPERAND (t, 1));
> >
> > Shouldn't this be an || ? -(5,a) can be cheaply negated to (-5,-a).
>
> Good point.
> The patch is ok if that change works out.
> Richard.

I don't think so, "cheaply negated" should be cheaper than (or as cheaply
as)  the current expression.  In the example above, the expression being
negated is (5,a)  not -(5,a), and (5,a) is already cheaper than (-5,-a).
It's only by adding the preceeding negate that you even reach cost
equivalence.  But the negate will not always be there, so in some cases
you end up worse.

You'll pessimize code when you combine this with other existing
transformations.  E.g. in fold_binary, there is an existing transformation
A-B -> A+(-B), if B is "cheaply negated".  If you supposed the following:

(x,y) - (5,a) -> (x,y) + (-5,-a)

Now we have a plus and a negate of "a" instead of just one minus.

I'm also worried about the possibility of infinite recursion, but I
haven't done an exhaustive search to find one.

Can I check in the code using the original && condition?

		Thanks,
		--Kaveh
--
Kaveh R. Ghazi			ghazi@caip.rutgers.edu


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