From 97d209eed26d4b025dd2eb2ff7704b13816a9b10 Mon Sep 17 00:00:00 2001 From: "William S. Moses" Date: Wed, 30 Oct 2024 00:52:58 -0400 Subject: [PATCH] Implement tgamma derivative --- enzyme/Enzyme/InstructionDerivatives.td | 11 +++++++++++ enzyme/test/Enzyme/ReverseMode/tgamma.ll | 9 +++++++++ 2 files changed, 20 insertions(+) diff --git a/enzyme/Enzyme/InstructionDerivatives.td b/enzyme/Enzyme/InstructionDerivatives.td index 4e2a48ef21c..fa415cd46bc 100644 --- a/enzyme/Enzyme/InstructionDerivatives.td +++ b/enzyme/Enzyme/InstructionDerivatives.td @@ -559,6 +559,17 @@ def : CallPattern<(Op $x, $y), [ReadNone, NoUnwind] >; +def : CallPattern<(Op $x), + ["tgamma"], + [ + ( + FMul (Call<(ArgAsRetTypesFunc<"digamma">), [ReadNone,NoUnwind]> $x), (DiffeRet) + ) + ], + (ForwardFromSummedReverse), + [ReadNone, NoUnwind] + >; + def : CallPattern<(Op $x), ["logabsgamma"], [ diff --git a/enzyme/test/Enzyme/ReverseMode/tgamma.ll b/enzyme/test/Enzyme/ReverseMode/tgamma.ll index 6dd83ac9967..5bd34a8757d 100644 --- a/enzyme/test/Enzyme/ReverseMode/tgamma.ll +++ b/enzyme/test/Enzyme/ReverseMode/tgamma.ll @@ -33,3 +33,12 @@ declare double @tgamma(double) ; CHECK-NEXT: } ; CHECK: define internal fastcc { double } @diffea5(double %arg, double %differeturn) +; CHECK-NEXT: bb: +; CHECK-NEXT: %i8 = call double @tgamma(double %arg) #1 +; CHECK-NEXT: %0 = fmul fast double %differeturn, %arg +; CHECK-NEXT: %1 = fmul fast double %i8, %differeturn +; CHECK-NEXT: %2 = call fast double @digamma(double %arg) #0 +; CHECK-NEXT: %3 = fmul fast double %2, %0 +; CHECK-NEXT: %4 = fadd fast double %1, %3 +; CHECK-NEXT: %5 = insertvalue { double } undef, double %4, 0 +; CHECK-NEXT: ret { double } %5