Skip to content

Conversation

atrick
Copy link
Contributor

@atrick atrick commented Apr 19, 2019

Canonicalize instruction will be a superset of
simplifyInstruction (once all the transforms are fixed for ownership
SIL). Additionally, it will also include simple SSA-based
canonicalization that requires new instruction creation. It may not
perform any optimization that interferes with diagnostics or increases
compile time.

The SILGenCleanup pass runs before diagnostics to perform any
canonicalization required by diagnostics.

Canonicalization replaces simplifyInstruction in SILCombine so we can
easily factor some existing SILCombine transforms into canonicalization.

@atrick atrick requested a review from gottesmm April 19, 2019 02:50
Copy link
Contributor

@gottesmm gottesmm left a comment

Choose a reason for hiding this comment

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

Quick drive by. I want to do another pass through on this before I give the LGTM. Also can you split this up so that:

  1. Adding the new code/utilities is one commit.
  2. We have separate commits for each pass that are being updated.

@@ -113,6 +135,39 @@ void SILCombineWorklist::add(SILInstruction *I) {
Worklist.push_back(I);
}

// Define a CanonicalizeInstruction subclass for use in SILCombine.
class SILCombineCanonicalize : CanonicalizeInstruction {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you make this final/add override to all of the overridden entry points.

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, fixed.

Copy link
Contributor Author

@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.

I will rebase this soon after splitting it into 4 commits.

SILBasicBlock::iterator canonicalize(SILInstruction *inst);

/// Record a newly generated instruction.
virtual void genInstruction(SILInstruction *inst) = 0;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Much better, fixed.

@@ -113,6 +135,39 @@ void SILCombineWorklist::add(SILInstruction *I) {
Worklist.push_back(I);
}

// Define a CanonicalizeInstruction subclass for use in SILCombine.
class SILCombineCanonicalize : CanonicalizeInstruction {
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, fixed.

@atrick
Copy link
Contributor Author

atrick commented Apr 30, 2019

@gottesmm this PR now has the full set of commits that I want to get into 5.1 to fix exclusivity diagnostics. I'll make a separate PR for store canonicalization for master only.

@atrick
Copy link
Contributor Author

atrick commented Apr 30, 2019

@swift-ci test

@atrick
Copy link
Contributor Author

atrick commented Apr 30, 2019

@swift-ci test source compatibility

@atrick
Copy link
Contributor Author

atrick commented Apr 30, 2019

@swift-ci benchmark

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 6517180eec972c180bfe3b9af6c1d1d99eb33d5b

@swift-ci
Copy link
Contributor

Build failed before running benchmark.

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 6517180eec972c180bfe3b9af6c1d1d99eb33d5b

@atrick
Copy link
Contributor Author

atrick commented May 1, 2019

@swift-ci test

@atrick
Copy link
Contributor Author

atrick commented May 1, 2019

@swift-ci benchmark

@swift-ci
Copy link
Contributor

swift-ci commented May 1, 2019

Build failed
Swift Test Linux Platform
Git Sha - 6517180eec972c180bfe3b9af6c1d1d99eb33d5b

@swift-ci
Copy link
Contributor

swift-ci commented May 1, 2019

Build failed
Swift Test OS X Platform
Git Sha - 6517180eec972c180bfe3b9af6c1d1d99eb33d5b

@swift-ci
Copy link
Contributor

swift-ci commented May 1, 2019

Build failed before running benchmark.

@atrick
Copy link
Contributor Author

atrick commented May 1, 2019

Forced pushed a minor test case fix for i386.

@atrick
Copy link
Contributor Author

atrick commented May 1, 2019

@swift-ci test.

@atrick
Copy link
Contributor Author

atrick commented May 1, 2019

@swift-ci benchmark.

@swift-ci
Copy link
Contributor

swift-ci commented May 1, 2019

Build failed
Swift Test Linux Platform
Git Sha - 9b201f0a616d7132066fc9b172ccaa8d995730e9

@swift-ci
Copy link
Contributor

swift-ci commented May 1, 2019

Build failed
Swift Test OS X Platform
Git Sha - 9b201f0a616d7132066fc9b172ccaa8d995730e9

@atrick
Copy link
Contributor Author

atrick commented May 1, 2019

@swift-ci benchmark

@swift-ci
Copy link
Contributor

swift-ci commented May 1, 2019

Build failed before running benchmark.

@atrick
Copy link
Contributor Author

atrick commented May 1, 2019

@swift-ci benchmark

@atrick
Copy link
Contributor Author

atrick commented May 1, 2019

@gottesmm I don't think there are any more build/test issues to fix here, but I'll wait to restart CI until you've finished your review.

@swift-ci
Copy link
Contributor

swift-ci commented May 1, 2019

Performance: -O

TEST OLD NEW DELTA RATIO
Regression
ArrayPlusEqualArrayOfInt 260 280 +7.7% 0.93x (?)
ArrayAppendToFromGeneric 260 280 +7.7% 0.93x (?)
Improvement
DropLastArrayLazy 5 4 -20.0% 1.25x (?)

Performance: -Osize

TEST OLD NEW DELTA RATIO
Regression
SortLettersInPlace 379 414 +9.2% 0.92x (?)
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

Copy link
Contributor

@gottesmm gottesmm left a comment

Choose a reason for hiding this comment

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

Some more suggestions. I went line by line. I need to read the load [copy] a bit more in depth. While you are looking at these I will look in more depth there.

atrick added 3 commits May 6, 2019 08:36
…ers.

This will make the forthcoming CanonicalizeInstruction interface more
clear.

This is generally the better approach to utilities that mutate the
instruction stream. It avoids the temptation to assume that only a
single instruction will be deleted or that only instructions before
the current iterator will be deleted. This often happens to work but
eventually fails in the presense of debug and end-of-scope
instructions.

A function returning an iterator has a more clear contract than one
accepting some iterator reference of unknown
providence. Unfortunately, it doesn't work at the lowest level of
utilities, such as recursivelyDeleteTriviallyDeadInstructions, where
we want to handle instruction batches.
CanonicalizeInstruction will be a superset of
simplifyInstruction (once all the transforms are fixed for ownership
SIL). Additionally, it will also include simple SSA-based
canonicalization that requires new instruction creation. It may not
perform any optimization that interferes with diagnostics or increases
compile time.

Canonicalization replaces simplifyInstruction in SILCombine so we can
easily factor some existing SILCombine transforms into canonicalization.
The SILGenCleanup pass runs before diagnostics to perform any
canonicalization required by diagnostics.
Copy link
Contributor

@gottesmm gottesmm left a comment

Choose a reason for hiding this comment

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

Some small additional asks. But beyond that... LGTM! This is a great PR! Great work Andy!

atrick added 11 commits May 6, 2019 13:31
Reimplement load instruction canonicalization as part of the
CanonicalizeInstruction utility.
Add -disable-diagnostic-passes because we want to test IRGen on
precisely the SIL input sequence.
Canonical access markers should always guard some memory
operation. It's valid to delete dead access markers even before
exclusivity diagnostics. Deleting dead memory operations before
diagnostics would *not* be ok.
This adds support to the load->struct_extract canonicalization for
nontrivial element types which look like:

load [copy]
borrow
struct_extract
...uses...
end_borrow
destroy
The recursivelyDeleteTriviallyDeadInstructions utility takes a
callBack to be called for every deleted instruction. However, it
wasn't passing this callBack to eraseFromParentWithdebugInsts. The
callback was used to update an iterator in some cases, so not calling
it resulted in iterator invalidation.

Doing this also cleans up the both APIs:
recursivelyDeleteTriviallyDeadInstructions and eraseFromParentWithdebugInsts.
@atrick
Copy link
Contributor Author

atrick commented May 7, 2019

@swift-ci test.

@atrick
Copy link
Contributor Author

atrick commented May 7, 2019

@swift-ci test source compatibility

@swift-ci
Copy link
Contributor

swift-ci commented May 7, 2019

Build failed
Swift Test OS X Platform
Git Sha - 3cda19a226722d3a5c5e127adce5a088b621b673

@swift-ci
Copy link
Contributor

swift-ci commented May 7, 2019

Build failed
Swift Test Linux Platform
Git Sha - 3cda19a226722d3a5c5e127adce5a088b621b673

@atrick atrick merged commit aa6347c into swiftlang:master May 7, 2019
atrick added a commit that referenced this pull request May 7, 2019
[5.1] Merge pull request #24153 from atrick/fix-let-exclusivity
@atrick atrick deleted the fix-let-exclusivity branch May 8, 2019 21:31
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