Skip to content

Optimizer: add simplifications for checked_cast_br and unchecked_ref_cast #66763

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 20, 2023

Conversation

eeckstein
Copy link
Contributor

Look through upcast and init_existential_ref instructions and replace the operand of this cast instruction with the original value. For example:

  %2 = upcast %1 : $Derived to $Base
  %3 = init_existential_ref %2 : $Base : $Base, $AnyObject
  checked_cast_br %3 : $AnyObject to Derived, bb1, bb2

This makes it more likely that the cast can be constant folded because the source operand's type is more accurate. In the example above, the cast reduces to

  checked_cast_br %1 : $Derived to Derived, bb1, bb2

which can be trivially folded to always-succeeds.

Found while looking at _SwiftDeferredNSDictionary.bridgeValues()

@eeckstein
Copy link
Contributor Author

@swift-ci test

@eeckstein
Copy link
Contributor Author

@swift-ci benchmark

…cast

Look through `upcast` and `init_existential_ref` instructions and replace the operand of this cast instruction with the original value.
For example:
```
  %2 = upcast %1 : $Derived to $Base
  %3 = init_existential_ref %2 : $Base : $Base, $AnyObject
  checked_cast_br %3 : $AnyObject to Derived, bb1, bb2
```

This makes it more likely that the cast can be constant folded because the source operand's type is more accurate.
In the example above, the cast reduces to
```
  checked_cast_br %1 : $Derived to Derived, bb1, bb2
```
which can be trivially folded to always-succeeds.

Found while looking at `_SwiftDeferredNSDictionary.bridgeValues()`
@eeckstein eeckstein force-pushed the existential-ref-cast-opt branch from 9f185c7 to 9474b9d Compare June 20, 2023 15:05
@eeckstein
Copy link
Contributor Author

@swift-ci test

@eeckstein eeckstein merged commit f9abb02 into swiftlang:main Jun 20, 2023
@eeckstein eeckstein deleted the existential-ref-cast-opt branch June 20, 2023 20:18
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.

1 participant