llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

llvm::SpillPlacement::addLinks takes all the time with asan or msan and -O2

Open kcc opened this issue 13 years ago • 30 comments

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) 6.11% clang-3.3 clang-3.3 [.] (anonymous namespace)::InlineSpiller::propagateSiblingValue(llvm::DenseMapIterator<llvm::VNInfo*, (anonymous namespace)::InlineSpiller::SibValueInfo, llvm::DenseMapInfollvm::VNInfo*, false>, llvm::VNInfo*) ... ================ -O2 -fsanitize=memory ============= TIME: real: 409.187; user: 405.200; system: 2.050 34.22% clang-3.3 clang-3.3 [.] llvm::SpillPlacement::addLinks(llvm::ArrayRef) 14.12% clang-3.3 clang-3.3 [.] (anonymous namespace)::InlineSpiller::propagateSiblingValue(llvm::DenseMapIterator<llvm::VNInfo*, (anonymous namespace)::InlineSpiller::SibValueInfo, llvm::DenseMapInfollvm::VNInfo*, false>, llvm::VNInfo*) 3.58% clang-3.3 clang-3.3 [.] llvm::TinyPtrVectorllvm::VNInfo*::push_back(llvm::VNInfo*) ...

kcc avatar Sep 30 '13 09:09 kcc

mentioned in issue llvm/llvm-bugzilla-archive#33063

DimitryAndric avatar Nov 26 '21 23:11 DimitryAndric

mentioned in issue llvm/llvm-bugzilla-archive#24618

qcolombet avatar Nov 26 '21 20:11 qcolombet

mentioned in issue llvm/llvm-bugzilla-archive#24618

cmtice avatar Nov 26 '21 20:11 cmtice

mentioned in issue llvm/llvm-bugzilla-archive#22665

llvmbot avatar Nov 26 '21 20:11 llvmbot

mentioned in issue llvm/llvm-bugzilla-archive#22630

rnk avatar Nov 26 '21 20:11 rnk

mentioned in issue llvm/llvm-bugzilla-archive#21349

kcc avatar Nov 26 '21 19:11 kcc

mentioned in issue llvm/llvm-bugzilla-archive#21349

dwblaikie avatar Nov 26 '21 19:11 dwblaikie

mentioned in issue llvm/llvm-bugzilla-archive#19163

llvmbot avatar Nov 26 '21 19:11 llvmbot

*** Bug llvm/llvm-bugzilla-archive#21349 has been marked as a duplicate of this bug. ***

llvmbot avatar Dec 02 '15 20:12 llvmbot

*** Bug llvm/llvm-bugzilla-archive#19163 has been marked as a duplicate of this bug. ***

llvmbot avatar Dec 01 '15 23:12 llvmbot

Another testcase is building gcc. Clang takes several hours when using -fsanitize=undefined. It is embarrassing.

llvmbot avatar Dec 01 '15 13:12 llvmbot

*** Bug llvm/llvm-project#13024 has been marked as a duplicate of this bug. ***

kcc avatar Dec 01 '15 00:12 kcc

*** Bug llvm/llvm-bugzilla-archive#24618 has been marked as a duplicate of this bug. ***

qcolombet avatar Oct 01 '15 22:10 qcolombet

llvm/llvm-bugzilla-archive#24618 seems to be related to this bug.

cmtice avatar Sep 03 '15 19:09 cmtice

*** Bug llvm/llvm-bugzilla-archive#22665 has been marked as a duplicate of this bug. ***

llvmbot avatar Feb 23 '15 22:02 llvmbot

repro

kcc avatar Jan 28 '15 22:01 kcc

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

kcc avatar Jan 28 '15 22:01 kcc

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

kcc avatar May 26 '14 13:05 kcc

We've applied a series of changes to asan/msan to reduce the effect of this problem:

  1. added -mllvm -asan-instrumentation-with-call-threshold=N (default=10000) to use function calls instead of inline checks
  2. similar flag coming soon in msan: -mllvm -asan-instrumentation-with-call-threshold=N
  3. -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)

kcc avatar Apr 21 '14 16:04 kcc

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

eugenis avatar Feb 21 '14 13:02 eugenis