Skip to content
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

[semantic-arc-opts] Implement @owned phi web elimination for phi webs with a single phi node that only have copy_value introducers. #30289

Conversation

gottesmm
Copy link
Contributor

@gottesmm gottesmm commented Mar 8, 2020

This is the most simple initial version that I can commit. The hope is that this will help to bring this up in a nice way.

I am going to handle the multiple phi node and load [copy] case later to reduce
code churn.

rdar://problem/56720436

@gottesmm gottesmm requested a review from atrick March 8, 2020 22:08
@gottesmm
Copy link
Contributor Author

gottesmm commented Mar 8, 2020

@swift-ci test

@gottesmm
Copy link
Contributor Author

gottesmm commented Mar 8, 2020

@swift-ci benchmark

@gottesmm
Copy link
Contributor Author

gottesmm commented Mar 8, 2020

@swift-ci test source compatibility

@gottesmm
Copy link
Contributor Author

gottesmm commented Mar 8, 2020

This is also one of the most simple cases, so I am not necessarily expecting a large change in perf. Will take what I can get though = p.

@swift-ci
Copy link
Contributor

swift-ci commented Mar 8, 2020

Performance: -O

Code size: -O

Performance: -Osize

Improvement OLD NEW DELTA RATIO
ObjectiveCBridgeStubFromNSStringRef 93 86 -7.5% 1.08x (?)

Code size: -Osize

Performance: -Onone

Improvement OLD NEW DELTA RATIO
DataCreateEmpty 750 690 -8.0% 1.09x (?)
Data.hash.Empty 102 94 -7.8% 1.09x (?)

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 Mar 8, 2020

I think the release failure is a problem on the bot. Saw this:

16:02:11 <unknown>:0: note: Cannot read '/Users/buildnode/jenkins/workspace-private/swift-PR-source-compat-suite/build/compat_macos/swift-macosx-x86_64/./lib/swift/iphonesimulator/layouts-x86_64.yaml'
16:02:11 Stack dump:

@gottesmm
Copy link
Contributor Author

gottesmm commented Mar 9, 2020

Reproduced the failure locally. I wonder if it is non-deterministic.

@gottesmm
Copy link
Contributor Author

gottesmm commented Mar 9, 2020

Debug source compat passed. I think the release one hit a race. Going to rerun.

@gottesmm
Copy link
Contributor Author

gottesmm commented Mar 9, 2020

@swift-ci test source compatibility

@gottesmm
Copy link
Contributor Author

gottesmm commented Mar 9, 2020

One of the failures in release suite looks real and actually related to the logic. Other has to do with my not being aggressive enough using autogenerated locations.

@gottesmm
Copy link
Contributor Author

gottesmm commented Mar 9, 2020

Looking at the failures now.

… with a single phi node that only have copy_value introducers.

This is the most simple initial version that I can commit. The hope is that this will help to bring this up in a nice way.

I am going to handle the multiple phi node and load [copy] case later to reduce
code churn.

<rdar://problem/56720436>
@gottesmm
Copy link
Contributor Author

gottesmm commented Mar 9, 2020

Found the core store issue. I used a propagated a branch location onto a begin_borrow. I just changed it to use an autogenerated location.

@gottesmm gottesmm force-pushed the pr-645bd01cfa67ffe64ed23d74e1ee1333fce6ba8a branch from 0245ac3 to 6fee59b Compare March 9, 2020 23:50
@gottesmm
Copy link
Contributor Author

gottesmm commented Mar 9, 2020

Both turned out to be the loc issue.

@gottesmm
Copy link
Contributor Author

gottesmm commented Mar 9, 2020

@swift-ci test source compatibility

2 similar comments
@gottesmm
Copy link
Contributor Author

gottesmm commented Mar 9, 2020

@swift-ci test source compatibility

@gottesmm
Copy link
Contributor Author

gottesmm commented Mar 9, 2020

@swift-ci test source compatibility

@gottesmm
Copy link
Contributor Author

gottesmm commented Mar 9, 2020

@swift-ci test

2 similar comments
@gottesmm
Copy link
Contributor Author

gottesmm commented Mar 9, 2020

@swift-ci test

@gottesmm
Copy link
Contributor Author

gottesmm commented Mar 9, 2020

@swift-ci test

@gottesmm
Copy link
Contributor Author

@atrick was just thinking. I think the same approach here would work with tuples and other aggregate forming instructions. They act as a phi in a certain sense of their operand's ownership.

@gottesmm
Copy link
Contributor Author

I talked with Andy offline. I am going to refactor parts of it according to his asks in a forthcoming commit.

@gottesmm gottesmm merged commit cee2af0 into swiftlang:master Mar 10, 2020
@gottesmm gottesmm deleted the pr-645bd01cfa67ffe64ed23d74e1ee1333fce6ba8a branch March 10, 2020 04:55
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.

Just a few insignificant comments... This and all the offline feedback can go into a separate PR

return destroyingUses.front();
}

/// If this LiveRange has a single unknown destroying use, return that
Copy link
Contributor

Choose a reason for hiding this comment

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

unknown destroying use

To be consistent: "unknown consuming use"

ArrayRef<Operand *> getNonConsumingForwardingUses() const {
return generalForwardingUses;
}

void convertOwnedGeneralForwardingUsesToGuaranteed();
Copy link
Contributor

Choose a reason for hiding this comment

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

convertOwnedGeneralForwardingUsesToGuaranteed

This declaration has a cryptic name, so should have a doc comment description

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 have a patch but it conflicts my other fix patch. I am going to wait for that to land then get to this.

@davezarzycki
Copy link
Contributor

davezarzycki commented Mar 10, 2020

Hi @gottesmm – This breaks my Fedora 31 box (x86_64). Do you have a quick fix or can we revert this?

[EDIT] – Updated with a debug backtrace:

FAIL: Swift(linux-x86_64) :: SILOptimizer/semantic-arc-opts.sil (953 of 12842)
******************** TEST 'Swift(linux-x86_64) :: SILOptimizer/semantic-arc-opts.sil' FAILED ********************
Script:
--
: 'RUN: at line 1';   /home/dave/b/u/d/bin/sil-opt -target x86_64-unknown-linux-gnu  -module-cache-path '/home/dave/b/u/d/swift-test-results/x86_64-unknown-linux-gnu/clang-module-cache'  -module-name Swift -enable-sil-verify-all -semantic-arc-opts /home/dave/s/u/swift/test/SILOptimizer/semantic-arc-opts.sil | '/usr/bin/python2.7' '/home/dave/s/u/swift/utils/PathSanitizingFileCheck' --sanitize BUILD_DIR='/home/dave/b/u/d/tools/swift' --sanitize SOURCE_DIR='/home/dave/s/u/swift' --use-filecheck '/home/dave/b/u/d/bin/FileCheck'  /home/dave/s/u/swift/test/SILOptimizer/semantic-arc-opts.sil
--
Exit Code: 2

Command Output (stderr):
--
SIL verification failed: instruction isn't dominated by its operand: properlyDominates(valueI, I)
Verifying instruction:
     %7 = begin_borrow %0 : $Klass                // users: %3, %8
->   %3 = begin_borrow %7 : $Klass                // user: %4
     br bb5(%3 : $Klass)                          // id: %4
In function:
// copy_guaranteed_three_copy_simple
sil [ossa] @copy_guaranteed_three_copy_simple : $@convention(thin) (@guaranteed Klass) -> () {
// %0                                             // user: %7
bb0(%0 : @guaranteed $Klass):
  cond_br undef, bb1, bb2                         // id: %1

bb1:                                              // Preds: bb0
  cond_br undef, bb3, bb4                         // id: %2

bb2:                                              // Preds: bb0
  %3 = begin_borrow %7 : $Klass                   // user: %4
  br bb5(%3 : $Klass)                             // id: %4

bb3:                                              // Preds: bb1
  %5 = begin_borrow %5 : $Klass                   // users: %6, %5
  br bb5(%5 : $Klass)                             // id: %6

bb4:                                              // Preds: bb1
  %7 = begin_borrow %0 : $Klass                   // users: %3, %8
  br bb5(%7 : $Klass)                             // id: %8

// %9                                             // user: %10
bb5(%9 : @guaranteed $Klass):                     // Preds: bb4 bb3 bb2
  end_borrow %9 : $Klass                          // id: %10
  %11 = tuple ()                                  // user: %12
  return %11 : $()                                // id: %12
} // end sil function 'copy_guaranteed_three_copy_simple'

Stack dump:
0.      Program arguments: /home/dave/b/u/d/bin/sil-opt -target x86_64-unknown-linux-gnu -module-cache-path /home/dave/b/u/d/swift-test-results/x86_64-unknown-linux-gnu/clang-module-cache -module-name Swift -enable-sil-verify-all -semantic-arc-opts /home/dave/s/u/swift/test/SILOptimizer/semantic-arc-opts.sil 
1.      While evaluating request ExecuteSILPipelineRequest(Run pipelines { Pass List Pipeline } on SIL for Swift.Swift)
2.      While running pass #84 SILFunctionTransform "SemanticARCOpts" on SILFunction "@copy_guaranteed_three_copy_simple".
 for /home/dave/s/u/swift/test/SILOptimizer/semantic-arc-opts.sil:1961:13
3.      While verifying SIL function "@copy_guaranteed_three_copy_simple".
 for /home/dave/s/u/swift/test/SILOptimizer/semantic-arc-opts.sil:1961:13
 #0 0x000000000bf01187 llvm::sys::PrintStackTrace(llvm::raw_ostream&) /home/dave/s/u/llvm/lib/Support/Unix/Signals.inc:548:11
 #1 0x000000000bf01329 PrintStackTraceSignalHandler(void*) /home/dave/s/u/llvm/lib/Support/Unix/Signals.inc:609:1
 #2 0x000000000beffc9b llvm::sys::RunSignalHandlers() /home/dave/s/u/llvm/lib/Support/Signals.cpp:67:5
 #3 0x000000000bf019cb SignalHandler(int) /home/dave/s/u/llvm/lib/Support/Unix/Signals.inc:390:1
 #4 0x00007ffff7fa2b20 __restore_rt (/lib64/libpthread.so.0+0x14b20)
 #5 0x00007ffff6152625 raise (/lib64/libc.so.6+0x3c625)
 #6 0x00007ffff613b8d9 abort (/lib64/libc.so.6+0x258d9)
 #7 0x0000000005ea8722 (anonymous namespace)::SILVerifier::_require(bool, llvm::Twine const&, std::__1::function<void ()> const&) /home/dave/s/u/swift/lib/SIL/SILVerifier.cpp:690:7
 #8 0x0000000005eb3db0 (anonymous namespace)::SILVerifier::checkSILInstruction(swift::SILInstruction*) /home/dave/s/u/swift/lib/SIL/SILVerifier.cpp:1054:11
 #9 0x0000000005eb3165 (anonymous namespace)::SILVerifier::visitSILInstruction(swift::SILInstruction*) /home/dave/s/u/swift/lib/SIL/SILVerifier.cpp:973:34
#10 0x0000000005eb30fb swift::SILInstructionVisitor<(anonymous namespace)::SILVerifier, void>::visitSingleValueInstruction(swift::SingleValueInstruction*) /home/dave/s/u/swift/include/swift/SIL/SILNodes.def:424:1
#11 0x0000000005eb141a (anonymous namespace)::SILVerifierBase<(anonymous namespace)::SILVerifier>::visitBeginBorrowInst(swift::BeginBorrowInst*) /home/dave/s/u/swift/include/swift/SIL/SILNodes.def:590:3
#12 0x0000000005ead9e7 swift::SILInstructionVisitor<(anonymous namespace)::SILVerifier, void>::visit(swift::SILInstruction*) /home/dave/s/u/swift/include/swift/SIL/SILNodes.def:590:3
#13 0x0000000005eaccaa swift::SILVisitorBase<(anonymous namespace)::SILVerifier, void>::visitSILBasicBlock(swift::SILBasicBlock*) /home/dave/s/u/swift/include/swift/SIL/SILVisitor.h:37:18
#14 0x0000000005eacc01 (anonymous namespace)::SILVerifier::visitSILBasicBlock(swift::SILBasicBlock*) /home/dave/s/u/swift/lib/SIL/SILVerifier.cpp:5055:27
#15 0x0000000005eaa507 (anonymous namespace)::SILVerifier::visitSILBasicBlocks(swift::SILFunction*) /home/dave/s/u/swift/lib/SIL/SILVerifier.cpp:5071:63
#16 0x0000000005ea8a00 (anonymous namespace)::SILVerifier::visitSILFunction(swift::SILFunction*) /home/dave/s/u/swift/lib/SIL/SILVerifier.cpp:5127:28
#17 0x0000000005ea4b6c (anonymous namespace)::SILVerifier::verify() /home/dave/s/u/swift/lib/SIL/SILVerifier.cpp:5137:3
#18 0x0000000005ea468b swift::SILFunction::verify(bool) const /home/dave/s/u/swift/lib/SIL/SILVerifier.cpp:5158:3
#19 0x0000000004d4ba0d swift::SILPassManager::runPassOnFunction(unsigned int, swift::SILFunction*) /home/dave/s/u/swift/lib/SILOptimizer/PassManager/PassManager.cpp:450:20
#20 0x0000000004d4cb04 swift::SILPassManager::runFunctionPasses(unsigned int, unsigned int) /home/dave/s/u/swift/lib/SILOptimizer/PassManager/PassManager.cpp:513:5
#21 0x0000000004d4d859 swift::SILPassManager::execute() /home/dave/s/u/swift/lib/SILOptimizer/PassManager/PassManager.cpp:0:5
#22 0x0000000004d5b014 swift::SILPassManager::executePassPipelinePlan(swift::SILPassPipelinePlan const&) /home/dave/s/u/swift/include/swift/SILOptimizer/PassManager/PassManager.h:258:42
#23 0x0000000004d4a593 swift::ExecuteSILPipelineRequest::evaluate(swift::Evaluator&, swift::SILPipelineExecutionDescriptor) const /home/dave/s/u/swift/lib/SILOptimizer/PassManager/PassManager.cpp:282:6
#24 0x0000000004d490c0 llvm::Expected<bool> swift::SimpleRequest<swift::ExecuteSILPipelineRequest, bool (swift::SILPipelineExecutionDescriptor), (swift::CacheKind)0>::callDerived<0ul>(swift::Evaluator&, std::__1::integer_sequence<unsigned long, 0ul>) const /home/dave/s/u/swift/include/swift/AST/SimpleRequest.h:200:24
#25 0x0000000004d4900e swift::SimpleRequest<swift::ExecuteSILPipelineRequest, bool (swift::SILPipelineExecutionDescriptor), (swift::CacheKind)0>::evaluateRequest(swift::ExecuteSILPipelineRequest const&, swift::Evaluator&) /home/dave/s/u/swift/include/swift/AST/SimpleRequest.h:219:20
#26 0x0000000004d6258d llvm::Expected<swift::ExecuteSILPipelineRequest::OutputType> swift::Evaluator::getResultUncached<swift::ExecuteSILPipelineRequest>(swift::ExecuteSILPipelineRequest const&) /home/dave/s/u/swift/include/swift/AST/Evaluator.h:370:3
#27 0x0000000004d5b19b llvm::Expected<swift::ExecuteSILPipelineRequest::OutputType> swift::Evaluator::operator()<swift::ExecuteSILPipelineRequest, (void*)0>(swift::ExecuteSILPipelineRequest const&) /home/dave/s/u/swift/include/swift/AST/Evaluator.h:282:12
#28 0x0000000004d4a64a swift::executePassPipelinePlan(swift::SILModule*, swift::SILPassPipelinePlan const&, bool, swift::irgen::IRGenModule*) /home/dave/s/u/swift/lib/SILOptimizer/PassManager/PassManager.cpp:292:24
#29 0x00000000045cb0c3 runCommandLineSelectedPasses(swift::SILModule*, swift::irgen::IRGenModule*) /home/dave/s/u/swift/tools/sil-opt/SILOpt.cpp:277:3
#30 0x00000000045ca6da main /home/dave/s/u/swift/tools/sil-opt/SILOpt.cpp:475:7
#31 0x00007ffff613d1a3 __libc_start_main (/lib64/libc.so.6+0x271a3)
#32 0x00000000045c926e _start (/home/dave/b/u/d/bin/sil-opt+0x45c926e)
FileCheck error: '-' is empty.
FileCheck command line:  /home/dave/b/u/d/bin/FileCheck /home/dave/s/u/swift/test/SILOptimizer/semantic-arc-opts.sil

gottesmm added a commit that referenced this pull request Mar 11, 2020
gottesmm added a commit that referenced this pull request Mar 11, 2020
…0070d8cd472328

[semantic-arc-opts] Follow ups to #30289
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