From 09f6f4f9b608d57fceba9de2d5a237ee9be8b626 Mon Sep 17 00:00:00 2001 From: Erik Eckstein Date: Wed, 22 Jan 2025 20:30:21 +0100 Subject: [PATCH 1/2] AutodiffClosureSpecialization: workaround a problem with OSSA. Disable the closure specializer optimization for closures in OSSA until the underlying problem is fixed. https://github.com/swiftlang/swift/issues/78847 Part of rdar://140229560 --- .../Optimizer/FunctionPasses/ClosureSpecialization.swift | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/SwiftCompilerSources/Sources/Optimizer/FunctionPasses/ClosureSpecialization.swift b/SwiftCompilerSources/Sources/Optimizer/FunctionPasses/ClosureSpecialization.swift index e0c1a4928a042..19f41dac5c0c3 100644 --- a/SwiftCompilerSources/Sources/Optimizer/FunctionPasses/ClosureSpecialization.swift +++ b/SwiftCompilerSources/Sources/Optimizer/FunctionPasses/ClosureSpecialization.swift @@ -503,6 +503,12 @@ private func handleApplies(for rootClosure: SingleValueInstruction, callSiteMap: continue } + // Workaround for a problem with OSSA: https://github.com/swiftlang/swift/issues/78847 + // TODO: remove this if-statement once the underlying problem is fixed. + if callee.hasOwnership { + continue + } + if callee.isDefinedExternally { continue } From 51628dde1277edbb70a5584a3d1c5341c552c86a Mon Sep 17 00:00:00 2001 From: Erik Eckstein Date: Thu, 23 Jan 2025 09:37:57 +0100 Subject: [PATCH 2/2] SILCombine: workaround a problem with `differential_function` in OSSA Disable this peephole optimization until the underlying problem is fixed. https://github.com/swiftlang/swift/issues/78848 Part of rdar://140229560 --- lib/SILOptimizer/SILCombiner/SILCombinerCastVisitors.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/SILOptimizer/SILCombiner/SILCombinerCastVisitors.cpp b/lib/SILOptimizer/SILCombiner/SILCombinerCastVisitors.cpp index fd0c76e6985bf..fe92106003fa8 100644 --- a/lib/SILOptimizer/SILCombiner/SILCombinerCastVisitors.cpp +++ b/lib/SILOptimizer/SILCombiner/SILCombinerCastVisitors.cpp @@ -1020,6 +1020,11 @@ SILCombiner::visitConvertFunctionInst(ConvertFunctionInst *cfi) { // %vjp' = convert_function %vjp // %y = differentiable_function(%orig', %jvp', %vjp') if (auto *DFI = dyn_cast(cfi->getOperand())) { + // Workaround for a problem with OSSA: https://github.com/swiftlang/swift/issues/78848 + // TODO: remove this if-statement once the underlying problem is fixed. + if (cfi->getFunction()->hasOwnership()) + return nullptr; + auto createConvertFunctionOfComponent = [&](NormalDifferentiableFunctionTypeComponent extractee) { if (!DFI->hasExtractee(extractee))