Files
swift-mirror/test/AutoDiff/compiler_crashers_fixed/issue-71164-unreachable-blocks.swift
Anton Korobeynikov f5cce4784f Make autdiff more robust in presence of unreachable blocks (#71356)
Unreachable blocks possess some challenges to autodiff since in reverse pass (pullback generation) we need to execute the function backwards, pushing the values from return BB back to entry block. As a result, unreachable blocks might become reachable from the return BB and this might cause all kind of issues.
2024-02-03 08:33:36 -08:00

45 lines
961 B
Swift

// RUN: %target-swift-frontend -emit-sil -verify %s
// REQUIRES: swift_in_compiler
// https://github.com/apple/swift/issues/71164
// There are few unreachble blocks created due to mandatory boolean constant
// propagation
// Ensure we do not ceeate linear map types for unreachable BB and that they
// are skipped during VJP and pullback generation
import _Differentiation
struct A: Differentiable {}
struct B: Differentiable {
@differentiable(reverse)
func c(b: B) -> A {
while true {
if true {
break
}
};
return A()
}
@differentiable(reverse)
func d(b: B) -> A {
while true {
if true {
return c(b : b)
}
if true {
break
}
if false {
return c(b : b)
} else {
break
}
};
return A()
}
}