[llvm] [InstCombine] Fold tan(x) * cos(x) => sin(x) (PR #136319)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 21 02:34:04 PDT 2025
================
@@ -1073,6 +1073,16 @@ Instruction *InstCombinerImpl::visitFMul(BinaryOperator &I) {
return Result;
}
+ // tan(X) * cos(X) -> sin(X)
+ if (I.hasAllowReassoc() && Op0->hasOneUse() && Op1->hasOneUse()) {
+ Value *X;
+ if (match(Op0, m_Intrinsic<Intrinsic::tan>(m_Value(X))) &&
+ match(Op1, m_Intrinsic<Intrinsic::cos>(m_Specific(X)))) {
+ Value *Sin = Builder.CreateUnaryIntrinsic(Intrinsic::sin, X, &I);
----------------
arsenm wrote:
I think in practice this will be true. This system is a mess though. In principle the intrinsics should always work regardless of target libcalls. We gate transforms on pure intrinsics based on libcall legality, but it's all hacks on hacks .
https://github.com/llvm/llvm-project/pull/136319
More information about the llvm-commits
mailing list