This is an archive of the discontinued LLVM Phabricator instance.

[TableGen] TypeSetByHwMode::operator== optimization
ClosedPublic

Authored by RKSimon on Aug 16 2018, 7:10 AM.

Details

Summary

This operator is called a great deal, by checking for the cheap isSimple equality cases first (a common occurrence) we can improve performance as we avoid a lot of std::map find/iteration in hasDefault.

isSimple also means that a default value is present, so we can avoid some hasDefault calls.

This also avoids a rather dodgy piece of logic that was checking for isSimple() && !VTS.isSimple() but not the inverse - it now uses the general hasDefault mode comparison test instead.

Saves around 15secs in debug builds of x86 -gen-dag-isel.

Diff Detail

Repository
rL LLVM

Event Timeline

RKSimon created this revision.Aug 16 2018, 7:10 AM

A bit of a background for clarity: <Something>ByHwMode represents <Something> parameterized by hardware mode. It's a map that to each hw mode assigns the corresponding value of <Something>. If a value for mode m is missing from the map, the default is used (this is a form of compression).

TypeSetByHwMode are sets of MVTs corresponding to hw modes. They are used in definitions of RegisterClasses, so that a given class can have value types i32 and v2i16 in 32-bit mode, and i64, v2i32, and v4i16 in 64-bit mode.

Here, the attempt here was to compare the two parameterized type sets taking into account that if the set for a particular mode is missing, the default will be assumed. Specifically,

default -> { i32 }

should compare identical to

default -> { i32 }
mode0 -> { i32 }

and similarly

default -> { i32 }
mode0 -> { i32 }

should compare identical to

default -> { i32 }
mode0 -> { i32 }
mode1 -> { i32 }

On targets that don't use this feature, all TypeSetByHwModes are in the form of a map with a single entry: default -> { ... }, which is what isSimple checks for. The case where both parameterized sets are simple is the case for X86 and most other targets, so I agree that it should be made fast. If any of them isn't simple, it means that we are dealing with parameterized sets and they should be handled more carefully. The return false at line 208 in the original code was erroneous, since it did not perform the expanded checks in that specific case.

kparzysz accepted this revision.Aug 16 2018, 7:49 AM

Looks good to me.

This revision is now accepted and ready to land.Aug 16 2018, 7:49 AM
This revision was automatically updated to reflect the committed changes.