Skip to content

Commit

Permalink
Correct complex inv (#1767)
Browse files Browse the repository at this point in the history
  • Loading branch information
wsmoses authored Feb 27, 2024
1 parent 21ead64 commit 8d75756
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions enzyme/Enzyme/InstructionDerivatives.td
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,20 @@ def CFNeg : SubRoutine<(Op (Op $re, $im):$z),
(FNeg $re),
(FNeg $im)
)>;

def Conj : SubRoutine<(Op (Op $re, $im):$z),
(ArrayRet
$re,
(FNeg $im)
)>;

def CFExp : SubRoutine<(Op (Op $re, $im):$z),
(ArrayRet
(FMul (FExp $re):$exp, (FCos $im)),
(FMul $exp, (FSin $im))
)>;


// Same function as the one being called
def SameFunc {
}
Expand Down Expand Up @@ -826,9 +834,10 @@ def : CallPattern<(Op (Op $x, $y):$z),
def : CallPattern<(Op (Op $x, $y):$z),
["cmplx_inv"],
[
(CFDiv (CFNeg (DiffeRet)), (CFMul $z, $z)),
// Reverse mode needs to return the conjugate
(Conj (CFDiv (CFNeg (Conj (DiffeRet))), (CFMul $z, $z))),
],
(ForwardFromSummedReverse),
(CFDiv (CFNeg (Shadow $z)), (CFMul $z, $z)),
[ReadNone, NoUnwind]
>;

Expand Down

0 comments on commit 8d75756

Please sign in to comment.