Skip to content

DeadObjectElimination: delete dead arrays for which the "destroyArray" builtin is inlined. #35737

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 4 commits into from
Feb 4, 2021

Conversation

eeckstein
Copy link
Contributor

This is needed for non-OSSA SIL: in case we see a destroyArray builtin, we can safely remove the otherwise dead array.
This optimization kicks in later in the pipeline, after array semantics are already inlined (for early SIL, DeadObjectElimination can remove arrays based on semantics).

rdar://73569282
https://bugs.swift.org/browse/SR-14100

@eeckstein
Copy link
Contributor Author

@swift-ci test

@eeckstein
Copy link
Contributor Author

@swift-ci benchmark

@eeckstein eeckstein requested a review from atrick February 3, 2021 18:33
@swift-ci
Copy link
Contributor

swift-ci commented Feb 3, 2021

Performance: -O

Regression OLD NEW DELTA RATIO
FlattenListLoop 1653 2514 +52.1% 0.66x (?)
FlattenListFlatMap 4821 6695 +38.9% 0.72x (?)
NSStringConversion.MutableCopy.Rebridge 810 954 +17.8% 0.85x (?)
ObjectiveCBridgeFromNSSetAnyObjectToStringForced 88000 95500 +8.5% 0.92x (?)

Code size: -O

Performance: -Osize

Improvement OLD NEW DELTA RATIO
FlattenListFlatMap 6666 6097 -8.5% 1.09x (?)

Code size: -Osize

Performance: -Onone

Code size: -swiftlibs

How to read the data The tables contain differences in performance which are larger than 8% and differences in code size which are larger than 1%.

If you see any unexpected regressions, you should consider fixing the
regressions before you merge the PR.

Noise: Sometimes the performance results (not code size!) contain false
alarms. Unexpected regressions which are marked with '(?)' are probably noise.
If you see regressions which you cannot explain you can try to run the
benchmarks again. If regressions still show up, please consult with the
performance team (@eeckstein).

Hardware Overview
  Model Name: Mac Pro
  Model Identifier: MacPro6,1
  Processor Name: 12-Core Intel Xeon E5
  Processor Speed: 2.7 GHz
  Number of Processors: 1
  Total Number of Cores: 12
  L2 Cache (per Core): 256 KB
  L3 Cache: 30 MB
  Memory: 64 GB

Copy link
Contributor

@atrick atrick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fantastic. Thanks!

fyi, the OSSA SILCombine can be tested now, although I realize this is all about late inlining.

// Check if the store is within the range of the destroyed array. In OSSA
// we would not need this check. Otherwise it would be a memory lifetime
// failure.
if (storePath.getOffset() < 0 || storePath.getOffset() >= numDestroyed)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, I can't imagine how this check could be hit, but it doesn't hurt to check I guess.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's not something which is ever generated from swift source, but in SIL it's legal.

Needed to remove unneeded reference counting for String literals.
…" builtin is inlined.

This is needed for non-OSSA SIL: in case we see a destroyArray builtin, we can safely remove the otherwise dead array.
This optimization kicks in later in the pipeline, after array semantics are already inlined (for early SIL, DeadObjectElimination can remove arrays based on semantics).

rdar://73569282
https://bugs.swift.org/browse/SR-14100
The offset was not compared.
@eeckstein
Copy link
Contributor Author

@swift-ci smoke test and merge

@swift-ci swift-ci merged commit 7a7237b into swiftlang:main Feb 4, 2021
@eeckstein eeckstein deleted the doe-destroy-array branch February 4, 2021 11:17
@drodriguez
Copy link
Contributor

Hi,

I was looking at why the Android CI has been failing since https://ci-external.swift.org/job/oss-swift-RA-linux-ubuntu-16.04-android/9117/ and it seems to be because of the changes introduced in the test in this commit. No need to fix it or anything, I am just trying to understand the changes, and how it might be have affected only Android.

This is the failure.

******************** TEST 'Swift(android-armv7) :: SILOptimizer/dead_array_elim.swift' FAILED ********************
Script:
--
: 'RUN: at line 1';   /home/ubuntu/jenkins/workspace/oss-swift-RA-linux-ubuntu-16.04-android/buildbot_linux/swift-linux-x86_64/bin/swift-frontend -target armv7-unknown-linux-android -I /home/ubuntu/android-ndk-r19c/sysroot/usr/include -I /home/ubuntu/android-ndk-r19c/sysroot/usr/include/arm-linux-androideabi -L /home/ubuntu/android-ndk-r19c/sources/cxx-stl/llvm-libc++/libs/armeabi-v7a -L /home/ubuntu/android-ndk-r19c/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/lib/gcc/arm-linux-androideabi/4.9.x -L /home/ubuntu/android-ndk-r19c/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/arm-linux-androideabi/lib  -module-cache-path /home/ubuntu/jenkins/workspace/oss-swift-RA-linux-ubuntu-16.04-android/buildbot_linux/swift-linux-x86_64/swift-test-results/armv7-unknown-linux-androideabi/clang-module-cache -swift-version 4  -ignore-module-source-info -typo-correction-limit 10  -O -emit-sil -primary-file /home/ubuntu/jenkins/workspace/oss-swift-RA-linux-ubuntu-16.04-android/swift/test/SILOptimizer/dead_array_elim.swift | /usr/bin/python3.5 /home/ubuntu/jenkins/workspace/oss-swift-RA-linux-ubuntu-16.04-android/swift/utils/PathSanitizingFileCheck --sanitize BUILD_DIR=/home/ubuntu/jenkins/workspace/oss-swift-RA-linux-ubuntu-16.04-android/buildbot_linux/swift-linux-x86_64 --sanitize SOURCE_DIR=/home/ubuntu/jenkins/workspace/oss-swift-RA-linux-ubuntu-16.04-android/swift --use-filecheck /home/ubuntu/jenkins/workspace/oss-swift-RA-linux-ubuntu-16.04-android/buildbot_linux/llvm-linux-x86_64/bin/FileCheck  /home/ubuntu/jenkins/workspace/oss-swift-RA-linux-ubuntu-16.04-android/swift/test/SILOptimizer/dead_array_elim.swift
--
Exit Code: 1

Command Output (stderr):
--
/home/ubuntu/jenkins/workspace/oss-swift-RA-linux-ubuntu-16.04-android/swift/test/SILOptimizer/dead_array_elim.swift:58:16: error: CHECK-NEXT: is not on the line after the previous match
// CHECK-NEXT: integer_literal $Builtin.Int{{[0-9]+}}, 21
               ^
<stdin>:99:8: note: 'next' match was here
 %18 = integer_literal $Builtin.Int32, 21 // user: %19
       ^
<stdin>:82:55: note: previous match ended here
 debug_value %0 : $String, let, name "stringParameter", argno 1 // id: %1
                                                      ^
<stdin>:83:1: note: non-matching line after previous match is here
 %2 = integer_literal $Builtin.Int32, 1819043176 // user: %3
^

Input file: <stdin>
Check file: /home/ubuntu/jenkins/workspace/oss-swift-RA-linux-ubuntu-16.04-android/swift/test/SILOptimizer/dead_array_elim.swift

-dump-input=help explains the following input dump.

Input was:
<<<<<<
         .
         .
         .
        94:  %13 = struct $String (%12 : $_StringGuts) // users: %16, %15
        95:  retain_value %0 : $String // id: %14
        96:  release_value %13 : $String // id: %15
        97:  release_value %13 : $String // id: %16
        98:  release_value %0 : $String // id: %17
        99:  %18 = integer_literal $Builtin.Int32, 21 // user: %19
next:58            !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~              error: match on wrong line
       100:  %19 = struct $Int (%18 : $Builtin.Int32) // user: %20
       101:  return %19 : $Int // id: %20
       102: } // end sil function '$s15dead_array_elim31testDeadArrayAfterOptimizationsySiSSF'
       103: 
       104: // static Array._adoptStorage(_:count:)
         .
         .
         .
>>>>>>

--

********************

From my understanding of the test (and the JIRA ticket), it seems that the final value 21 is indeed created, but there's seems to be something in between constructing the return value and returning it, and the debug_value line. Those lines are retain_value/release_value, which seems like something is being constructed and destroyed (maybe what these changes tried to remove).

This is Android 32 bits (64 bits works fine), and if I understand correctly Darwin doesn't have a lot of 32 bits platforms lying around anymore, but https://github.com/apple/swift/pull/35737/files#diff-c34c7dab63c3329cf8671662271a8d64c1ee918eff414b91196fe5df89883265R259 looks like something that might not be true for a 32 bit platform.

Any insight will be appreciated. If nobody have any idea, I can simply disable the test with an XFAIL.

@eeckstein
Copy link
Contributor Author

@drodriguez Thanks for letting me know!
I fixed it in #35776

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.

4 participants