[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 18:04:49 PDT 2025


================
@@ -947,6 +947,14 @@ Instruction *InstCombinerImpl::foldFMulReassoc(BinaryOperator &I) {
     return BinaryOperator::CreateFMulFMF(XX, Y, &I);
   }
 
+  // tan(X) * cos(X) -> sin(X)
+  if (match(&I,
+            m_c_FMul(m_OneUse(m_Intrinsic<Intrinsic::tan>(m_Value(X))),
+                     m_OneUse(m_Intrinsic<Intrinsic::cos>(m_Specific(X)))))) {
----------------
dtcxzyw wrote:

Oops, you should use `m_Deferred` instead of `m_Specific`. See also https://llvm.org/docs/InstCombineContributorGuide.html#patternmatch

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


More information about the llvm-commits mailing list