Skip to content

Commit aa8ce55

Browse files
authored
Merge pull request #34841 from atrick/disable-cpf
2 parents 3b4b1c3 + 39db766 commit aa8ce55

File tree

2 files changed

+57
-938
lines changed

2 files changed

+57
-938
lines changed

lib/SILOptimizer/Transforms/CopyForwarding.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1508,6 +1508,23 @@ class CopyForwardingPass : public SILFunctionTransform
15081508
if (!EnableCopyForwarding && !EnableDestroyHoisting)
15091509
return;
15101510

1511+
// This pass assumes that the ownership lifetime of a value in a memory
1512+
// locations can be determined by analyzing operations on the memory
1513+
// address. However, in non-OSSA code, this is not guaranteed. For example,
1514+
// this is valid non-OSSA SIL:
1515+
//
1516+
// bb0(%0 : $AnyObject):
1517+
// %alloc1 = alloc_stack $AnyObject
1518+
// store %0 to %objaddr : $*AnyObject
1519+
// %ref = load %objaddr : $*AnyObject
1520+
// %alloc2 = alloc_stack $ObjWrapper
1521+
// # The in-memory reference is destroyed before retaining the loaded ref.
1522+
// copy_addr [take] %alloc1 to [initialization] %alloc2 : $*ObjWrapper
1523+
// retain_value %ref : $AnyObject
1524+
// destroy_addr %alloc2 : $*ObjWrapper
1525+
if (!getFunction()->hasOwnership())
1526+
return;
1527+
15111528
LLVM_DEBUG(llvm::dbgs() << "Copy Forwarding in Func "
15121529
<< getFunction()->getName() << "\n");
15131530

0 commit comments

Comments
 (0)