Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unknown binary operator #27

Closed
MasonProtter opened this issue Nov 25, 2020 · 2 comments
Closed

Unknown binary operator #27

MasonProtter opened this issue Nov 25, 2020 · 2 comments

Comments

@MasonProtter
Copy link

MasonProtter commented Nov 25, 2020

Here's a MWE for an error I experienced:

julia> using Enzyme

julia> function f(x)
           y = (x + im)*(x - im)
           real(y)
       end
f (generic function with 1 method)

julia> autodiff(f, Active(2.0))
4.0julia> function g(x)
           y = (x + im)*(1 - im*x)
           real(y)
       end
g (generic function with 1 method)

julia> autodiff(g, Active(2.0))define dso_local double @preprocess_julia_overdub_1835(double) local_unnamed_addr {
top:
  %1 = bitcast double %0 to i64
  %2 = and i64 %1, -9223372036854775808
  %3 = bitcast i64 %2 to double
  %4 = fsub double 1.000000e+00, %3
  %5 = fmul double %4, %0
  %6 = fadd double %5, %0
  ret double %6
} constantinst[  %1 = bitcast double %0 to i64] = 0 val:0 type: {[-1]:Float@double}
 constantinst[  %2 = and i64 %1, -9223372036854775808] = 0 val:0 type: {[-1]:Float@double}
 constantinst[  ret double %6] = 1 val:1 type: {}
 constantinst[  %3 = bitcast i64 %2 to double] = 0 val:0 type: {[-1]:Float@double}
 constantinst[  %4 = fsub double 1.000000e+00, %3] = 0 val:0 type: {[-1]:Float@double}
 constantinst[  %5 = fmul double %4, %0] = 0 val:0 type: {[-1]:Float@double}
 constantinst[  %6 = fadd double %5, %0] = 0 val:0 type: {[-1]:Float@double}
cannot handle unknown binary operator:   %2 = and i64 %1, -9223372036854775808
ERROR: LLVM error: unknown binary operator
Stacktrace:
 [1] handle_error(::Cstring) at /home/mason/.julia/packages/LLVM/dVU7J/src/core/context.jl:105
@wsmoses
Copy link
Member

wsmoses commented Nov 25, 2020

Oh this is a pretty interesting bithack that Julia seems to have emitted (signed zero(x) == and(x, MAGIC NUM)).

Usually horrible bithacks of active values tend not to be handled in Enzyme automatically but this one should be easy to ensure happens.

I'll make a patch to Enzyme proper and we'll propagate that to Enzyme.jl shortly

This was referenced Nov 25, 2020
@wsmoses
Copy link
Member

wsmoses commented Dec 25, 2020

Merged in #31

@wsmoses wsmoses closed this as completed Dec 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants