This is an archive of the discontinued LLVM Phabricator instance.

[ValueTracking][InstSimplify] improve efficiency for detecting non-zero value
ClosedPublic

Authored by spatel on Apr 13 2021, 12:49 PM.

Details

Summary

I was stepping through some of the callstacks in the example from D99759 and noticed a potential compile-time improvement.
This is really 2 patches, but I've put them together to make it easier to see if it does anything to help real-world compile-time:

  1. Improve the logic in isNonZeroRecurrence() to handle the case of a negative-stepping phi+add pair.
  2. Limit a call from instsimplify to isKnownNonEqual() to avoid a pile of redundant analysis.

The first step is needed to avoid a regression - the test example shown here is caught by isKnownNonEqual() but missed by isNonZeroRecurrence() without this patch.

This makes a degenerate test based on PR49785 about 40x faster (25 sec -> 0.6 sec), but it does not address the larger question of how to limit computeKnownBitsFromAssume(). Ie, the original test there is still infinite-time for all practical purposes.

Diff Detail

Event Timeline

spatel created this revision.Apr 13 2021, 12:49 PM
spatel requested review of this revision.Apr 13 2021, 12:49 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 13 2021, 12:49 PM
nikic accepted this revision.Apr 13 2021, 1:01 PM

LG, but please apply the two changes separately.

llvm/lib/Analysis/ValueTracking.cpp
2232 ↗(On Diff #337227)

I'd directly return !StartC->isNullValue() && !StepC->isNullValue(); here and below.

As a side note, the requirement that StepC is non-zero is unnecessary here -- which also means that we don't need it to be a constant. But that's independent of your patch.

This revision is now accepted and ready to land.Apr 13 2021, 1:01 PM
spatel marked an inline comment as done.Apr 14 2021, 5:48 AM
spatel added inline comments.
llvm/lib/Analysis/ValueTracking.cpp
2232 ↗(On Diff #337227)

Good point - this patch should be clearer if we hoist the StartC null check:
49193653974a

I'll add a TODO about the StepC requirement.

This revision was landed with ongoing or failed builds.Apr 14 2021, 6:12 AM
This revision was automatically updated to reflect the committed changes.
spatel marked an inline comment as done.