This is an archive of the discontinued LLVM Phabricator instance.

[analyzer] Improve simplifySVal performance.
ClosedPublic

Authored by NoQ on May 21 2018, 12:25 PM.

Details

Summary

Reported by Mikael Holmén on http://lists.llvm.org/pipermail/cfe-commits/Week-of-Mon-20180416/225349.html - a combination of rC329780 and rC300178 caused a performance regression that seemed to be a hang on the attached test case.

Reducing even further from 20 to 10 gives a ~15% further speed boost on the test, but i don't think it's worth it because such code is not common and therefore accuracy is more important.

Diff Detail

Repository
rL LLVM

Event Timeline

NoQ created this revision.May 21 2018, 12:25 PM
NoQ added a subscriber: mikhail.ramalho.

@mikhail.ramalho Does it solve your problems with ffmpeg as well? :)

@NoQ I'm really wary of magic numbers.

  • We should expose it through an analyzer-config flag. We already do so for the budget.
  • We should probably have both positive and negative tests. What scenarios _stop_ working after the threshold is decreased? [point 1 is required to be able to test that]
  • Finally, do we understand where the slowdown comes from? If it comes from attempted rearrangements due to https://reviews.llvm.org/rC329780 I think we should roll that back instead.
george.karpenkov requested changes to this revision.May 21 2018, 3:22 PM
This revision now requires changes to proceed.May 21 2018, 3:22 PM

Also we should make sure that all recursive transformations on expressions represented as DAGs should be memoized.

Hello! Thank you for addressing this problem. Are these kinds of symbols common in real code? For me it seems very artificial. However, I agree with George, it would be better to have this value as an analyzer option with a default value (of 20).

NoQ updated this revision to Diff 148681.May 25 2018, 3:53 PM

Optimize simplifySVal() instead of reducing the threshold.

I'll address the memoization separately.

NoQ added a comment.May 25 2018, 3:56 PM

I only essentially did one optimization - introduce a short path that returns the original value if visiting its sub-values changed nothing, which is a relatively common case. The reason it works though is that evalBinOp() will be called later to combine the sub-values, which may in turn call simplifySVal() again, which is clearly unwanted.

test/Analysis/hangs.c
18–30 ↗(On Diff #148681)

This currently finishes in 1 second on my machine. This test, unlike the original test, is easy to experiment with.

NoQ updated this revision to Diff 148684.May 25 2018, 4:11 PM

Add an explicit brute-force protection against re-entering simplifySVal(). Remove the threshold completely.

NoQ retitled this revision from [analyzer] Reduce simplifySVal complexity threshold further. to [analyzer] Improve simplifySVal performance..May 25 2018, 4:12 PM
george.karpenkov accepted this revision.May 28 2018, 5:01 PM
This revision is now accepted and ready to land.May 28 2018, 5:01 PM
This revision was automatically updated to reflect the committed changes.