This is an archive of the discontinued LLVM Phabricator instance.

NFC: Improve pattern matching in computeKnownBitsFromAssume.
ClosedPublic

Authored by sdesmalen on Apr 10 2019, 4:46 AM.

Details

Summary

This patch changes the order of pattern matching by first testing
a compare instruction's predicate, before doing the pattern
match for the whole expression tree. This has a positive impact
on compilation cost.

Patch by Paul Walker.

Diff Detail

Event Timeline

sdesmalen created this revision.Apr 10 2019, 4:46 AM

Seems like a good micro-optimization while actually improving readability slightly. Do you have any performance numbers for this change? It would be good to note those here and in the commit message.

lib/Analysis/ValueTracking.cpp
619–620

IMO, it would make things a bit clearer to name this "Cmp" instead of recycling "Arg" as the name. Then use that name throughout the later code.

631

Here and later, please remove the duplicated check of the predicate value.

sdesmalen marked 2 inline comments as done.Apr 10 2019, 8:35 AM

We found a case where repeated calls into computeKnownBits(FromAssume) skyrocketed our build-times after we added a call to llvm.assume after vectorized loops to describe the range of a newly introduced induction variable, causing some builds to time-out.
Because the 'less then' or 'less then equal' case was way down this list in this function, it had to go through all the matching calls. Unfortunately I don't have any real numbers to back this up, because we did this work a while ago.

lib/Analysis/ValueTracking.cpp
619–620

Yes, I agree that is clearer.

631

Good catch!

sdesmalen updated this revision to Diff 194526.Apr 10 2019, 8:36 AM
  • Removed redundant checks for predicate value.
  • Renamed ArgV to Cmp
spatel accepted this revision.Apr 10 2019, 8:55 AM

LGTM

  1. Re-run clang-format or manually check indentation; I marked a couple of lines that don't look right.
  2. Since this code is still a potential perf problem, consider converting the chain of if-else to a switch on the compare predicate as a follow-up. [insert joke about using a good optimizing compiler... :) ]
  3. This patch should not be titled with 'NFC' because it has external motivation/intent. "Improve compile-time performance in computeKnownBitsFromAssume" ?
lib/Analysis/ValueTracking.cpp
846

indentation looks wrong here

864

indentation looks wrong here

This revision is now accepted and ready to land.Apr 10 2019, 8:55 AM
sdesmalen marked 2 inline comments as done.Apr 10 2019, 9:23 AM

Thanks @spatel. I'll also create a follow-up patch to use a switch statement as you suggested!

This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptApr 10 2019, 9:23 AM