[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


================
@@ -0,0 +1,123 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
+; RUN: opt -S -passes=instcombine < %s | FileCheck %s
+
+define double @fmul_tan_cos(double %a) {
+; CHECK-LABEL: define double @fmul_tan_cos(
+; CHECK-SAME: double [[A:%.*]]) {
+; CHECK-NEXT:    [[TMP1:%.*]] = call double @llvm.tan.f64(double [[A]])
+; CHECK-NEXT:    [[TMP2:%.*]] = call double @llvm.cos.f64(double [[A]])
+; CHECK-NEXT:    [[RES:%.*]] = fmul double [[TMP1]], [[TMP2]]
+; CHECK-NEXT:    ret double [[RES]]
+;
+  %1 = call double @llvm.tan.f64(double %a)
+  %2 = call double @llvm.cos.f64(double %a)
+  %res = fmul double %1, %2
+  ret double %res
+}
+
+define double @fmul_strict_tan_strict_cos_reassoc(double %a) {
+; CHECK-LABEL: define double @fmul_strict_tan_strict_cos_reassoc(
+; CHECK-SAME: double [[A:%.*]]) {
+; CHECK-NEXT:    [[TMP1:%.*]] = call double @llvm.tan.f64(double [[A]])
+; CHECK-NEXT:    [[TMP2:%.*]] = call reassoc double @llvm.cos.f64(double [[A]])
+; CHECK-NEXT:    [[RES:%.*]] = fmul double [[TMP1]], [[TMP2]]
+; CHECK-NEXT:    ret double [[RES]]
+;
+  %1 = call double @llvm.tan.f64(double %a)
+  %2 = call reassoc double @llvm.cos.f64(double %a)
+  %res = fmul double %1, %2
+  ret double %res
+}
+
+define double @fmul_reassoc_tan_strict_cos_strict(double %a, ptr dereferenceable(2) %dummy) {
----------------
dtcxzyw wrote:

Unused parameter `%dummy`

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


More information about the llvm-commits mailing list