Skip to content

Commit 1eab92b

Browse files
authored
[CodeGen] Implement MVT::getSizeInBits with a lookup table (llvm#65604)
This allows it to be inlined in Release builds giving a geomean 0.10% speed up according to https://llvm-compile-time-tracker.com/
1 parent d6cc341 commit 1eab92b

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

llvm/include/llvm/CodeGen/MachineValueType.h

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -302,18 +302,16 @@ namespace llvm {
302302
/// be set and the runtime size will be a positive integer multiple of the
303303
/// base size.
304304
TypeSize getSizeInBits() const {
305-
switch (SimpleTy) {
306-
default:
307-
switch (SimpleTy) {
308-
default:
309-
llvm_unreachable("getSizeInBits called on extended MVT.");
310-
305+
static constexpr TypeSize SizeTable[] = {
311306
#define GET_VT_ATTR(Ty, N, Sz, Any, Int, FP, Vec, Sc) \
312-
case Ty: \
313-
return (Sc ? TypeSize::Scalable(Sz) : TypeSize::Fixed(Sz));
307+
TypeSize(Sz, Sc || Ty == aarch64svcount /* FIXME: Not in the td. */),
314308
#include "llvm/CodeGen/GenVT.inc"
315309
#undef GET_VT_ATTR
316-
}
310+
};
311+
312+
switch (SimpleTy) {
313+
case INVALID_SIMPLE_VALUE_TYPE:
314+
llvm_unreachable("getSizeInBits called on extended MVT.");
317315
case Other:
318316
llvm_unreachable("Value type is non-standard value, Other.");
319317
case iPTR:
@@ -329,8 +327,9 @@ namespace llvm {
329327
"in codegen and has no size");
330328
case Metadata:
331329
llvm_unreachable("Value type is metadata.");
332-
case aarch64svcount: // FIXME: Not in the td.
333-
return TypeSize::Scalable(16);
330+
default:
331+
assert(SimpleTy < VALUETYPE_SIZE && "Unexpected value type!");
332+
return SizeTable[SimpleTy - FIRST_VALUETYPE];
334333
}
335334
}
336335

0 commit comments

Comments
 (0)