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] Fix PR30028, fold sin, cos to sincos on the tree-level



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.

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

Paolo


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