[llvm] [InstCombine] Fold tan(x) * cos(x) => sin(x) (PR #136319)

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Sat Apr 19 05:49:08 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);
----------------
dtcxzyw wrote:

@arsenm Is `sin/sinf` always available if `tan/cos` are supported?


https://github.com/llvm/llvm-project/pull/136319


More information about the llvm-commits mailing list