[PATCH] Fix PR30028, fold sin, cos to sincos on the tree-level
Richard Guenther
rguenther@suse.de
Mon Dec 11 09:52:00 GMT 2006
On Mon, 11 Dec 2006, Paolo Bonzini wrote:
>
> > I'll try to re-work it after vacation and if the canonicalization patch
> > goes in. Of course I still have the plan to teach VN/PRE to do this
> > transformation by value-numbering sin (x) as IMAGPART_EXPR <cexpi (x)>
> > and cos (x) as REALPART_EXPR <cexpi (x)> and teaching insertion and
> > expression re-constructing to deal with value-numbers without a leader.
>
> I would do something much simpler, using a dominator walk. Sines and cosines
> are complicated enough (and infrequent enough) that they do not require the
> *post*dominator magic needed for reciprocals.
>
> For every basic block, check if it invokes sin and cos on the same argument,
> and if so put a cexpi before the first invocation, and rewrite the others to
> REALPART_EXPRs or IMAGPART_EXPRs. Put the argument in a hash table mapping
> the argument to the cexpi statement. You may want to take a look at my
> pointer_map patch. :-)
>
> When you find a sin or cos, look up its argument in the hash table. Use
> bb_for_stmt to check if the sincos really dominates the current basic block,
> and if so rewrite the sin or cos to the REALPART_EXPR or IMAGPART_EXPR.
Sure, I need to do _something_ anyway because of the cost issue. The
current code will happily transform
if (a)
s = sin (x);
else
c = cos (x);
to use sincos.
> It will catch most occurrences. I wonder in fact if the dominator walk
> catches more occurrences than just looking for a sin and a cos in the same
> basic block (and relying on PRE to eliminate redundant cexpi's, but not
> redundant sin's and cos's).
Probably not (all real-world testcases I looked at have sin and cos in
the same BB only). But the tree-ssa-math-opts pass is run after
tree-loop, so too late for PRE to clean up. Was there any reason for
this? If not I'd move it at least before loop.
Thanks,
Richard.
--
Richard Guenther <rguenther@suse.de>
Novell / SUSE Labs
More information about the Gcc-patches
mailing list