Enzyme.jl
Enzyme.jl copied to clipboard
Union leads to illegal type analysis
julia> f(cond, x) = cond ? x : 0
f (generic function with 1 method)
julia> g(cond, x) = f(cond,x)*x
g (generic function with 1 method)
julia> autodiff(g, Active, true, Active(1.0))
; ModuleID = 'text'
source_filename = "text"
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128-ni:10:11:12:13"
target triple = "x86_64-pc-linux-gnu"
@exception = private unnamed_addr constant [10 x i8] c"exception\00", align 1
; Function Attrs: readnone
declare {}*** @julia.get_pgcstack() local_unnamed_addr #0
; Function Attrs: argmemonly nofree nosync nounwind willreturn
declare void @llvm.memcpy.p0i8.p0i8.i64(i8* noalias nocapture writeonly, i8* noalias nocapture readonly, i64, i1 immarg) #1
; Function Attrs: argmemonly nofree nosync nounwind willreturn
declare void @llvm.lifetime.end.p0i8(i64 immarg, i8* nocapture) #1
; Function Attrs: cold noreturn nounwind
declare void @llvm.trap() #2
; Function Attrs: argmemonly nofree nosync nounwind willreturn
declare void @llvm.lifetime.start.p0i8(i64 immarg, i8* nocapture) #1
; Function Attrs: nosync readnone
define double @julia_g_2701.inner.5(i8 zeroext %0, double %1) local_unnamed_addr #3 {
entry:
%2 = call {}*** @julia.get_pgcstack()
%3 = and i8 %0, 1, !dbg !36
%.not = icmp eq i8 %3, 0, !dbg !36
%4 = bitcast double %1 to i64, !dbg !36
%.sroa.02.0 = select i1 %.not, i64 0, i64 %4, !dbg !36
%5 = bitcast i64 %.sroa.02.0 to double, !dbg !43
%6 = sitofp i64 %.sroa.02.0 to double, !dbg !43
%.pn = select i1 %.not, double %6, double %5, !dbg !43
%value_phi.i = fmul double %.pn, %1, !dbg !44
ret double %value_phi.i
}
; Function Attrs: nosync readnone willreturn mustprogress
define double @preprocess_julia_g_2701.inner.5(i8 zeroext %0, double %1) local_unnamed_addr #4 {
entry:
%2 = call {}*** @julia.get_pgcstack() #5
%3 = and i8 %0, 1, !dbg !36
%.not = icmp eq i8 %3, 0, !dbg !36
%4 = bitcast double %1 to i64, !dbg !36
%.sroa.02.0 = select i1 %.not, i64 0, i64 %4, !dbg !36
%5 = bitcast i64 %.sroa.02.0 to double, !dbg !43
%6 = sitofp i64 %.sroa.02.0 to double, !dbg !43
%.pn = select i1 %.not, double %6, double %5, !dbg !43
%value_phi.i = fmul double %.pn, %1, !dbg !44
ret double %value_phi.i
}
; Function Attrs: nosync readnone willreturn mustprogress
define internal { double } @diffejulia_g_2701.inner.5(i8 zeroext %0, double %1, double %differeturn) local_unnamed_addr #4 {
entry:
%2 = call {}*** @julia.get_pgcstack() #5
%3 = and i8 %0, 1, !dbg !36
%.not = icmp eq i8 %3, 0, !dbg !36
%4 = bitcast double %1 to i64, !dbg !36
%.sroa.02.0 = select i1 %.not, i64 0, i64 %4, !dbg !36
%5 = bitcast i64 %.sroa.02.0 to double, !dbg !43
%6 = sitofp i64 %.sroa.02.0 to double, !dbg !43
%.pn = select i1 %.not, double %6, double %5, !dbg !43
%value_phi.i = fmul double %.pn, %1, !dbg !44
ret double %value_phi.i
allocsForInversion: ; No predecessors!
invertentry: ; No predecessors!
}
attributes #0 = { readnone "enzyme_inactive" }
attributes #1 = { argmemonly nofree nosync nounwind willreturn }
attributes #2 = { cold noreturn nounwind }
attributes #3 = { nosync readnone "probe-stack"="inline-asm" }
attributes #4 = { nosync readnone willreturn mustprogress "probe-stack"="inline-asm" }
attributes #5 = { willreturn mustprogress }
!llvm.module.flags = !{!0, !1}
!llvm.dbg.cu = !{!2, !5, !7, !8, !9, !11, !12, !13, !14, !15, !16, !17, !18, !19, !20, !21, !22, !23, !24, !25, !26, !27, !28, !29, !30, !31, !32, !33, !34, !35}
!0 = !{i32 2, !"Dwarf Version", i32 4}
!1 = !{i32 2, !"Debug Info Version", i32 3}
!2 = distinct !DICompileUnit(language: DW_LANG_Julia, file: !3, producer: "julia", isOptimized: true, runtimeVersion: 0, emissionKind: LineTablesOnly, enums: !4, nameTableKind: None)
!3 = !DIFile(filename: "REPL[4]", directory: ".")
!4 = !{}
!5 = distinct !DICompileUnit(language: DW_LANG_Julia, file: !6, producer: "julia", isOptimized: true, runtimeVersion: 0, emissionKind: LineTablesOnly, enums: !4, nameTableKind: None)
!6 = !DIFile(filename: "/home/vchuravy/.julia/packages/GPUCompiler/yCkO8/src/runtime.jl", directory: ".")
!7 = distinct !DICompileUnit(language: DW_LANG_Julia, file: !6, producer: "julia", isOptimized: true, runtimeVersion: 0, emissionKind: LineTablesOnly, enums: !4, nameTableKind: None)
!8 = distinct !DICompileUnit(language: DW_LANG_Julia, file: !6, producer: "julia", isOptimized: true, runtimeVersion: 0, emissionKind: LineTablesOnly, enums: !4, nameTableKind: None)
!9 = distinct !DICompileUnit(language: DW_LANG_Julia, file: !10, producer: "julia", isOptimized: true, runtimeVersion: 0, emissionKind: LineTablesOnly, enums: !4, nameTableKind: None)
!10 = !DIFile(filename: "/home/vchuravy/.julia/packages/Enzyme/3SS7y/src/compiler.jl", directory: ".")
!11 = distinct !DICompileUnit(language: DW_LANG_Julia, file: !6, producer: "julia", isOptimized: true, runtimeVersion: 0, emissionKind: LineTablesOnly, enums: !4, nameTableKind: None)
!12 = distinct !DICompileUnit(language: DW_LANG_Julia, file: !6, producer: "julia", isOptimized: true, runtimeVersion: 0, emissionKind: LineTablesOnly, enums: !4, nameTableKind: None)
!13 = distinct !DICompileUnit(language: DW_LANG_Julia, file: !10, producer: "julia", isOptimized: true, runtimeVersion: 0, emissionKind: LineTablesOnly, enums: !4, nameTableKind: None)
!14 = distinct !DICompileUnit(language: DW_LANG_Julia, file: !6, producer: "julia", isOptimized: true, runtimeVersion: 0, emissionKind: LineTablesOnly, enums: !4, nameTableKind: None)
!15 = distinct !DICompileUnit(language: DW_LANG_Julia, file: !6, producer: "julia", isOptimized: true, runtimeVersion: 0, emissionKind: LineTablesOnly, enums: !4, nameTableKind: None)
!16 = distinct !DICompileUnit(language: DW_LANG_Julia, file: !10, producer: "julia", isOptimized: true, runtimeVersion: 0, emissionKind: LineTablesOnly, enums: !4, nameTableKind: None)
!17 = distinct !DICompileUnit(language: DW_LANG_Julia, file: !6, producer: "julia", isOptimized: true, runtimeVersion: 0, emissionKind: LineTablesOnly, enums: !4, nameTableKind: None)
!18 = distinct !DICompileUnit(language: DW_LANG_Julia, file: !10, producer: "julia", isOptimized: true, runtimeVersion: 0, emissionKind: LineTablesOnly, enums: !4, nameTableKind: None)
!19 = distinct !DICompileUnit(language: DW_LANG_Julia, file: !6, producer: "julia", isOptimized: true, runtimeVersion: 0, emissionKind: LineTablesOnly, enums: !4, nameTableKind: None)
!20 = distinct !DICompileUnit(language: DW_LANG_Julia, file: !6, producer: "julia", isOptimized: true, runtimeVersion: 0, emissionKind: LineTablesOnly, enums: !4, nameTableKind: None)
!21 = distinct !DICompileUnit(language: DW_LANG_Julia, file: !6, producer: "julia", isOptimized: true, runtimeVersion: 0, emissionKind: LineTablesOnly, enums: !4, nameTableKind: None)
!22 = distinct !DICompileUnit(language: DW_LANG_Julia, file: !6, producer: "julia", isOptimized: true, runtimeVersion: 0, emissionKind: LineTablesOnly, enums: !4, nameTableKind: None)
!23 = distinct !DICompileUnit(language: DW_LANG_Julia, file: !6, producer: "julia", isOptimized: true, runtimeVersion: 0, emissionKind: LineTablesOnly, enums: !4, nameTableKind: None)
!24 = distinct !DICompileUnit(language: DW_LANG_Julia, file: !6, producer: "julia", isOptimized: true, runtimeVersion: 0, emissionKind: LineTablesOnly, enums: !4, nameTableKind: None)
!25 = distinct !DICompileUnit(language: DW_LANG_Julia, file: !6, producer: "julia", isOptimized: true, runtimeVersion: 0, emissionKind: LineTablesOnly, enums: !4, nameTableKind: None)
!26 = distinct !DICompileUnit(language: DW_LANG_Julia, file: !6, producer: "julia", isOptimized: true, runtimeVersion: 0, emissionKind: LineTablesOnly, enums: !4, nameTableKind: None)
!27 = distinct !DICompileUnit(language: DW_LANG_Julia, file: !6, producer: "julia", isOptimized: true, runtimeVersion: 0, emissionKind: LineTablesOnly, enums: !4, nameTableKind: None)
!28 = distinct !DICompileUnit(language: DW_LANG_Julia, file: !6, producer: "julia", isOptimized: true, runtimeVersion: 0, emissionKind: LineTablesOnly, enums: !4, nameTableKind: None)
!29 = distinct !DICompileUnit(language: DW_LANG_Julia, file: !6, producer: "julia", isOptimized: true, runtimeVersion: 0, emissionKind: LineTablesOnly, enums: !4, nameTableKind: None)
!30 = distinct !DICompileUnit(language: DW_LANG_Julia, file: !6, producer: "julia", isOptimized: true, runtimeVersion: 0, emissionKind: LineTablesOnly, enums: !4, nameTableKind: None)
!31 = distinct !DICompileUnit(language: DW_LANG_Julia, file: !6, producer: "julia", isOptimized: true, runtimeVersion: 0, emissionKind: LineTablesOnly, enums: !4, nameTableKind: None)
!32 = distinct !DICompileUnit(language: DW_LANG_Julia, file: !6, producer: "julia", isOptimized: true, runtimeVersion: 0, emissionKind: LineTablesOnly, enums: !4, nameTableKind: None)
!33 = distinct !DICompileUnit(language: DW_LANG_Julia, file: !6, producer: "julia", isOptimized: true, runtimeVersion: 0, emissionKind: LineTablesOnly, enums: !4, nameTableKind: None)
!34 = distinct !DICompileUnit(language: DW_LANG_Julia, file: !10, producer: "julia", isOptimized: true, runtimeVersion: 0, emissionKind: LineTablesOnly, enums: !4, nameTableKind: None)
!35 = distinct !DICompileUnit(language: DW_LANG_Julia, file: !10, producer: "julia", isOptimized: true, runtimeVersion: 0, emissionKind: LineTablesOnly, enums: !4, nameTableKind: None)
!36 = !DILocation(line: 1, scope: !37, inlinedAt: !40)
!37 = distinct !DISubprogram(name: "f;", linkageName: "f", scope: !38, file: !38, type: !39, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !4)
!38 = !DIFile(filename: "REPL[1]", directory: ".")
!39 = !DISubroutineType(types: !4)
!40 = distinct !DILocation(line: 1, scope: !41, inlinedAt: !42)
!41 = distinct !DISubprogram(name: "g", linkageName: "julia_g_2701", scope: null, file: !3, line: 1, type: !39, scopeLine: 1, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !4)
!42 = distinct !DILocation(line: 0, scope: !41)
!43 = !DILocation(line: 1, scope: !41, inlinedAt: !42)
!44 = !DILocation(line: 0, scope: !41, inlinedAt: !42)
; Function Attrs: nosync readnone willreturn mustprogress
define double @preprocess_julia_g_2701.inner.5(i8 zeroext %0, double %1) local_unnamed_addr #4 {
entry:
%2 = call {}*** @julia.get_pgcstack() #5
%3 = and i8 %0, 1, !dbg !36
%.not = icmp eq i8 %3, 0, !dbg !36
%4 = bitcast double %1 to i64, !dbg !36
%.sroa.02.0 = select i1 %.not, i64 0, i64 %4, !dbg !36
%5 = bitcast i64 %.sroa.02.0 to double, !dbg !43
%6 = sitofp i64 %.sroa.02.0 to double, !dbg !43
%.pn = select i1 %.not, double %6, double %5, !dbg !43
%value_phi.i = fmul double %.pn, %1, !dbg !44
ret double %value_phi.i
}
<analysis>
i64 0: {[-1]:Anything}, intvals: {0,}
i8 %0: {[-1]:Integer}, intvals: {}
double %1: {[-1]:Float@double}, intvals: {}
%3 = and i8 %0, 1, !dbg !36: {[-1]:Integer}, intvals: {}
%4 = bitcast double %1 to i64, !dbg !36: {[-1]:Float@double}, intvals: {}
%.sroa.02.0 = select i1 %.not, i64 0, i64 %4, !dbg !36: {[-1]:Integer}, intvals: {}
%6 = sitofp i64 %.sroa.02.0 to double, !dbg !43: {[-1]:Float@double}, intvals: {}
%.not = icmp eq i8 %3, 0, !dbg !36: {[-1]:Integer}, intvals: {}
%value_phi.i = fmul double %.pn, %1, !dbg !44: {[-1]:Float@double}, intvals: {}
%5 = bitcast i64 %.sroa.02.0 to double, !dbg !43: {}, intvals: {}
%.pn = select i1 %.not, double %6, double %5, !dbg !43: {[-1]:Float@double}, intvals: {}
</analysis>
Illegal updateAnalysis prev:{[-1]:Float@double} new: {[-1]:Integer}
val: %4 = bitcast double %1 to i64, !dbg !36 origin= %.sroa.02.0 = select i1 %.not, i64 0, i64 %4, !dbg !36
julia: /workspace/srcdir/Enzyme/enzyme/Enzyme/TypeAnalysis/TypeAnalysis.cpp:643: void TypeAnalyzer::updateAnalysis(llvm::Value*, TypeTree, llvm::Value*): Assertion `0 && "Performed illegal updateAnalysis"' failed.
partially fixed by #263
Should be fixed by https://github.com/EnzymeAD/Enzyme/pull/763/files with strict-aliasing=0
Confirmed fixed with strict aliasing disabled:
julia> Enzyme.API.strictAliasing!(false)
julia> autodiff(g, Active, true, Active(1.0))
(1.0,)