Uploaded image for project: 'Swift'
  1. Swift
  2. SR-5403

Memory Optimization Opportunity (Load/Store forwarding)

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Medium
    • Resolution: Done
    • Component/s: Compiler
    • Labels:

      Description

      This is sad:

      // protocol witness for B.foo(_:) in conformance OtherB
      sil shared [transparent] [serialized] [thunk] @_T04test6OtherBCAA1BA2aDP3fooyAA1ACFTW : $@convention(witness_method) (@owned A, @in_guaranteed OtherB) -> () {
      // %0                                             // user: %7
      // %1                                             // user: %3
      bb0(%0 : $A, %1 : $*OtherB):
        %2 = alloc_stack $OtherB                        // users: %9, %4, %11, %7
        %3 = load %1 : $*OtherB                         // users: %6, %4
        store %3 to %2 : $*OtherB                       // id: %4
        // function_ref B.foo(_:)
        %5 = function_ref @_T04test1BPAAE3fooyAA1ACF : $@convention(method) <τ_0_0 where τ_0_0 : B> (@owned A, @in_guaranteed τ_0_0) -> () // user: %7
        strong_retain %3 : $OtherB                      // id: %6
        %7 = apply %5<OtherB>(%0, %2) : $@convention(method) <τ_0_0 where τ_0_0 : B> (@owned A, @in_guaranteed τ_0_0) -> ()
        %8 = tuple ()                                   // user: %12
        %9 = load %2 : $*OtherB                         // user: %10
        strong_release %9 : $OtherB                     // id: %10
        dealloc_stack %2 : $*OtherB                     // id: %11
        return %8 : $()                                 // id: %12
      } // end sil function '_T04test6OtherBCAA1BA2aDP3fooyAA1ACFTW'
      

      This should get fixed by moving to opaque value types. At that point the load store stuff would disappear and the ARC optimizer would see a retain/release on the same value and should remove it.

      If memory ops could just tell that the apply does not write to the alloc_stack (it could because @in_guaranteed doe not modify the alloc_stack)_ … i would expect it to mem promote the store load sequence.

        Attachments

          Activity

            People

            Assignee:
            jw Johannes Weiss
            Reporter:
            aschwaighofer@apple.com Arnold Schwaighofer
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: