This is an archive of the discontinued LLVM Phabricator instance.

[SelectionDAG][NFCI] Use common logic for identifying MMI vars
ClosedPublic

Authored by fdeazeve on May 2 2023, 12:51 PM.

Details

Summary

After function argument lowering, but prior to instruction selection,
dbg declares pointing to function arguments are lowered using special
logic.

Later, during instruction selection (both "fast" and regular ISel), this
logic is "repeated" in order to identify which intrinsics have already
been lowered. This is bad for two reasons:

  1. The logic is not _really_ repeated, the code is different, which

could lead to duplicate lowering of the intrinsic.

  1. Even if the logic were repeated properly, this is still code

duplication.

This patch addresses these issues by storing all preprocessed
dbg.declare intrinsics in a set inside FuncInfo; the set is queried upon
instruction selection.

Diff Detail

Event Timeline

fdeazeve created this revision.May 2 2023, 12:51 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 2 2023, 12:51 PM
fdeazeve requested review of this revision.May 2 2023, 12:51 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 2 2023, 12:51 PM
fdeazeve updated this revision to Diff 518838.May 2 2023, 12:55 PM

Update some code comments

fdeazeve added inline comments.May 2 2023, 12:58 PM
llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
6174

In case you're curious, all of this code is duplicated in the next file (SelectionDAGISel.cpp). You can see it in this review.

Note how the FastIsel branch had a very different logic (see the previous file in this review), even though it also calls this deleted code.

aprantl accepted this revision.May 2 2023, 3:33 PM

This looks like a nice simplification!

llvm/include/llvm/CodeGen/FunctionLoweringInfo.h
192

///

193

4 seems like a low number. You could hack up a version of clang to dump the number of elements at the end and then pick something close to the median. Or you could pick 8 :-)

This revision is now accepted and ready to land.May 2 2023, 3:33 PM
Orlando added a subscriber: Orlando.May 3 2023, 1:42 AM

Nice, that's much better!

(This is just a passing thumbs up, FWIW it LGTM too)

fdeazeve added inline comments.May 3 2023, 5:19 AM
llvm/include/llvm/CodeGen/FunctionLoweringInfo.h
193

(Side note, I found out about the st --summary CLI tool, which is very useful)

Hah! This actually revealed a problem with the patch :)

Because this class doesn't rely on RAII (we keep reusing it for all functions in the Module), it has a "clear" method that needs to be manually updated. When I tried compiling a big-ish cpp file, the size of the set kept growing and growing. I've now fixed this.

I compiled APInt.cpp with this change printing the set size after each function is lowered:

min     q1      median  q3      max
0       0       0       0       17       # O2
0       1       2       4       29       # O0

When compiling SelectionDAGISel.cpp, we also get similar ideas:

min     q1      median  q3      max
0       0       0       0       15       # O2
0       1       1       2       258      # O0

Since one of the Q3 == 4, and eyeballing the numbers there was a decent chunk of values in the [5;8] range, I'll just go ahead and use 8 to make the vast majority of cases fall in the "Small" case.

fdeazeve updated this revision to Diff 519035.May 3 2023, 5:19 AM

Addressed review comments.

This revision was landed with ongoing or failed builds.May 3 2023, 7:59 AM
This revision was automatically updated to reflect the committed changes.