This is an archive of the discontinued LLVM Phabricator instance.

[MachineVerifier] Doing ::calcRegsPassed over faster sets: ~15-20% faster MV
ClosedPublic

Authored by rtereshin on Feb 24 2020, 12:43 AM.

Details

Summary

MachineVerifier still takes 45-50% of total compile time with
-verify-machineinstrs, with calcRegsPassed dataflow taking ~50-60% of
MachineVerifier.

The majority of that time is spent in BBInfo::addPassed, mostly within
DenseSet implementing the sets the dataflow is operating over.

In particular, 1/4 of that DenseSet time is spent just iterating over it
(operator++), 40-50% on insertions, and most of the rest in ::count.

Given that, we're implementing custom sets just for this analysis here,
focusing on cheap insertions and O(n) iteration time (as opposed to
O(U), where U is the universe).

As it's based _mostly_ on BitVector for sparse and SmallVector for
dense, it may remotely resemble SparseSet. The difference is, our
solution is a lot less clever, doesn't have constant time clear that
we won't use anyway as reusing these sets across analyses is cumbersome,
and thus more space efficient and safer (got a resizable Universe and a
fallback to DenseSet for sparse if it gets too big).

With this patch MachineVerifier gets ~15-20% faster, its contribution to
total compile time drops from 45-50% to ~35%, while contribution of
calcRegsPassed to MachineVerifier drops from 50-60% to ~35% as well.

calcRegsPassed itself gets another 2x faster here.

All measured on a large suite of shaders targeting a number of GPUs.

Diff Detail

Event Timeline

rtereshin created this revision.Feb 24 2020, 12:43 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 24 2020, 12:43 AM
rudkx added inline comments.Feb 24 2020, 3:13 PM
llvm/lib/CodeGen/MachineVerifier.cpp
2190

FILTERb seems like a typo.

2195

FILTERb again.

rtereshin marked an inline comment as done.Feb 24 2020, 3:16 PM
rtereshin added inline comments.
llvm/lib/CodeGen/MachineVerifier.cpp
2190

Not a typo, intended is OUT_b, as a subscript, for "block". FILTER is unique per BB.

rudkx added inline comments.Feb 24 2020, 3:17 PM
llvm/lib/CodeGen/MachineVerifier.cpp
2131

You could reduce indentation here by adding braces around the body of the for loop, inverting the condition, and using continue, per https://www.llvm.org/docs/CodingStandards.html#use-early-exits-and-continue-to-simplify-code.

rtereshin marked 2 inline comments as done.Feb 24 2020, 3:31 PM
rtereshin added inline comments.
llvm/lib/CodeGen/MachineVerifier.cpp
2131

I could indeed! The body has started as one-liner, then grew, and I haven't changed this.

I'll update it that way in one go with the rest of the nitpicks when those are all available together, and if the patch clears overall. Thanks!

2190

Does that clears the issue, or you'd rather prefer those subscripts dropped (I suppose everywhere then, not just on FILTERb)?

I don't have a preference, fine either way.

rudkx accepted this revision.Feb 24 2020, 3:43 PM

LGTM.

llvm/lib/CodeGen/MachineVerifier.cpp
2131

SGTM!

2190

I hadn't noticed the comment before the class which is why it stuck out. I guess I'm not opposed to any particular convention as long as we're consistent here but the all-caps name with lower-case suffix did stick out.

This revision is now accepted and ready to land.Feb 24 2020, 3:43 PM
rtereshin marked an inline comment as done.Feb 24 2020, 3:55 PM
rtereshin added inline comments.
llvm/lib/CodeGen/MachineVerifier.cpp
2190

Yeah, I'm not very accustomed to trying to reproduce mathy notations in ASCII, I guess :)

Literally from wikipedia, for example:

Any particular style exists in LLVM's codebase for this kind of stuff?

rtereshin marked an inline comment as done.Feb 24 2020, 4:06 PM
rtereshin added inline comments.
llvm/lib/CodeGen/MachineVerifier.cpp
2190

I talked to @qcolombet briefly about this, he says he's not aware about any particular style being preferred, and we converged on a little bit more LATeX'y take on this with everything lower case and underscores for subscripts: out_b = in_b \ filter_b. I'll go with that.

rtereshin updated this revision to Diff 246354.Feb 24 2020, 6:32 PM
rtereshin marked 5 inline comments as done.

Addressing the feedback (tidying up the comments a bit as discussed, going for if(! continue; instead of if() {})

This revision was automatically updated to reflect the committed changes.