This is an archive of the discontinued LLVM Phabricator instance.

SmallPtrSet: Avoid initializing Array in the small case.
ClosedPublic

Authored by MatzeB on Jan 27 2016, 10:08 PM.

Details

Summary

This patch avoids the initial memset at the cost of making iterators
slightly more complex. This should be beneficial as most SmallPtrSets
hold no or only a few elements, while iterating over them is less
common.

It's not a measurable change in compiletime but valgrind/callgrind shows saving of ~0.25% instructions in my tests.

Diff Detail

Repository
rL LLVM

Event Timeline

MatzeB updated this revision to Diff 46222.Jan 27 2016, 10:08 PM
MatzeB retitled this revision from to SmallPtrSet: Avoid initializing Array in the small case..
MatzeB updated this object.
MatzeB set the repository for this revision to rL LLVM.
MatzeB added a subscriber: llvm-commits.
chandlerc added inline comments.Jan 27 2016, 10:22 PM
include/llvm/ADT/SmallPtrSet.h
206–208 ↗(On Diff #46222)

If we're going to iterate specially in the small case, why not completely specialize the iteration? Notably, can't you skip the tombstone test in the loop when small?

214–215 ↗(On Diff #46222)

Why not adjust the end iterator in the small case?

MatzeB updated this revision to Diff 46335.Jan 28 2016, 7:41 PM

Thanks for the review and IRC discussion yesterday.
This version starts putting tombstones into the small set, which allows a simpler iterator design because erase() does not change the end() iterator anymore.

bkramer accepted this revision.Feb 12 2016, 7:14 AM
bkramer edited edge metadata.

Change looks good to me. This could use some git-clang-format though.

This revision is now accepted and ready to land.Feb 12 2016, 7:14 AM
This revision was automatically updated to reflect the committed changes.