mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
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.
45 lines
961 B
Swift
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()
|
|
}
|
|
|
|
}
|