Skip to content

Commit 454b30d

Browse files
authored
Merge pull request #29532 from atrick/comment-cow-array
2 parents b896013 + 17d9d20 commit 454b30d

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

lib/SILOptimizer/LoopTransforms/COWArrayOpt.cpp

+10-5
Original file line numberDiff line numberDiff line change
@@ -849,11 +849,16 @@ bool COWArrayOpt::hoistMakeMutable(ArraySemanticsCall MakeMutable,
849849

850850
// Check whether we can hoist make_mutable based on the operations that are
851851
// in the loop.
852-
// Note that in this case we don't verify that the array buffer is not aliased
853-
// and therefore we must be conservative if the make_mutable is executed
854-
// conditionally (i.e. doesn't dominate all exit blocks).
855-
// The test SILOptimizer/cowarray_opt.sil: dont_hoist_if_executed_conditionally
856-
// shows the problem.
852+
//
853+
// Hoisting make_mutable releases the original array storage. If an alias of
854+
// that storage is accessed on any path reachable from the loop header that
855+
// doesn't already pass through the make_mutable, then hoisting is
856+
// illegal. hasLoopOnlyDestructorSafeArrayOperations checks that the array
857+
// storage is not accessed within the loop. However, this does not include
858+
// paths exiting the loop. Rather than analyzing code outside the loop, simply
859+
// check that the original make_mutable dominates all exits. The test
860+
// SILOptimizer/cowarray_opt.sil: dont_hoist_if_executed_conditionally shows
861+
// the problem.
857862
if (hasLoopOnlyDestructorSafeArrayOperations() && dominatesExits) {
858863
// Done. We can hoist the make_mutable.
859864
// We still need the array uses later to check if we can add loads to

0 commit comments

Comments
 (0)