[llvm] [InstCombine] Optimize `sinh` and `cosh` divisions (PR #81433)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Wed May 8 08:40:44 PDT 2024


================
@@ -0,0 +1,111 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt -S -passes=instcombine < %s | FileCheck %s
+
+define double @fdiv_sinh_cosh(double %a) {
+; CHECK-LABEL: @fdiv_sinh_cosh(
+; CHECK-NEXT:    [[TMP1:%.*]] = call double @sinh(double [[A:%.*]])
+; CHECK-NEXT:    [[TMP2:%.*]] = call double @cosh(double [[A]])
+; CHECK-NEXT:    [[DIV:%.*]] = fdiv double [[TMP1]], [[TMP2]]
+; CHECK-NEXT:    ret double [[DIV]]
+;
+  %sinh = call double @sinh(double %a)
+  %cosh = call double @cosh(double %a)
+  %div = fdiv double %sinh, %cosh
+  ret double %div
+}
+
+define double @fdiv_reassoc_sinh_strict_cosh_strict(double %a, ptr dereferenceable(2) %dummy) {
+; CHECK-LABEL: @fdiv_reassoc_sinh_strict_cosh_strict(
+; CHECK-NEXT:    [[TANH:%.*]] = call reassoc double @tanh(double [[A]])
+; CHECK-NEXT:    ret double [[TANH]]
+;
+  %sinh = call double @sinh(double %a)
+  %cosh = call double @cosh(double %a)
+  %div = fdiv reassoc double %sinh, %cosh
+  ret double %div
+}
+
+define double @fdiv_reassoc_sinh_reassoc_cosh_strict(double %a) {
+; CHECK-LABEL: @fdiv_reassoc_sinh_reassoc_cosh_strict(
+; CHECK-NEXT:    [[TANH:%.*]] = call reassoc double @tanh(double [[A]])
+; CHECK-NEXT:    ret double [[TANH]]
+;
+  %sinh = call reassoc double @sinh(double %a)
+  %cosh = call double @cosh(double %a)
+  %div = fdiv reassoc double %sinh, %cosh
+  ret double %div
+}
+
+define double @fdiv_sin_cos_reassoc_multiple_uses_sinh(double %a) {
+; CHECK-LABEL: @fdiv_sin_cos_reassoc_multiple_uses_sinh(
+; CHECK-NEXT:    [[TMP1:%.*]] = call reassoc double @sinh(double [[A:%.*]])
+; CHECK-NEXT:    [[TMP2:%.*]] = call reassoc double @cosh(double [[A]])
+; CHECK-NEXT:    [[DIV:%.*]] = fdiv reassoc double [[TMP1]], [[TMP2]]
+; CHECK-NEXT:    call void @use(double [[TMP1]])
+; CHECK-NEXT:    ret double [[DIV]]
+;
+  %sinh = call reassoc double @sinh(double %a)
+  %cosh = call reassoc double @cosh(double %a)
+  %div = fdiv reassoc double %sinh, %cosh
+  call void @use(double %sinh)
+  ret double %div
+}
+
+define double @fdiv_sin_cos_reassoc_multiple_uses_cosh(double %a) {
+; CHECK-LABEL: @fdiv_sin_cos_reassoc_multiple_uses_cosh(
+; CHECK-NEXT:    [[TMP1:%.*]] = call reassoc double @sinh(double [[A:%.*]])
+; CHECK-NEXT:    [[TMP2:%.*]] = call reassoc double @cosh(double [[A]])
+; CHECK-NEXT:    [[DIV:%.*]] = fdiv reassoc double [[TMP1]], [[TMP2]]
+; CHECK-NEXT:    call void @use(double [[TMP2]])
+; CHECK-NEXT:    ret double [[DIV]]
+;
+  %sinh = call reassoc double @sinh(double %a)
+  %cosh = call reassoc double @cosh(double %a)
+  %div = fdiv reassoc double %sinh, %cosh
+  call void @use(double %cosh)
+  ret double %div
+}
+
+
+define double @fdiv_sinh_cosh_reassoc(double %a) {
+; CHECK-LABEL: @fdiv_sinh_cosh_reassoc(
+; CHECK-NEXT:    [[TANH:%.*]] = call reassoc double @tanh(double [[A]])
+; CHECK-NEXT:    ret double [[TANH]]
+;
+  %sinh = call reassoc double @sinh(double %a)
+  %cosh = call reassoc double @cosh(double %a)
+  %div = fdiv reassoc double %sinh, %cosh
+  ret double %div
+}
+
+define float @fdiv_sinhf_coshf_reassoc(float %a) {
+; CHECK-LABEL: @fdiv_sinhf_coshf_reassoc(
+; CHECK-NEXT:    [[TANH:%.*]] = call reassoc float @tanhf(float [[A]])
+; CHECK-NEXT:    ret float [[TANH]]
+;
+  %sinhf = call reassoc float @sinhf(float %a)
+  %coshf = call reassoc float @coshf(float %a)
+  %div = fdiv reassoc float %sinhf, %coshf
+  ret float %div
+}
+
+define fp128 @fdiv_sinhl_coshl_reassoc(fp128 %a) {
+; CHECK-LABEL: @fdiv_sinhl_coshl_reassoc(
+; CHECK-NEXT:    [[TANH:%.*]] = call reassoc fp128 @tanhl(fp128 [[A]])
+; CHECK-NEXT:    ret fp128 [[TANH]]
+;
+  %sinhl = call reassoc fp128 @sinhl(fp128 %a)
+  %coshl = call reassoc fp128 @coshl(fp128 %a)
+  %div = fdiv reassoc fp128 %sinhl, %coshl
+  ret fp128 %div
+}
+
----------------
arsenm wrote:

Same, test contract cases? 

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


More information about the llvm-commits mailing list