-
Notifications
You must be signed in to change notification settings - Fork 10.6k
SILGen: improve code generation for array literals #84795
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
Conversation
@swift-ci smoke test |
@swift-ci apple silicon benchmark |
// DEBUG-NEXT: [AD] Adjoint for the following value is a projection, skipping: %[[#D4:]] = pointer_to_address %[[#D5:]] : $Builtin.RawPointer to [strict] $*Float | ||
// DEBUG-NEXT: [AD] The following active value is loop-local, zeroing its adjoint value in loop header: %[[#D6:]] = apply %[[#]]<Float>(%[[#D2]]) : $@convention(thin) <τ_0_0> (@owned Array<τ_0_0>) -> @owned Array<τ_0_0> | ||
// DEBUG-NEXT: [AD] Setting adjoint value for %[[#D6]] = apply %[[#]]<Float>(%[[#D2]]) : $@convention(thin) <τ_0_0> (@owned Array<τ_0_0>) -> @owned Array<τ_0_0> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kovdan01 Will you please double check that this is expected result here given the change of SIL for array literals?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
338bbd6
to
221d2e8
Compare
221d2e8
to
5fa3183
Compare
@swift-ci test |
@swift-ci apple silicon benchmark |
It used to be done with a library intrinsic which returns the array and an element address pointer. A `mark_dependence` was used to "connect" the two results. But this resulted in completely wrong OSSA after inlining. It just didn't get caught be the verifier because the SIL was obfuscated by address-pointer conversions. Now we don't use the second result (= the element address) of the intrinsic but generate a correct borrow scope from the first (= array) result. Within that borrow scope we project out the element address with a `ref_tail_addr` instruction. This relies on knowledge of the internal Array data structures. However those data structures are baked into the ABI since a long time and will not change.
…_based_sendability.swift TODO: fix handling of Array initialization in the SendNonSenable pass
…e ForEachLoopUnroll pass
…e ArrayCountPropagation pass
This benchmark just wants to test if stack promotion of an array literal works. This is so simple that it's better tested with a lit test.
5fa3183
to
60efd32
Compare
@swift-ci smoke test |
LGTM Please update the PR description as discussed:
OSLogOptimization also generates the previous SILGen pattern -
This may need to be updated as well. |
As this is not actually causing a miscompile, I'll leave that open for future work |
It used to be done with a library intrinsic which returns the array and an element address pointer. A
mark_dependence
was used to "connect" the two results.But the pointer was obtained from a wrong borrow scope and from a wrong copy of the buffer. This resulted in completely wrong OSSA after inlining. It just didn't get caught by the verifier because the SIL was obfuscated by address-pointer conversions.
Now we don't use the second result (= the element address) of the intrinsic but generate a correct borrow scope from the first (= array) result. Within that borrow scope we project out the element address with a
ref_tail_addr
instruction.This relies on knowledge of the internal Array data structures. However those data structures are baked into the ABI since a long time and will not change.