This is an archive of the discontinued LLVM Phabricator instance.

[MachineInstr] Increase the size of a SmallVector
ClosedPublic

Authored by foad on Nov 15 2019, 3:28 AM.

Details

Summary

The SmallVector reserve() call in
MachineInstrExpressionTrait::getHashValue accounted for over 3% of all
calls to malloc() when I compiled a bunch of graphics shaders for the
AMDGPU target. Its initial size was only enough for machine instructions
with up to 7 operands, but for AMDGPU 8 and 10 operands are very common.
Here's a histogram of number of operands for each call to getHashValue,
gathered from the same collection of shaders:

1 13503
2 254273
3 135781
4 422508
5 614997
6 194953
7 287248
8 1517255
9 31218
10 1191269
11 70731
12 24
13 77
15 84
17 4692
27 16
33 705
49 6

Typical instructions with 8 and 10 operands are floating point
arithmetic and multiply-accumulate instructions like:

%83:vgpr_32 = V_MUL_F32_e64 0, killed %82:vgpr_32, 0, killed %81:vgpr_32, 0, 0, implicit $exec
%330:vgpr_32 = V_MAC_F32_e64 0, killed %327:vgpr_32, 0, killed %329:sgpr_32, 0, %328:vgpr_32(tied-def 0), 0, 0, implicit $exec

Diff Detail

Event Timeline

foad created this revision.Nov 15 2019, 3:28 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 15 2019, 3:28 AM
foad added a reviewer: arsenm.Nov 15 2019, 3:30 AM
arsenm accepted this revision.Nov 15 2019, 3:33 AM

LGTM. I have thought for a long time we should probably compress the various immediate operands into one to avoid these kind of issues. There are a lot of loops over all of the operands

This revision is now accepted and ready to land.Nov 15 2019, 3:33 AM
This revision was automatically updated to reflect the committed changes.