This is an archive of the discontinued LLVM Phabricator instance.

Optimize OptTable::findNearest implementation and usage
ClosedPublic

Authored by serge-sans-paille on Jan 18 2023, 8:14 AM.

Details

Summary

When used to find an exact match, some extra context can be used to
totally cut some computations.

This saves 1% of the instruction count when pre processing sqlite3.c
through

valgrind --tool=callgrind ./bin/clang -E sqlite3.c -o/dev/null

Diff Detail

Event Timeline

Herald added a project: Restricted Project. · View Herald TranscriptJan 18 2023, 8:14 AM
serge-sans-paille requested review of this revision.Jan 18 2023, 8:14 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptJan 18 2023, 8:14 AM
nikic added inline comments.Jan 18 2023, 8:22 AM
clang/lib/Driver/Driver.cpp
2475

I think this changes MinimumLength from the default of 4 to 0?

llvm/include/llvm/Option/OptTable.h
179

Shouldn't this be MaximumDistance?

llvm/lib/Option/OptTable.cpp
285

Should probably be ssize_t rather than signed?

Thanks @nikic for the review. Remarks taken into account.

nikic accepted this revision.Jan 19 2023, 1:57 AM

LGTM

This revision is now accepted and ready to land.Jan 19 2023, 1:57 AM
This revision was landed with ongoing or failed builds.Jan 19 2023, 5:16 AM
This revision was automatically updated to reflect the committed changes.
nikic added a comment.Jan 20 2023, 1:20 PM

FYI I just noticed some i686 failures that look something like this:

/builddir/build/BUILD/llvm-16.0.0.src/redhat-linux-build/unittests/Option/./OptionTests --gtest_filter=OptTableTest/0.FindNearest
--
/builddir/build/BUILD/llvm-16.0.0.src/unittests/Option/OptionParsingTest.cpp:314: Failure
Expected equality of these values:
  1U
    Which is: 1
  T.findNearest("-blorb", Nearest)
    Which is: 4294967295
/builddir/build/BUILD/llvm-16.0.0.src/unittests/Option/OptionParsingTest.cpp:315: Failure
Expected equality of these values:
  Nearest
    Which is: ""
  "-blorp"

Plausibly caused by this change -- I'm thinking that MaximumDistance is initialized to UINT_MAX - 1, but then we cast that to a signed integer and compare that, so it wraps to a large negative number.

Plausibly caused by this change -- I'm thinking that MaximumDistance is initialized to UINT_MAX - 1, but then we cast that to a signed integer and compare that, so it wraps to a large negative number.

@nikic : I thought I fixed that with e8a163dc03e6913360beb305620104ba129c081c ... is it included in your build?