Files
swift-mirror/lib/SILOptimizer/Transforms/SSADestroyHoisting.cpp
Nate Chandler 4dec48f9a6 [SSADestroyHoisting] Don't fold over trivial use.
Given an aggregate addr `%agg` with trivial subobject addr `%triv` and
nontrivial subobject addr `%sub` which `%triv` is projected from,
```
  Aggregate   <- %agg
    Subobject <- %sub
      Trivial <- %triv
      ...
    ...
```

after `%sub` is destroyed, `%triv` is no longer initialized.  As a
result, it's not valid to fold a destroy_addr of %agg into a sequence of
`load [copy]`s and `copy_addr`s if there's an access to `%triv` after
the `load [copy]`/`copy_addr` of `%sub` (or some intermediate
subobject).

In other words, transforming
```
  copy_addr %sub
  load [trivial] %triv
  destroy_addr %agg
```
into
```
  copy_addr [take] %sub
  load [trivial] %triv
```
is invalid.

During destroy_addr folding, prevent that from happening by keeping
track of the trivial fields that have already been visited.  If a
trivial field is seen more than once, then bail on folding.  This is
the same as what is done for non-trivial fields except that there's no
requirement that all trivial fields be destroyed.
2023-01-05 15:18:36 -08:00

40 KiB