Skip to content

Conversation

nate-chandler
Copy link
Contributor

@nate-chandler nate-chandler commented Nov 16, 2023

Description: Make DCE mark instructions added by InstructionDeleter live.

In OSSA, the InstructionDeleter may insert instructions when it deletes a dead instruction. Specifically, when the instruction that is deleted would have resulted in something being destroyed, it inserts an instruction to destroy that thing. For example, if the InstructionDeleter deletes an instruction which consumes a value, such as a cast of an owned value, it inserts a destroy_value of that value. In the same vein, when deleting a load [take], it inserts destroy_addr of the the taken-from address.

Previously, DCE didn't observe these newly created instructions. As a result it was able to delete them.

Here, the newly created instructions are marked live, preventing DCE from deleting them.

Risk: Low. The patch makes DCE delete less code.

Scope: Affects dead code deletion.

Original PR: #69898

Reviewed By: Andrew Trick ( @atrick )

Testing: Added tests.

Resolves: rdar://118524766

In cea0f00, `InstructionDeleter` began
deleting `load [take]` instructions.  Analogous to how it creates a
`destroy_value` when deleting an instruction which consumes a value, in
the case of deleting a `load [take]` the `InstructionDeleter` inserts a
compensating `destroy_addr`.

Previously, `DeadCodeElimination` did not observe the creation of any
instructions created by the `InstructionDeleter`.  In the case of the
newly created `destroy_addr`, DCE didn't mark that the `destroy_addr`
was live and so deleted it.  The result was a leak.

Here, this is fixed by passing an `InstModCallbacks`--with an
`onCreateNewInst` implementation--down into `erasePhiArgument` that
eventually invokes the `InstructionDeleter`.  When the
`InstructionDeleter` creates a new instruction, DCE marks it live.
@nate-chandler nate-chandler force-pushed the cherrypick/release/5.10/bug/20231115/1/dce_instdeleter_loadtake branch from e696502 to cc0430c Compare November 16, 2023 20:33
@nate-chandler
Copy link
Contributor Author

@swift-ci please test

@nate-chandler
Copy link
Contributor Author

@swift-ci please test linux platform

@nate-chandler nate-chandler marked this pull request as ready for review November 16, 2023 20:48
@nate-chandler nate-chandler requested a review from a team as a code owner November 16, 2023 20:48
@nate-chandler nate-chandler merged commit c0f4278 into swiftlang:release/5.10 Nov 17, 2023
@nate-chandler nate-chandler deleted the cherrypick/release/5.10/bug/20231115/1/dce_instdeleter_loadtake branch November 29, 2023 00:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants