llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

Simplify sinh(x) / cosh(x) -> tanh(x) with fast-math

Open k-arrows opened this issue 2 years ago • 6 comments

It seems that the simplification sin(x) / cos(x) -> tan(x) has been already implemented, but the same applies for hyperbolic function(s).

https://godbolt.org/z/WqYfKxr7K

For those who are interested in floating-point arithmetic optimization, I think this can be added to https://github.com/llvm/llvm-project/issues/34959.

k-arrows avatar Jan 21 '24 01:01 k-arrows

Hey is anyone working on this ? If not could someone assign this to me ?

ghost avatar Jan 25 '24 13:01 ghost

No one's replied till now (5 days since issue filing), so I'll assume no one has picked this up.

dc03 avatar Jan 25 '24 14:01 dc03

#77799 also related

arsenm avatar Jan 25 '24 14:01 arsenm

Thanks for assigning me, I will look into this as soon as possible

ghost avatar Jan 25 '24 18:01 ghost

I am almost done with this but there is one thing I can't quite figure out. I used replaceInstUsesWith to replace the div Instruction with a call Instruction to tanh. This does not replace the calls to sinh and cosh but when looking at the optimization of sin/cos it seems to replace the calls to sin and cos, why is this and how can I delete the calls to sinh and cosh ? Any help would be appreciated.

ghost avatar Feb 03 '24 16:02 ghost

it seems to replace the calls tosinandcos, why is this and how can I delete the calls to sinhandcosh` ? Any help would be appreciated.

The replaceInstUsesWith only replaces the uses, leaving behind the dead call instructions. You need to separately erase them

arsenm avatar Feb 05 '24 10:02 arsenm