Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions enzyme/Enzyme/InstructionDerivatives.td
Original file line number Diff line number Diff line change
Expand Up @@ -352,19 +352,19 @@ def : CallPattern<(Op $x, $y),

def : CallPattern<(Op $x),
["tanh"],
[(FDiv (DiffeRet), (FMul(Call<(SameTypesFunc<"cosh">), [ReadNone,NoUnwind]> $x):$c, $c))],
[(FMul (DiffeRet), (FSub (ConstantFP<"1.0"> $x), (FMul(Call<(SameFunc), [ReadNone,NoUnwind]> $x):$c, $c)))],
(ForwardFromSummedReverse),
[ReadNone, NoUnwind]
>;
def : CallPattern<(Op $x),
["tanhf"],
[(FDiv (DiffeRet), (FMul(Call<(SameTypesFunc<"coshf">), [ReadNone,NoUnwind]> $x):$c, $c))],
[(FMul (DiffeRet), (FSub (ConstantFP<"1.0"> $x), (FMul(Call<(SameFunc), [ReadNone,NoUnwind]> $x):$c, $c)))],
(ForwardFromSummedReverse),
[ReadNone, NoUnwind]
>;
def : CallPattern<(Op $x),
["tanhl"],
[(FDiv (DiffeRet), (FMul(Call<(SameTypesFunc<"coshl">), [ReadNone,NoUnwind]> $x):$c, $c))],
[(FMul (DiffeRet), (FSub (ConstantFP<"1.0"> $x), (FMul(Call<(SameFunc), [ReadNone,NoUnwind]> $x):$c, $c)))],
(ForwardFromSummedReverse),
[ReadNone, NoUnwind]
>;
Expand Down Expand Up @@ -931,7 +931,7 @@ def : CallPattern<(Op (Op $x, $y):$z),

def : IntrPattern<(Op $x),
[["tanh", "19", ""]],
[(FDiv (DiffeRet), (FMul(Intrinsic<"cosh"> $x):$c, $c))],
[(FMul (DiffeRet), (FSub (ConstantFP<"1.0"> $x), (FMul(Intrinsic<"tanh"> $x):$c, $c)))],
(ForwardFromSummedReverse)
>;

Expand Down
9 changes: 5 additions & 4 deletions enzyme/test/Enzyme/ReverseMode/tanh19.ll
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ declare double @__enzyme_autodiff(ptr, ...)

; CHECK: define internal { double } @diffetester(double %x, double %differeturn)
; CHECK-NEXT: entry:
; CHECK-NEXT: %0 = call fast double @llvm.cosh.f64(double %x)
; CHECK-NEXT: %0 = call fast double @llvm.tanh.f64(double %x)
; CHECK-NEXT: %1 = fmul fast double %0, %0
; CHECK-NEXT: %2 = fdiv fast double %differeturn, %1
; CHECK-NEXT: %3 = insertvalue { double } undef, double %2, 0
; CHECK-NEXT: ret { double } %3
; CHECK-NEXT: %2 = fsub fast double 1.000000e+00, %1
; CHECK-NEXT: %3 = fmul fast double %differeturn, %2
; CHECK-NEXT: %4 = insertvalue { double } undef, double %3, 0
; CHECK-NEXT: ret { double } %4
; CHECK-NEXT: }
Loading