Commit Graph

7345 Commits

Author SHA1 Message Date
eeckstein
d9489d7757 Merge pull request #79604 from eeckstein/fix-licm
LICM: fix handling of stores of Optional.none in OSSA
2025-02-25 22:13:43 +01:00
Dario Rexin
f5dd557307 Merge pull request #79506 from drexin/wip-145095088
[SILOptimizer] Don't apply CMO to key paths that reference inaccessib…
2025-02-25 07:08:52 -08:00
Erik Eckstein
bfdeb57863 LICM: fix handling of stores of Optional.none in OSSA
Currently we don't support hoisting ownership instructions.
But the check was missing a store of Optional.none because such a value has no ownership even if the optional is not trivial.

Fixes a SIL verifier crash.
https://github.com/swiftlang/swift/issues/79491
2025-02-25 09:34:59 +01:00
Dario Rexin
bde7daa2f2 [SILOptimizer] Don't apply CMO to key paths that reference inaccessible properties
rdar://145095088
2025-02-24 23:07:18 -08:00
Meghana Gupta
653925bff0 Merge pull request #79476 from meg-gupta/lrfix
Fix loop rotate when header has instructions producing ownership results
2025-02-20 11:03:31 -08:00
eeckstein
06042c1cba Merge pull request #79483 from eeckstein/fix-temp-lvalue-opt
TempLValueOpt: avoid creating invalid apply argument aliasing.
2025-02-20 06:55:33 +01:00
eeckstein
ee360e0854 Merge pull request #79484 from eeckstein/fix-simplify-cfg
SimplifyCFG: remove all borrowed-from uses from arguments when merging blocks
2025-02-20 06:55:09 +01:00
Meghana Gupta
4561658799 Avoid creating unoptimizable copies in CSE
CSE uses OSSA rauw which creates copies and copies that are created to optimize
across borrow scopes are unoptimizable. This PR avoids this situation for now.
2025-02-19 11:20:43 -08:00
Erik Eckstein
5ef3b96da2 SimplifyCFG: remove all borrowed-from uses from arguments when merging blocks
So far we only considered the forwarding use. But there may be other uses.

Fixes a compiler crash.
rdar://145091197
2025-02-19 13:25:48 +01:00
Erik Eckstein
f0b7bdb382 TempLValueOpt: avoid creating invalid apply argument aliasing.
An indirect argument (except `@inout_aliasable`) must not alias with another indirect argument.
Now, if we would replace tempAddr with destAddr in
```
  apply %f(%tempAddr, %destAddr) : (@in T) -> @out T
```
we would invalidate this rule.
This is even true if the called function does not read from destAddr.

Fixes a SIL verification error.
rdar://145090659
2025-02-19 10:33:18 +01:00
Meghana Gupta
03038d201e Fix loop rotate when header has instructions producing ownership results
rdar://145086395
2025-02-18 14:42:28 -08:00
Doug Gregor
654f8534bd Merge pull request #79399 from DougGregor/enable-span-everywhere
Enable usable of Span by default
2025-02-14 15:39:30 -08:00
Doug Gregor
3c8ef82963 Enable usable of Span by default
Usage of Span was temporarily behind an experimental feature flag. Now
that SE-0447 has been accepted, remove the experimental feature flag and
allow Span usage everywhere.

Implements rdar://144819992.
2025-02-14 10:45:47 -08:00
Erik Eckstein
e9d0393c50 tests: add a missing codesign in SILOptimizer/static_inline_arrays.swift
rdar://144826336
2025-02-14 10:05:06 +01:00
Meghana Gupta
797dd8f4cb Update inlinearray_bounds_check_tests.swift 2025-02-13 15:33:31 -08:00
Meghana Gupta
7b097a0ecb Rename to InlineArray 2025-02-13 12:35:45 -08:00
Meghana Gupta
c93f8a0527 Update Slab bounds check tests 2025-02-13 10:30:25 -08:00
Meghana Gupta
a31a603e49 Handle type_value instruction in CSE 2025-02-13 10:30:25 -08:00
Meghana Gupta
904aac759d Add bounds check tests with Slab 2025-02-13 10:30:25 -08:00
Erik Eckstein
57a236e671 InitializeStaticGlobals: support statically initializing globals which are or contain inline arrays
For example:

```
struct S {
  static let slab: Slab = [1, 2, 3, 4]
}
```

rdar://143005996
2025-02-12 22:37:49 +01:00
Erik Eckstein
3fd93c0dc1 tests: don't print SIL types in the SILOptimizer/init_static_globals.sil test 2025-02-12 22:22:43 +01:00
eeckstein
dff88f968b Merge pull request #79317 from eeckstein/remove-alloc-vector
Remove the experimental FixedArray
2025-02-12 17:03:06 +01:00
Erik Eckstein
5b93eb31bf Optimizer: remove the AllocVectorLowering pass
It's not needed anymore, because the "FixedArray" experimental feature is replaced by inline-arrays.
2025-02-12 10:51:14 +01:00
Erik Eckstein
2962474b58 SimplifyKeyPath: insert the correct destroy operation for an operand of a removed keypath
If the operand is an address, we need to use `destroy_addr` and not `destroy_value`.

Fixes a compiler crash.
rdar://144662171
2025-02-12 08:35:23 +01:00
Meghana Gupta
e6c772b1a9 Merge pull request #79275 from meg-gupta/boundstestsupdate2
[Test] Enable test for all platforms and update check lines
2025-02-11 10:03:40 -08:00
eeckstein
aa0833b0b3 Merge pull request #79110 from eeckstein/verify_mark_dependence
SIL: Fix memory behavior of mark_dependence
2025-02-11 06:39:43 +01:00
Meghana Gupta
69233c729e Merge pull request #79280 from meg-gupta/csetest
[Test] Run test on 64-bit platforms only
2025-02-10 19:03:42 -08:00
Arnold Schwaighofer
ed32270d72 Merge pull request #79191 from aschwaighofer/access_enforcement_fixes
AccessEnforcement: Fix analysis to include mayReleases as potentially executing unknown code
2025-02-10 16:57:31 -08:00
Meghana Gupta
27de3db686 [Test] Run test on 64-bit platforms only
Fixes rdar://144400233
2025-02-10 13:02:52 -08:00
Meghana Gupta
0a860a1215 [Test] Enable test for all platforms and update check lines 2025-02-10 12:37:11 -08:00
Andrew Trick
c2842e8e19 LifetimeDependenceInsertion: remove a bailout on ~Copyable
Needed to diagnose MutableSpan and OutputSpan.

For now, simply remove the bailout and TODO. The next change will introduce more
logic to force a diagnostic error in rare cases that can't be handled completely.

Fixes rdar://143584461 (Extended exclusive borrow issues with
MutableSpan and OutputSpan)
2025-02-10 09:13:27 -08:00
Andrew Trick
fa3ebb5c1e LifetimeDependence.Scope add global variable support.
This fixes functions that return @lifetime(immortal).
2025-02-10 09:11:22 -08:00
Andrew Trick
39bae0bb58 LifetimeDependenceDiagnostics: immortal dependence on global 'let' 2025-02-10 09:11:22 -08:00
Andrew Trick
c3de120ca5 LifetimeDependence: simplify and fix multiple bugs.
Functional changes:

Improved modeling of dependence on local variable scopes.

For nested modify->read accesses, only extend the read accesses.

Avoid making a read access dependent on an inout argument.
The following needs to be an error to prevent span storage from being modified:

  @lifetime(owner)
  foo(owner: inout Owner) -> Span {
    owner.span
  }

Improve usability of borrowing trivial values (UnsafePointer). Allow:

  let span = Span(buffer.baseAddress)

Ignore access scopes for trivial values.

Structural changes:

Delete the LifetimeDependenceUseDefWalker.

Encapsulate all logic for variable introducers within the LifetimeDependenceInsertion pass. Once mark_dependence instructions are inserted, no subsequent pass needs to think about the "root" of a dependence.

Fixes: rdar://142451725 (Escape analysis fails with mutations)
2025-02-10 09:11:22 -08:00
Andrew Trick
c8742e429a Add and update lifetime_dependence unit tests. 2025-02-10 09:11:21 -08:00
Erik Eckstein
6a6d3f0b13 SIL: handle mark_dependence in the MemoryLifetimeVerifier
The check is not perfect, because it only checks that the base operand is alive _at_ the mark_dependence.
Ideally it should check that the base operand is alive during the whole lifetime of the value operand.
2025-02-10 17:57:47 +01:00
Erik Eckstein
a88cb49ee8 SIL: define a memory-read effect on the mark_dependence base value
If the base value of a mark_dependence is an address, that memory location must be initialized at the mark_dependence.
This requires that the mark_dependence is considered to read from the base address.
2025-02-10 17:57:47 +01:00
Erik Eckstein
d918b316c9 TempRValueOptimization: don't optimize copies to mark_dependence base values.
We want to keep the original lifetime of the base. If we would eliminate the base alloc_stack, we risk to insert a destroy_addr too early.
2025-02-10 17:57:47 +01:00
Meghana Gupta
2ac449a545 Update SIL and LLVM check lines 2025-02-09 16:44:54 -08:00
Meghana Gupta
ebdd3683c8 Remove problematic OutputSpan initializers and dependencies
These initializers have ownership errors. Once rdar://144352938 is fixed,
these can be enabled again.
2025-02-09 10:49:10 -08:00
Meghana Gupta
c5f36181a5 Update _overrideLifetime and use -O 2025-02-09 10:48:34 -08:00
Andrew Trick
4f5b614cdc Merge pull request #79239 from atrick/fix-span-test
Fix mutable_span_bounds_check_tests.swift on iOS: REQUIRES: OS=macosx
2025-02-08 22:20:35 -08:00
Guillaume Lessard
2877d5b3f3 [test] expand availability annotations
- MutableSpan’s availability must be as selective as Span’s
2025-02-08 16:18:32 -08:00
Andrew Trick
85ec364c13 Fix mutable_span_bounds_check_tests.swift on iOS: REQUIRES: OS=macosx 2025-02-08 06:16:37 -08:00
eeckstein
c4af3b3a8e Merge pull request #79186 from eeckstein/remove-predictable-memopt
Optimizer: replace PredictableMemoryAccessOptimizations with a "mandatory" redundant load elimination pass
2025-02-08 08:05:33 +01:00
eeckstein
1fcb944934 Merge pull request #79215 from eeckstein/add-arc-test
tests: add a test which checks that only a minimal ARC operations are generated
2025-02-08 01:21:56 +01:00
Meghana Gupta
64ae2a99e8 Merge pull request #79129 from meg-gupta/boundstests
[NFC] Add some span unit tests for bounds check optimizations
2025-02-07 15:44:26 -08:00
Arnold Schwaighofer
7a251af60c AccessEnforcement: Fix analysis to include mayReleases as potentially
executing unknown code

This means we have to claw back some performance by recognizing harmless
releases.

Such as releases on types we known don't call a deinit with unknown
side-effects.

rdar://143497196
rdar://143141695
2025-02-07 15:10:13 -08:00
Erik Eckstein
9a7bcbe2c9 tests: add a test which checks that only a minimal ARC operations are generated
This is the case for the test since we enabled OSSA modules.
rdar://143691773
2025-02-07 17:07:18 +01:00
Erik Eckstein
ba4081ee76 Optimizer: replace PredictableMemoryAccessOptimizations with MandatoryRedundantLoadElimination in the pass pipeline
PredictableMemoryAccessOptimizations has become unmaintainable as-is.
RedundantLoadElimination does (almost) the same thing as PredictableMemoryAccessOptimizations.
It's not as powerful but good enough because PredictableMemoryAccessOptimizations is actually only needed for promoting integer values for mandatory constant propagation.
And most importantly: RedundantLoadElimination does not insert additional copies which was a big problem in PredictableMemoryAccessOptimizations.

Fixes rdar://142814676
2025-02-07 11:30:35 +01:00