[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:07 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))) &&
----------------
dtcxzyw wrote:

Please use `m_c_FMul(m_OneUse(m_Intrinsic<Intrinsic::tan>(m_Value(X))), m_OneUse(m_Intrinsic<Intrinsic::cos>(m_Specific(X)))))` to handle commuted case.


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


More information about the llvm-commits mailing list