This is an archive of the discontinued LLVM Phabricator instance.

Fix accidentally quadratic time in BlockFrequencyInfoImpl::propagateMassToSuccessors
AbandonedPublic

Authored by AndrewScheidecker on Dec 6 2017, 4:55 AM.

Details

Reviewers
dexonsmith
Summary

Pass the successor-iterator to getEdgeProbability so that it doesn't need to do a linear search of the successor list to calculate the index. This reduces an operation that was O(n^2) time to O(n) time, where n is the number of successors to the basic block.

In my WebAssembly VM that uses LLVM to generate machine code, I was running into this on a test case with a large switch from the WebAssembly reference interpreter test suite: https://github.com/WebAssembly/spec/blob/master/test/core/br_table.wast#L110

To find the bottleneck, I increased the number of cases in the switch statement further, which caused it to spend ~13 seconds in LLVM code generation. This optimization reduced the code generation time to tens of milliseconds.

Diff Detail

Repository
rL LLVM

Event Timeline

AndrewScheidecker abandoned this revision.Dec 6 2017, 5:01 AM

Abandoning so I can resubmit with llvm-commits as a subscriber