I noticed it was showing up as hot in some profiles. Making it a lookup table makes it basically disappear. I'm attaching a patch for how I did it.
It may make sense to move the table construction out of line (I don't know if we are ever getting any benefit from calling this on a known-constant value), but the lookup should probably stay inline since it is just 2-3 instructions (possibly compute the address of the table using rip-relative addressing, sign extend the type, do the lookup). Canonicalizing 2 types (as is usually done) takes only 5 instructions because the actual table address only needs to be computed once.