Skip to content

[semantic-arc] Attempt to handle indirect_mutating parameters that are never written to. #29480

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

gottesmm
Copy link
Contributor

It only handles local writes, so we can not handle chains of inout parameters.
That being said, I wonder if we could hook this up to an analysis to determine
if the inout has this same property in callees.

rdar://problem/58667192


Just had to get this out of my fingers.

@gottesmm
Copy link
Contributor Author

@swift-ci smoke test

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.

To handle calls, this can be converted into a bottom-up IPA... eventually...

Also, is there a possibility this will be called on the same argument multiple times? It's a red flag that you're calling an unbounded def-use analysis from within a use-def analysis.

}

// load_borrow and debug_value_addr are both fine as well.
if (isa<LoadBorrowInst>(user) || isa<DebugValueAddrInst>(user)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

When visiting uses, I like to use isIncidentalUse, instead of checking for Debug opcodes so we can add different "marker" instructions later without auditing all passes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. I was just writing something up real quickly. Also I realized I need to look through access markers.

// interprocedural analysis that we do not perform here.
if (auto fas = FullApplySite::isa(user)) {
if (fas.getArgumentConvention(*op) ==
SILArgumentConvention::Indirect_In_Guaranteed)
Copy link
Contributor

Choose a reason for hiding this comment

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

Too bad you need to hard-code Full-Apply + Indirect_In_Guaranteed. I feel like we should be using the isMutatingOrConsuming logic from the verifier to handle closures, coroutines, and other conventions... but it looks like it returns an overly optimistic results for inout_aliasable

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was just trying to do something really simple. I am going to refactor it out.

@gottesmm
Copy link
Contributor Author

@atrick I don't think this will be unbounded since it does not trigger the parent use-def walk in any way. We may perform the walk multiple times, but always a bounded amount of times.

@gottesmm
Copy link
Contributor Author

From talking with Andy, he was actually referring to quadratic behavior.

@atrick
Copy link
Contributor

atrick commented Jan 28, 2020

When I say "unbounded" I mean there's nothing stopping it from running away on pathological code. You could have 1000 use-def walks in a pathological case, which is ok, but then then same def-use chain will be visited again.. quadratically

@gottesmm gottesmm force-pushed the pr-53b63ed55998c4245196c9d026b31c41598abb2e branch from 40a7730 to ac486a1 Compare January 28, 2020 00:28
@gottesmm
Copy link
Contributor Author

@swift-ci smoke test

1 similar comment
@gottesmm
Copy link
Contributor Author

@swift-ci smoke test

@gottesmm
Copy link
Contributor Author

@swift-ci benchmark

2 similar comments
@gottesmm
Copy link
Contributor Author

@swift-ci benchmark

@gottesmm
Copy link
Contributor Author

@swift-ci benchmark

@gottesmm gottesmm force-pushed the pr-53b63ed55998c4245196c9d026b31c41598abb2e branch from ac486a1 to 79b77f2 Compare January 28, 2020 00:52
@swift-ci
Copy link
Contributor

Build failed before running benchmark.

@gottesmm
Copy link
Contributor Author

@swift-ci test

@gottesmm
Copy link
Contributor Author

@swift-ci smoke test

3 similar comments
@gottesmm
Copy link
Contributor Author

@swift-ci smoke test

@gottesmm
Copy link
Contributor Author

@swift-ci smoke test

@gottesmm
Copy link
Contributor Author

@swift-ci smoke test

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 40a773030b01b98b8dfcdae517f0f4b3020b74fe

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 40a773030b01b98b8dfcdae517f0f4b3020b74fe

@gottesmm gottesmm force-pushed the pr-53b63ed55998c4245196c9d026b31c41598abb2e branch from 79b77f2 to 0f924f0 Compare January 28, 2020 01:05
@gottesmm
Copy link
Contributor Author

Going to do a little more work on this real quick in the background and make sure at least when building the stdlib, I am not missing anything.

@gottesmm gottesmm force-pushed the pr-53b63ed55998c4245196c9d026b31c41598abb2e branch 2 times, most recently from 8da4eed to a4bf2c1 Compare January 28, 2020 01:21
@gottesmm
Copy link
Contributor Author

@swift-ci smoke test

3 similar comments
@gottesmm
Copy link
Contributor Author

@swift-ci smoke test

@gottesmm
Copy link
Contributor Author

@swift-ci smoke test

@gottesmm
Copy link
Contributor Author

@swift-ci smoke test

@gottesmm
Copy link
Contributor Author

@swift-ci benchmark

1 similar comment
@gottesmm
Copy link
Contributor Author

@swift-ci benchmark

@gottesmm
Copy link
Contributor Author

@swift-ci benchmark

3 similar comments
@gottesmm
Copy link
Contributor Author

@swift-ci benchmark

@gottesmm
Copy link
Contributor Author

@swift-ci benchmark

@gottesmm
Copy link
Contributor Author

@swift-ci benchmark

@swift-ci
Copy link
Contributor

Performance: -O

Regression OLD NEW DELTA RATIO
FlattenListFlatMap 4102 5049 +23.1% 0.81x (?)
 
Improvement OLD NEW DELTA RATIO
NSStringConversion.Long 570 503 -11.8% 1.13x (?)
ObjectiveCBridgeStubNSDateRefAccess 196 174 -11.2% 1.13x (?)
RemoveWhereMoveInts 19 17 -10.5% 1.12x (?)
RandomShuffleLCG2 464 416 -10.3% 1.12x (?)
ArrayPlusEqualFiveElementCollection 4773 4292 -10.1% 1.11x (?)
StringHashing_fastPrenormal 600 540 -10.0% 1.11x (?)
NormalizedIterator_fastPrenormal 630 570 -9.5% 1.11x
Calculator 143 130 -9.1% 1.10x (?)
MapReduce 218 200 -8.3% 1.09x (?)
RemoveWhereSwapInts 38 35 -7.9% 1.09x (?)
Set.isSubset.Int.Empty 52 48 -7.7% 1.08x (?)
ArraySetElement 283 262 -7.4% 1.08x
DropLastSequence 320 298 -6.9% 1.07x (?)

Code size: -O

Performance: -Osize

Regression OLD NEW DELTA RATIO
Set.isStrictSubset.Int.Empty 47 51 +8.5% 0.92x (?)
ArrayAppendLazyMap 4170 4520 +8.4% 0.92x (?)
 
Improvement OLD NEW DELTA RATIO
ArrayLiteral2 115 100 -13.0% 1.15x (?)
NormalizedIterator_fastPrenormal 640 570 -10.9% 1.12x (?)
StringHashing_fastPrenormal 600 540 -10.0% 1.11x (?)
NormalizedIterator_latin1 222 202 -9.0% 1.10x (?)
NSStringConversion.Long 549 503 -8.4% 1.09x (?)

Code size: -Osize

Improvement OLD NEW DELTA RATIO
ArraySetElement.o 1227 1212 -1.2% 1.01x
Sim2DArray.o 1259 1244 -1.2% 1.01x
COWArrayGuaranteedParameterOverhead.o 1334 1319 -1.1% 1.01x

Performance: -Onone

Improvement OLD NEW DELTA RATIO
PopFrontArray 1960 1580 -19.4% 1.24x
Hanoi 14830 12490 -15.8% 1.19x (?)
ArrayAppendLatin1 12818 11050 -13.8% 1.16x (?)
ArrayAppendAscii 12852 11084 -13.8% 1.16x (?)
ArrayAppendUTF16 12886 11186 -13.2% 1.15x (?)
PopFrontArrayGeneric 3440 3060 -11.0% 1.12x (?)
ArrayOfGenericRef 7300 6660 -8.8% 1.10x (?)
ArrayOfRef 7150 6530 -8.7% 1.09x (?)
ArrayOfGenericPOD2 815 752 -7.7% 1.08x (?)
NormalizedIterator_fastPrenormal 950 880 -7.4% 1.08x (?)

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 mini
  Model Identifier: Macmini8,1
  Processor Name: Intel Core i7
  Processor Speed: 3.2 GHz
  Number of Processors: 1
  Total Number of Cores: 6
  L2 Cache (per Core): 256 KB
  L3 Cache: 12 MB
  Memory: 64 GB

@gottesmm
Copy link
Contributor Author

gottesmm commented Feb 2, 2020

I am going to clean up this a bit to get rid of the quadratic behavior and then in a follow on commit, I am going to add support for handling more complex cases including cases where the value is written to but not in the region we are loading within. I have a simple implementation that should work.

@gottesmm gottesmm changed the title [DRAFT][semantic-arc] Attempt to handle indirect_mutating parameters that are never written to. [semantic-arc] Attempt to handle indirect_mutating parameters that are never written to. Feb 3, 2020
…e never written to.

It only handles local writes, so we can not handle chains of inout parameters.
That being said, I wonder if we could hook this up to an analysis to determine
if the inout has this same property in callees.
@gottesmm gottesmm force-pushed the pr-53b63ed55998c4245196c9d026b31c41598abb2e branch from a4bf2c1 to f9b0f99 Compare February 3, 2020 03:35
@gottesmm
Copy link
Contributor Author

gottesmm commented Feb 3, 2020

@swift-ci test

2 similar comments
@gottesmm
Copy link
Contributor Author

gottesmm commented Feb 3, 2020

@swift-ci test

@gottesmm
Copy link
Contributor Author

gottesmm commented Feb 3, 2020

@swift-ci test

@gottesmm
Copy link
Contributor Author

gottesmm commented Feb 3, 2020

@swift-ci test source compatibility

@gottesmm
Copy link
Contributor Author

gottesmm commented Feb 3, 2020

@swift-ci benchmark

@gottesmm
Copy link
Contributor Author

gottesmm commented Feb 3, 2020

@swift-ci test

@gottesmm
Copy link
Contributor Author

gottesmm commented Feb 3, 2020

@swift-ci test windows platform

@gottesmm
Copy link
Contributor Author

gottesmm commented Feb 3, 2020

@swift-ci benchmark

@gottesmm
Copy link
Contributor Author

gottesmm commented Feb 3, 2020

@swift-ci test source compatibility

@gottesmm
Copy link
Contributor Author

gottesmm commented Feb 3, 2020

@swift-ci test windows platform

@swift-ci
Copy link
Contributor

swift-ci commented Feb 3, 2020

Performance: -O

Improvement OLD NEW DELTA RATIO
FlattenListFlatMap 9599 6962 -27.5% 1.38x (?)
FlattenListLoop 5117 3955 -22.7% 1.29x (?)
CharacterLiteralsLarge 108 97 -10.2% 1.11x
RandomShuffleLCG2 768 704 -8.3% 1.09x (?)
Array2D 7520 6944 -7.7% 1.08x (?)
MapReduceClass2 40 37 -7.5% 1.08x (?)
RemoveWhereSwapInts 67 62 -7.5% 1.08x (?)
ArrayPlusEqualFiveElementCollection 8436 7807 -7.5% 1.08x (?)
ObjectiveCBridgeStubNSDateRefAccess 400 371 -7.2% 1.08x (?)
MapReduceAnyCollection 397 369 -7.1% 1.08x (?)
MapReduce 400 372 -7.0% 1.08x

Code size: -O

Performance: -Osize

Regression OLD NEW DELTA RATIO
FlattenListFlatMap 6888 7531 +9.3% 0.91x (?)
 
Improvement OLD NEW DELTA RATIO
String.replaceSubrange.RepChar.Small 391 355 -9.2% 1.10x (?)
NSStringConversion.LongUTF8 585 539 -7.9% 1.09x (?)
ObjectiveCBridgeStubFromNSDateRef 4010 3710 -7.5% 1.08x (?)

Code size: -Osize

Improvement OLD NEW DELTA RATIO
ArraySetElement.o 1227 1212 -1.2% 1.01x
Sim2DArray.o 1259 1244 -1.2% 1.01x
COWArrayGuaranteedParameterOverhead.o 1334 1319 -1.1% 1.01x

Performance: -Onone

Improvement OLD NEW DELTA RATIO
PopFrontArray 3500 2980 -14.9% 1.17x (?)
FatCompactMap 491850 420500 -14.5% 1.17x (?)
FindString.Rec3.Substring 1054 903 -14.3% 1.17x (?)
LazilyFilteredArrays2 133800 115200 -13.9% 1.16x (?)
Hanoi 22060 19050 -13.6% 1.16x (?)
FindString.Rec3.String 1070 937 -12.4% 1.14x (?)
LazilyFilteredArrayContains 1380100 1210500 -12.3% 1.14x (?)
ArrayAppendAscii 21114 18632 -11.8% 1.13x (?)
ArrayAppendLatin1 21046 18700 -11.1% 1.13x (?)
ArrayAppendUTF16 20876 18564 -11.1% 1.12x
ChainedFilterMap 343773 306594 -10.8% 1.12x (?)
StringUTF16SubstringBuilder 18770 16770 -10.7% 1.12x (?)
String.replaceSubrange.RepChar.Small 397 359 -9.6% 1.11x (?)
Histogram 8873 8063 -9.1% 1.10x (?)
ArrayOfRef 9500 8650 -8.9% 1.10x (?)
ArrayOfGenericRef 9600 8760 -8.7% 1.10x (?)
PopFrontArrayGeneric 5960 5440 -8.7% 1.10x (?)
FlattenListFlatMap 266394 243526 -8.6% 1.09x (?)
RangeReplaceableCollectionPlusDefault 7272 6672 -8.3% 1.09x (?)
ArrayOfPOD 1125 1038 -7.7% 1.08x (?)
ArrayPlusEqualSingleElementCollection 204591 189974 -7.1% 1.08x (?)
ArrayPlusEqualFiveElementCollection 163503 151996 -7.0% 1.08x (?)
ArrayAppendAsciiSubstring 50004 46620 -6.8% 1.07x (?)

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

@gottesmm gottesmm merged commit 9ce20c4 into swiftlang:master Feb 3, 2020
@gottesmm gottesmm deleted the pr-53b63ed55998c4245196c9d026b31c41598abb2e branch February 3, 2020 12:27
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.

3 participants