[Scheduler] Recent improvements lead to compile time bloat
| Bugzilla Link | 26940 |
| Resolution | FIXED |
| Resolved on | Apr 01, 2016 09:25 |
| Version | trunk |
| OS | All |
| CC | @atrick,@bcardosolopes,@chandlerc,@hfinkel,@MatzeB,@JonPsson,@Weverything |
Extended Description
Commit r259673 (“[ScheduleDAGInstrs::buildSchedGraph()] Handling of memory dependecies rewritten”) introduced a huge slowdown in an internal benchmark:
=== Before r259673
$ clang -arch arm64 -Os -c t.mi real 1389.12s user 1314.71s => 22min sys 14.92s
$ clang -arch x86_64 -Os -c t.mi real 76.90s user 75.46s => 1min15s sys 0.92s
=== After r259673
real 10045.62s user 9131.03s => 3h20min sys 95.60s
real 2217.71s user 2174.12s => 36min23s sys 33.07s
ARM64 is a lot worse than x86, but compile time for both are pretty bad! Note that before r259673 arm64 time was already bad (22min) but got even worse after. Gonna try to reduce the testcase / provide a testcase with the same reproducible slowdown factor.
Well, I am not sure if that is a "random knob", considering that the scheduler must have a cut-off mechanism somewhere since there is no theoretical limit to the sizes of regions.
But I think you have a point in that this value should be found after the data structures have been reworked, per your suggestions. Hopefully, the 1000 limit could be good enough then :-)
Err, if we can solve this problem without tweaking random knobs in the compiler that nobody will ever quite tune (IE by fixing data structures), we should do that, rather than finding good values for those knobs. :)
Nobody checked setting -dag-maps-huge-region to 100 / 200 as initial value? Per my previous compile times, the test case that went from 2.5 min to 7.7 sec was further reduced to 3.4 sec with a value of 200...
Created attachment 16098 [details] Bugfix in buildSchedGraph() to make -dag-maps-huge-region work properly
I found that the reduction of the maps did in fact never happen in this test case. This was because all the stores / loads were made with addresses from arguments and they thus became "unknown" stores / loads. Fixed by removing continue statements and making sure that the test for reduction always takes place.
Before this fix compile time was 2m28s, which then became 7.7s. For smaller values of -dag-maps-huge-region (default is 1000): 200 3.4s 100 3.2s 50 3.1s 10 3.05s
I would like to propose also to set the default value to 100, or so.
Furthermore, it seems that the SUnit::Preds / Succs should be a set instead of a vector, to enable faster check for overlap and removal. Has anyone tried this?
I was just about to point these out. These should be sets or small dense maps.
->overlaps is just checking a few fields, and latency is being used for sort ordering.
This would be trivial to make into an ordered set or unordered_multimap.
Fixed in r265063.
For the results on our internal testcase, we got it down to ~5min, which is much better than what we had before your patch, thanks Jonas.
We've hit this hard, I've mailed your patch out in http://reviews.llvm.org/D18673 Jonas, thanks for that!
Thanks!
Andy, please review this small patch, and also let me know about the default value for the reduction threshold.
/Jonas
Jonas,
I tested your patch. For the examples I've come across, this patch has brought back the pre-r259673 compile times.
Richard
Bugfix in buildSchedGraph() to make -dag-maps-huge-region work properly I found that the reduction of the maps did in fact never happen in this test case. This was because all the stores / loads were made with addresses from arguments and they thus became "unknown" stores / loads. Fixed by removing continue statements and making sure that the test for reduction always takes place.
Before this fix compile time was 2m28s, which then became 7.7s. For smaller values of -dag-maps-huge-region (default is 1000): 200 3.4s 100 3.2s 50 3.1s 10 3.05s
I would like to propose also to set the default value to 100, or so.
Furthermore, it seems that the SUnit::Preds / Succs should be a set instead of a vector, to enable faster check for overlap and removal. Has anyone tried this?
Please try the patch and let me know what you think,
Jonas
That's awesome, thanks for the reduced testcase!
I have also ran into this issue and managed to get a reduced example (also attached).
array.cc: void ProcessArr1(const float *in, float *out) { out[0] = in[1] + in[2] + in[3]; ... repeat line 2000 times ... }
int main(int argc, char *argv[]) { float arr[10]; float out[10]; ProcessArr1(arr, out); return 0; }
clang array.cc -O2
Prior to r259673, this would compile in ~2 seconds. After, it would take ~40 seconds. I did not see any effect from modifying the -dag-maps-huge-region value.
Take a look at the inverted call tree:
Running Time Self (ms) Symbol Name 1935910.0ms 100.0% 1935910.0 llvm::SUnit::addPred(llvm::SDep const&, bool) 1935601.0ms 99.9% 0.0 llvm::ScheduleDAGInstrs::addChainDependency(llvm::SUnit*, llvm::SUnit*, unsigned int) 1935601.0ms 99.9% 0.0 llvm::ScheduleDAGInstrs::buildSchedGraph(llvm::AAResults*, llvm::RegPressureTracker*, llvm::PressureDiffs*, llvm::LiveIntervals*, bool) 1935601.0ms 99.9% 0.0 llvm::ScheduleDAGMILive::buildDAGWithRegPressure() 1935601.0ms 99.9% 0.0 llvm::ScheduleDAGMILive::schedule() 1935601.0ms 99.9% 0.0 (anonymous namespace)::MachineSchedulerBase::scheduleRegions(llvm::ScheduleDAGInstrs&, bool) 1935601.0ms 99.9% 0.0 (anonymous namespace)::MachineScheduler::runOnMachineFunction(llvm::MachineFunction&) 1935601.0ms 99.9% 0.0 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) 1935601.0ms 99.9% 0.0 llvm::FPPassManager::runOnFunction(llvm::Function&) 1935601.0ms 99.9% 0.0 llvm::FPPassManager::runOnModule(llvm::Module&) 1935601.0ms 99.9% 0.0 llvm::legacy::PassManagerImpl::run(llvm::Module&) 1935601.0ms 99.9% 0.0 main
One can spot a quadratic behaviour in addPred when there's an overlap:
bool SUnit::addPred(const SDep &D, bool Required) {
// If this node already has this dependence, don't add a redundant one.
for (SmallVectorImpl
Giving the -dag-maps-huge-region flag a try, did use -dag-maps-huge-region=10 but it didn't help much mitigating the issue, it only decreases compile time by 2min:
real 160m20.168s user 150m1.280s sys 1m30.513s
assigned to @JonPsson