Repeated savepoints on higher order AD
- Dominant language
- Julia
- Stars
- 586
- Forks
- 108
- Avg merge
- 1d 5h
- Merged PRs (30d)
- 44
Description
```julia
using Enzyme
function d(f)
return x -> (autodiff(Forward, Const(f), Duplicated(x, 1.0))[1])
end
@show sin(2.0)
@show d(sin)(2.0)
@show d(d(sin))(2.0)
@show d(d(d(sin)))(2.0)
@show d(d(d(d(sin))))(2.0)
@show d(d(d(d(d(sin)))))(2.0)
@show d(d(d(d(d(d(sin))))))(2.0)
Enzyme.API.printall!(true)
@show d(d(d(d(d(d(d(d(d(d(d(d(d(d(d(sin)))))))))))))))(2.0)
```
```llvm
; Function Attrs: mustprogress nofree
define internal double @fwddiffejulia__11_2152(double "enzyme_type"="{[-1]:Float@double}" "enzymejl_parmtype"="5251946832" "enzymejl_parmtype_ref"="0" %0, double "enzyme_type"="{[-1]:Float@double}" "enzymejl_parmtype"="5251946832" "enzymejl_parmtype_ref"="0" %"'") local_unnamed_addr #5 !dbg !1054 {
top:
%1 = call {}*** @julia.get_pgcstack() #6
%ptls_field3 = getelementptr inbounds {}**, {}*** %1, i64 2
%2 = bitcast {}*** %ptls_field3 to i64***
%ptls_load45 = load i64**, i64*** %2, align 8, !tbaa !24, !alias.scope !1055, !noalias !1058
%3 = getelementptr inbounds i64*, i64** %ptls_load45, i64 2
%safepoint = load i64*, i64** %3, align 8, !tbaa !28, !alias.scope !1060, !noalias !1063
fence syncscope("singlethread") seq_cst
call void @julia.safepoint(i64* %safepoint) #6, !dbg !1065
fence syncscope("singlethread") seq_cst
%ptls_load45.i.i = load i64**, i64*** %2, align 8, !tbaa !24, !alias.scope !1066, !noalias !1067
%4 = getelementptr inbounds i64*, i64** %ptls_load45.i.i, i64 2
%safepoint.i.i = load i64*, i64** %4, align 8, !tbaa !28, !alias.scope !1068, !noalias !1071
fence syncscope("singlethread") seq_cst
call void @julia.safepoint(i64* %safepoint.i.i) #6, !dbg !1073
fence syncscope("singlethread") seq_cst
%ptls_load45.i.i.i.i = load i64**, i64*** %2, align 8, !tbaa !24, !alias.scope !1080, !noalias !1081
%5 = getelementptr inbounds i64*, i64** %ptls_load45.i.i.i.i, i64 2
%safepoint.i.i.i.i = load i64*, i64** %5, align 8, !tbaa !28, !alias.scope !1082, !noalias !1085
fence syncscope("singlethread") seq_cst
call void @julia.safepoint(i64* %safepoint.i.i.i.i) #6, !dbg !1087
fence syncscope("singlethread") seq_cst
%ptls_load45.i.i.i.i.i.i = load i64**, i64*** %2, align 8, !tbaa !24, !alias.scope !1095, !noalias !1096
%6 = getelementptr inbounds i64*, i64** %ptls_load45.i.i.i.i.i.i, i64 2
%safepoint.i.i.i.i.i.i = load i64*, i64** %6, align 8, !tbaa !28, !alias.scope !1097, !noalias !1100
fence syncscope("singlethread") seq_cst
call void @julia.safepoint(i64* %safepoint.i.i.i.i.i.i) #6, !dbg !1102
fence syncscope("singlethread") seq_cst
%ptls_load45.i.i.i.i.i.i.i.i = load i64**, i64*** %2, align 8, !tbaa !24, !alias.scope !1110, !noalias !1111
%7 = getelementptr inbounds i64*, i64** %ptls_load45.i.i.i.i.i.i.i.i, i64 2
%safepoint.i.i.i.i.i.i.i.i = load i64*, i64** %7, align 8, !tbaa !28, !alias.scope !1112, !noalias !1115
fence syncscope("singlethread") seq_cst
call void @julia.safepoint(i64* %safepoint.i.i.i.i.i.i.i.i) #6, !dbg !1117
fence syncscope("singlethread") seq_cst
%ptls_load45.i.i.i.i.i.i.i.i.i.i = load i64**, i64*** %2, align 8, !tbaa !24, !alias.scope !1125, !noalias !1126
%8 = getelementptr inbounds i64*, i64** %ptls_load45.i.i.i.i.i.i.i.i.i.i, i64 2
%safepoint.i.i.i.i.i.i.i.i.i.i = load i64*, i64** %8, align 8, !tbaa !28, !alias.scope !1127, !noalias !1130
fence syncscope("singlethread") seq_cst
call void @julia.safepoint(i64* %safepoint.i.i.i.i.i.i.i.i.i.i) #6, !dbg !1132
fence syncscope("singlethread") seq_cst
%ptls_load45.i.i.i.i.i.i.i.i.i.i.i.i = load i64**, i64*** %2, align 8, !tbaa !24, !alias.scope !1140, !noalias !1141
%9 = getelementptr inbounds i64*, i64** %ptls_load45.i.i.i.i.i.i.i.i.i.i.i.i, i64 2
%safepoint.i.i.i.i.i.i.i.i.i.i.i.i = load i64*, i64** %9, align 8, !tbaa !28, !alias.scope !1142, !noalias !1145
fence syncscope("singlethread") seq_cst
call void @julia.safepoint(i64* %safepoint.i.i.i.i.i.i.i.i.i.i.i.i) #6, !dbg !1147
fence syncscope("singlethread") seq_cst
%ptls_load45.i.i.i.i.i.i.i.i.i.i.i.i.i.i = load i64**, i64*** %2, align 8, !tbaa !24, !alias.scope !1155, !noalias !1156
%10 = getelementptr inbounds i64*, i64** %ptls_load45.i.i.i.i.i.i.i.i.i.i.i.i.i.i, i64 2
%safepoint.i.i.i.i.i.i.i.i.i.i.i.i.i.i = load i64*, i64** %10, align 8, !tbaa !28, !alias.scope !1157, !noalias !1160
fence syncscope("singlethread") seq_cst
call void @julia.safepoint(i64* %safepoint.i.i.i.i.i.i.i.i.i.i.i.i.i.i) #6, !dbg !1162
fence syncscope("singlethread") seq_cst
%ptls_load45.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i = load i64**, i64*** %2, align 8, !tbaa !24, !alias.scope !1170, !noalias !1171
%11 = getelementptr inbounds i64*, i64** %ptls_load45.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i, i64 2
%safepoint.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i = load i64*, i64** %11, align 8, !tbaa !28, !alias.scope !1172, !noalias !1175
fence syncscope("singlethread") seq_cst
call void @julia.safepoint(i64* %safepoint.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i) #6, !dbg !1177
fence syncscope("singlethread") seq_cst
%ptls_load45.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i = load i64**, i64*** %2, align 8, !tbaa !24, !alias.scope !1185, !noalias !1186
%12 = getelementptr inbounds i64*, i64** %ptls_load45.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i, i64 2
%safepoint.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i = load i64*, i64** %12, align 8, !tbaa !28, !alias.scope !1187, !noalias !1190
fence syncscope("singlethread") seq_cst
call void @julia.safepoint(i64* %safepoint.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i) #6, !dbg !1192
fence syncscope("singlethread") seq_cst
%ptls_load45.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i = load i64**, i64*** %2, align 8, !tbaa !24, !alias.scope !1200, !noalias !1201
%13 = getelementptr inbounds i64*, i64** %ptls_load45.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i, i64 2
%safepoint.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i = load i64*, i64** %13, align 8, !tbaa !28, !alias.scope !1202, !noalias !1205
fence syncscope("singlethread") seq_cst
call void @julia.safepoint(i64* %safepoint.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i) #6, !dbg !1207
fence syncscope("singlethread") seq_cst
%ptls_load45.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i = load i64**, i64*** %2, align 8, !tbaa !24, !alias.scope !1215, !noalias !1216
%14 = getelementptr inbounds i64*, i64** %ptls_load45.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i, i64 2
%safepoint.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i = load i64*, i64** %14, align 8, !tbaa !28, !alias.scope !1217, !noalias !1220
fence syncscope("singlethread") seq_cst
call void @julia.safepoint(i64* %safepoint.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i) #6, !dbg !1222
fence syncscope("singlethread") seq_cst
%ptls_load45.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i = load i64**, i64*** %2, align 8, !tbaa !24, !alias.scope !1230, !noalias !1231
%15 = getelementptr inbounds i64*, i64** %ptls_load45.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i, i64 2
%safepoint.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i = load i64*, i64** %15, align 8, !tbaa !28, !alias.scope !1232, !noalias !1235
fence syncscope("singlethread") seq_cst
call void @julia.safepoint(i64* %safepoint.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i) #6, !dbg !1237
fence syncscope("singlethread") seq_cst
%ptls_load45.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i = load i64**, i64*** %2, align 8, !tbaa !24, !alias.scope !1245, !noalias !1246
%16 = getelementptr inbounds i64*, i64** %ptls_load45.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i, i64 2
%safepoint.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i = load i64*, i64** %16, align 8, !tbaa !28, !alias.scope !1247, !noalias !1250
fence syncscope("singlethread") seq_cst
call void @julia.safepoint(i64* %safepoint.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i) #6, !dbg !1252
fence syncscope("singlethread") seq_cst
%17 = call fast double @llvm.cos.f64(double %0), !dbg !1260
%18 = fmul fast double %"'", %17, !dbg !1260
%19 = fneg fast double %18, !dbg !1261
ret double %19
}
(d(d(d(d(d(d(d(d(d(d(d(d(d(d(d(sin))))))))))))))))(2.0) = 0.4161468365471424
0.4161468365471424
```
Contributor guide
Assessment
This issue has not been assessed yet.