[SR-15259] Should be possible to statically optimise out calls to swift_isUniquelyReferenced_nonNull_native immediately after retain call #57581
Labels
bug
A deviation from expected or documented behavior. Also: expected but undesirable behavior.
compiler
The Swift compiler in itself
performance
Environment
Swift 5.5 RELEASE
Additional Detail from JIRA
md5: cae4a3377826580828afb9b77121337e
Issue Description:
Consider the following function:
When compiled (see this godbolt page) this includes the following lines of assembly for part of the first two lines:
In this instance, we load the empty array storage into r15. We then retain r15 and then pass it to swift_isUniquelyReferenced_nonNull_native.
This pattern has a statically-known result: the call to isUniquelyReferenced can only return false. In this instance, we have issued a retain call on a strong reference and, without any intervening release, we have then asked if it is uniquely referenced. Of course, it cannot be: we just issued a +1 and the object was already held strongly (at +1).
In principle we could have safely elided the call to isUniquelyReferenced, the jump, and just hit the resize operation in straight-line code. This would be a bit of a code size win.
The text was updated successfully, but these errors were encountered: