Skip to content

Commit f961e33

Browse files
committed
Ensure we're commuting instructions only when internal one has a single
use. Fix couple of similar single use predicates while there. Fixes #78848
1 parent b98ca03 commit f961e33

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

lib/SILOptimizer/SILCombiner/SILCombinerCastVisitors.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,7 @@ SILInstruction *SILCombiner::visitConvertEscapeToNoEscapeInst(
790790
//
791791
// This unblocks the `thin_to_thick_function` peephole optimization below.
792792
if (auto *CFI = dyn_cast<ConvertFunctionInst>(Cvt->getOperand())) {
793-
if (CFI->getSingleUse()) {
793+
if (hasOneNonDebugUse(CFI)) {
794794
if (auto *TTTFI = dyn_cast<ThinToThickFunctionInst>(CFI->getOperand())) {
795795
if (TTTFI->getSingleUse()) {
796796
auto convertedThickType = CFI->getType().castTo<SILFunctionType>();
@@ -836,7 +836,7 @@ SILInstruction *SILCombiner::visitConvertEscapeToNoEscapeInst(
836836
// %vjp' = convert_escape_to_noescape %vjp
837837
// %y = differentiable_function(%orig', %jvp', %vjp')
838838
if (auto *DFI = dyn_cast<DifferentiableFunctionInst>(Cvt->getOperand())) {
839-
if (DFI->hasOneUse()) {
839+
if (hasOneNonDebugUse(DFI)) {
840840
auto createConvertEscapeToNoEscape =
841841
[&](NormalDifferentiableFunctionTypeComponent extractee) {
842842
if (!DFI->hasExtractee(extractee))
@@ -1020,9 +1020,7 @@ SILCombiner::visitConvertFunctionInst(ConvertFunctionInst *cfi) {
10201020
// %vjp' = convert_function %vjp
10211021
// %y = differentiable_function(%orig', %jvp', %vjp')
10221022
if (auto *DFI = dyn_cast<DifferentiableFunctionInst>(cfi->getOperand())) {
1023-
// Workaround for a problem with OSSA: https://github.com/swiftlang/swift/issues/78848
1024-
// TODO: remove this if-statement once the underlying problem is fixed.
1025-
if (cfi->getFunction()->hasOwnership())
1023+
if (!hasOneNonDebugUse(DFI))
10261024
return nullptr;
10271025

10281026
auto createConvertFunctionOfComponent =

0 commit comments

Comments
 (0)