This is an archive of the discontinued LLVM Phabricator instance.

Use a fast path when initializing LineOffsetMapping
ClosedPublic

Authored by serge-sans-paille on Feb 23 2021, 11:53 AM.

Details

Summary

Use the fact that the number of line break is lower than printable characters to
guide the optimization process. Also use a fuzzy test that catches both \n and
\r in a single check to speedup the computation.

Diff Detail

Event Timeline

serge-sans-paille requested review of this revision.Feb 23 2021, 11:53 AM

Interesting optimization! How much speedup does this provide?

Interesting optimization! How much speedup does this provide?

When running perf stat -e instructions ./bin/clang -O0 -fsyntax-only sqlite3.c -o/dev/null -w before / after the patch, I get:

1,929,024,335 instructions before
1,905,625,961 instructions after

That's roughly a 1% speedup ;-)

lattner accepted this revision.Feb 27 2021, 9:28 PM

Nice, it would be worth checking to see if something like this (duplicating the ++I) would be faster or if it codegens the same:

while (I < BufLen) {

// Use a fast check to catch both newlines
if (LLVM_UNLIKELY(Buf[I] > std::max('\n', '\r'))) {
  ++I;
  continue;
}
other stuff

}

This revision is now accepted and ready to land.Feb 27 2021, 9:28 PM

Same generated assembly:

┌─→movzbl 0x0(%r13,%rbp,1),%ecx
│  cmp    $0xd,%cl
│↑ jbe    61
│  add    $0x1,%ebp
├──cmp    %rbp,%rbx
└──ja     110
This revision was landed with ongoing or failed builds.Mar 1 2021, 1:23 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptMar 1 2021, 1:23 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript

Nice, thanks!