-
Notifications
You must be signed in to change notification settings - Fork 69
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
try
/catch
block error on Julia 1.8 and earlier
#971
Comments
Looks like what's happening here is that we prove that sqrt result is not needed for the derivative and it is dead code eliminated. We should run a postprocessing to emit a new "unreachable reached" error on such unreachables, so that the same error is throw condition is applied. |
That error message will be somethign along the lines of "the original primal code is guaranteed to hit this error condition, thus differentiating it does not make sense" |
We should probably handle exceptional Control-Flow better, gradients could propagate through PhiC nodes. |
This fixes the issue for Julia 1.7 and 1.8 but on Julia 1.6.7 it returns the wrong answer: using Enzyme
function f(x)
try
sqrt(-1.0)
return 3x
catch
return 2x
end
end
autodiff(Reverse, f, Active, Active(2.0))[1][1]
|
julia> autodiff(Reverse, f, Active, Active(2.0))[1][1]
after simplification :
; Function Attrs: willreturn
define double @preprocess_julia_f_4904_inner.1(double %0) local_unnamed_addr #16 !dbg !102 {
entry:
%phic.i = alloca double, align 8
%phic.i.0.sroa_cast2 = bitcast double* %phic.i to i8*
call void @llvm.lifetime.start.p0i8(i64 8, i8* %phic.i.0.sroa_cast2)
%1 = call {}*** @julia.ptls_states() #17
%2 = call i64 @jl_excstack_state() #18, !dbg !103
%3 = call i32 @julia.except_enter() #19, !dbg !103
%4 = icmp eq i32 %3, 0, !dbg !103
br i1 %4, label %try.i, label %julia_f_4904_inner.exit, !dbg !103
try.i: ; preds = %entry
store volatile double %0, double* %phic.i, align 8, !dbg !103, !tbaa !70, !noalias !105
%5 = call fastcc nonnull {} addrspace(10)* @julia_throw_complex_domainerror_4907() #20, !dbg !108
unreachable, !dbg !108
julia_f_4904_inner.exit: ; preds = %entry
%phic.i.0.phic.i.0.phic.i.0.phic.i.0.phic.i.0.phic.i.0.phic.i.0.phic.i.0.phic.i.0.phic.i.0. = load volatile double, double* %phic.i, align 8, !dbg !110
call void @jl_pop_handler(i32 1) #21, !dbg !110
%6 = fmul double %phic.i.0.phic.i.0.phic.i.0.phic.i.0.phic.i.0.phic.i.0.phic.i.0.phic.i.0.phic.i.0.phic.i.0., 2.000000e+00, !dbg !111
call void @jl_restore_excstack(i64 %2) #21, !dbg !114
%phic.i.0.sroa_cast3 = bitcast double* %phic.i to i8*, !dbg !114
call void @llvm.lifetime.end.p0i8(i64 8, i8* %phic.i.0.sroa_cast3), !dbg !114
ret double %6, !dbg !115
}
; Function Attrs: willreturn
define internal { double } @diffejulia_f_4904_inner.1(double %0, double %differeturn) local_unnamed_addr #16 !dbg !116 {
entry:
%"'de" = alloca double, align 8
%1 = getelementptr double, double* %"'de", i64 0
store double 0.000000e+00, double* %1, align 8
%phic.i = alloca double, align 8
%2 = call {}*** @julia.ptls_states() #17
%3 = call i64 @jl_excstack_state() #18, !dbg !117
%4 = call i32 @julia.except_enter() #19, !dbg !117
%5 = icmp eq i32 %4, 0, !dbg !117
br i1 %5, label %try.i, label %julia_f_4904_inner.exit, !dbg !117
try.i: ; preds = %entry
store volatile double %0, double* %phic.i, align 8, !dbg !117, !tbaa !70, !noalias !119
%6 = call fastcc nonnull {} addrspace(10)* @julia_throw_complex_domainerror_4907() #20, !dbg !122
unreachable
julia_f_4904_inner.exit: ; preds = %entry
%phic.i.0.phic.i.0.phic.i.0.phic.i.0.phic.i.0.phic.i.0.phic.i.0.phic.i.0.phic.i.0.phic.i.0. = load volatile double, double* %phic.i, align 8, !dbg !124, !alias.scope !125, !noalias !128
call void @jl_pop_handler(i32 1) #21, !dbg !124
call void @jl_restore_excstack(i64 %3) #21, !dbg !130
br label %invertjulia_f_4904_inner.exit, !dbg !131
invertentry: ; preds = %invertjulia_f_4904_inner.exit
%7 = load double, double* %"'de", align 8
%8 = insertvalue { double } undef, double %7, 0
ret { double } %8
invertjulia_f_4904_inner.exit: ; preds = %julia_f_4904_inner.exit
br label %invertentry
}
0.0
|
Correction to the above, the wrong answer is also returned on Julia 1.7.3. |
Pre 1.10 is now not supported, closing |
This works on Julia 1.9 and Enzyme main (6692fad):
But on Julia 1.8.5 (and earlier?) it errors. I'm struggling to catch the segfault but it is probably the same one as at https://github.com/EnzymeAD/Enzyme.jl/actions/runs/5707501454/job/15464242433?pr=969:
The text was updated successfully, but these errors were encountered: