llvm::SpillPlacement::addLinks takes all the time with asan or msan and -O2
| Bugzilla Link | 17409 |
| Version | unspecified |
| OS | Linux |
| CC | @atrick,@bcardosolopes,@chandlerc,@cmtice,@echristo,@ramosian-glider,@pcc,@qcolombet,@stephenhines,@stoklund |
Extended Description
This is a continuation of http://llvm.org/bugs/show_bug.cgi?id=12653 and to some extent related to http://llvm.org/bugs/show_bug.cgi?id=12652 Linux x86_64, r191651 (fresh trunk)
We have a large auto-generated (from protobuffers) C++ code, which takes too long to compile at -O2 with asan or msan instrumentation. Most of the time is taken by llvm::SpillPlacement::addLinks
The reproducer is too large to attach here: it is attached to https://b.corp.google.com/viewIssue?id=5993523#ISSUE_HistoryHeader10
for opt in "-O0" "-O1" "-O2" "-O2 -fsanitize=address" "-O2 -fsanitize=memory"; do echo ================ $opt =============; (time perf record -f -- clang $opt -c 1000.cc) 2>&1 perf report 2>&1 | grep "%" | head -5; done
================ -O0 ============= TIME: real: 7.350; user: 4.990; system: 0.260 3.45% clang-3.3 clang-3.3 [.] clang::CFGReverseBlockReachabilityAnalysis::mapReachability(clang::CFGBlock const*) .. ================ -O1 ============= TIME: real: 13.761; user: 13.390; system: 0.210 ... ================ -O2 ============= TIME: real: 38.358; user: 37.320; system: 0.790 3.36% clang-3.3 clang-3.3 [.] llvm::ValueHandleBase::RemoveFromUseList() ... ================ -O2 -fsanitize=address =============
TIME: real: 196.757; user: 194.500; system: 1.230
41.30% clang-3.3 clang-3.3 [.] llvm::SpillPlacement::addLinks(llvm::ArrayRef
mentioned in issue llvm/llvm-bugzilla-archive#33063
mentioned in issue llvm/llvm-bugzilla-archive#24618
mentioned in issue llvm/llvm-bugzilla-archive#24618
mentioned in issue llvm/llvm-bugzilla-archive#22665
mentioned in issue llvm/llvm-bugzilla-archive#22630
mentioned in issue llvm/llvm-bugzilla-archive#21349
mentioned in issue llvm/llvm-bugzilla-archive#21349
mentioned in issue llvm/llvm-bugzilla-archive#19163
*** Bug llvm/llvm-bugzilla-archive#21349 has been marked as a duplicate of this bug. ***
*** Bug llvm/llvm-bugzilla-archive#19163 has been marked as a duplicate of this bug. ***
Another testcase is building gcc. Clang takes several hours when using -fsanitize=undefined. It is embarrassing.
*** Bug llvm/llvm-project#13024 has been marked as a duplicate of this bug. ***
*** Bug llvm/llvm-bugzilla-archive#24618 has been marked as a duplicate of this bug. ***
llvm/llvm-bugzilla-archive#24618 seems to be related to this bug.
*** Bug llvm/llvm-bugzilla-archive#22665 has been marked as a duplicate of this bug. ***
We are now getting hit by this bug in llvm itself. When compiling llvm for coverage-guided fuzzing tools/clang/lib/Lex/ModuleMap.cpp takes 6 minutes to build.
Repro:
clang++ -std=c++11 -c 17409.cpp -O3 -fsanitize=address -fsanitize-coverage=4
26.60% llvm::BranchProbability::scale(unsigned long) const 20.91% llvm::MachineBlockFrequencyInfo::getBlockFreq(llvm::MachineBasicBlock const*) const 18.50% (anonymous namespace)::InlineSpiller::propagateSiblingValue(llvm::DenseMapIterator<llvm::VNInfo*, (anonymous namespace)::InlineSpiller::SibValueInfo, l 7.36% llvm::BlockFrequencyInfoImplBase::getBlockFreq(llvm::BlockFrequencyInfoImplBase::BlockNode const&) const 4.63% llvm::TinyPtrVectorllvm::VNInfo*::push_back(llvm::VNInfo*) 3.16% llvm::SpillPlacement::Node::update(llvm::SpillPlacement::Node const*, llvm::BlockFrequency const&)
We can add more thresholds to the coverage implementation (and we will), but the problem will continue to trouble us
ipc.ii.gz This continues hitting us. At r209613 we get insane compile time with asan on one of the chrome files:
clang -fstack-protector --param=ssp-buffer-size=4 -pthread -fno-exceptions -fno-strict-aliasing -fvisibility=hidden -pipe -fPIC -pthread -m64 -march=x86-64 -fno-omit-frame-pointer -gline-tables-only -fsanitize=address -w -O2 -fdata-sections -ffunction-sections -funwind-tables -fno-rtti -fno-threadsafe-statics -fvisibility-inlines-hidden -std=gnu++11 -c ipc.ii
69.60% clang-3.5 clang-3.5 [.] llvm::SpillPlacement::iterate() 15.76% clang-3.5 clang-3.5 [.] llvm::BlockFrequency::operator+=(llvm::BlockFrequency const&) 8.88% clang-3.5 clang-3.5 [.] llvm::BlockFrequency::operator+(llvm::BlockFrequency const&) const
The function has 9822 memory accesses, which is just below the current threshold 10000. r209623 decreases it further to 7000, but the problem will remain
We've applied a series of changes to asan/msan to reduce the effect of this problem:
- added -mllvm -asan-instrumentation-with-call-threshold=N (default=10000) to use function calls instead of inline checks
- similar flag coming soon in msan: -mllvm -asan-instrumentation-with-call-threshold=N
- -mllvm -asan-coverage-block-threshold=N (default 1500) Add coverage instrumentation only to the entry block if there are more than this number of blocks.
We had to do this to unblock multiple asan/msan/AsanCoverage users, but this is still bad in many ways:
- calls are slower than inline instrumentation
- we essentially doubled the amount of required asan/msan testing (OUCH!)
- sometimes calls actually slowdown the compilation instead of fixing it
- the problem itself is not gone, we've seen it with just O3 w/o any instrumentation (see comment #10)
test cast without addresssanitizer instrumentation I've got a test case without ASan that Clang takes at least 5.5 minutes to compile at -O3, while gcc takes just a few seconds. Profiling suggests that it is the same issue.
14.43% clang-3.5 clang-3.5 [.] _ZN12_GLOBAL__N_113InlineSpiller21propagateSiblingValueEN4llvm16DenseMapIteratorIPNS1_6VNInfoENS0_12SibValueInfoENS1_12DenseMapInfoIS4_EELb0EEES4_.constprop.335
12.38% clang-3.5 clang-3.5 [.] llvm::MachineBasicBlock::getWeightIterator(__gnu_cxx::__normal_iterator<llvm::MachineBasicBlock* const*, std::vector<llvm::MachineBasicBlock*, std::allocator<llvm::MachineBasicBlock*> > >) const
9.30% clang-3.5 clang-3.5 [.] llvm::MachineBranchProbabilityInfo::getEdgeWeight(llvm::MachineBasicBlock const*, __gnu_cxx::__normal_iterator<llvm::MachineBasicBlock* const*, std::vector<llvm::MachineBasicBlock*, std::allocator<llvm::MachineBasicBlock*> > >) const
9.03% clang-3.5 clang-3.5 [.] llvm::MachineBasicBlock::getSuccWeight(__gnu_cxx::__normal_iterator<llvm::MachineBasicBlock* const*, std::vector<llvm::MachineBasicBlock*, std::allocator<llvm::MachineBasicBlock*> > >) const
6.55% clang-3.5 clang-3.5 [.] llvm::MachineBranchProbabilityInfo::getSumForBlock(llvm::MachineBasicBlock const*, unsigned int&) const
5.89% clang-3.5 clang-3.5 [.] (anonymous namespace)::InlineSpiller::traceSiblingValue(unsigned int, llvm::VNInfo*, llvm::VNInfo*)
4.92% clang-3.5 clang-3.5 [.] llvm::LiveRange::find(llvm::SlotIndex)
4.60% clang-3.5 clang-3.5 [.] llvm::LiveRange::extendSegmentEndTo(llvm::LiveRange::Segment*, llvm::SlotIndex)
2.50% clang-3.5 clang-3.5 [.] llvm::MachineBranchProbabilityInfo::getEdgeWeight(llvm::MachineBasicBlock const*, llvm::MachineBasicBlock const*) const