[llvm] [CodeGen] Implement MVT::getSizeInBits with a lookup table (PR #65604)
Jay Foad via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 7 06:03:22 PDT 2023
https://github.com/jayfoad created https://github.com/llvm/llvm-project/pull/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/
>From 3148b78b61c25e03e3882fd7f1155312db7cc529 Mon Sep 17 00:00:00 2001
From: Jay Foad <jay.foad at amd.com>
Date: Thu, 7 Sep 2023 13:08:09 +0100
Subject: [PATCH] [CodeGen] Implement MVT::getSizeInBits with a lookup table
This allows it to be inlined in Release builds giving a geomean 0.10%
speed up according to https://llvm-compile-time-tracker.com/
---
llvm/include/llvm/CodeGen/MachineValueType.h | 21 ++++++++++----------
1 file changed, 10 insertions(+), 11 deletions(-)
diff --git a/llvm/include/llvm/CodeGen/MachineValueType.h b/llvm/include/llvm/CodeGen/MachineValueType.h
index d7dc38c7bd9885a..f0d380fa9cda20f 100644
--- a/llvm/include/llvm/CodeGen/MachineValueType.h
+++ b/llvm/include/llvm/CodeGen/MachineValueType.h
@@ -302,18 +302,16 @@ namespace llvm {
/// be set and the runtime size will be a positive integer multiple of the
/// base size.
TypeSize getSizeInBits() const {
- switch (SimpleTy) {
- default:
- switch (SimpleTy) {
- default:
- llvm_unreachable("getSizeInBits called on extended MVT.");
-
+ static constexpr TypeSize SizeTable[] = {
#define GET_VT_ATTR(Ty, N, Sz, Any, Int, FP, Vec, Sc) \
- case Ty: \
- return (Sc ? TypeSize::Scalable(Sz) : TypeSize::Fixed(Sz));
+ TypeSize(Sz, Sc || Ty == aarch64svcount /* FIXME: Not in the td. */),
#include "llvm/CodeGen/GenVT.inc"
#undef GET_VT_ATTR
- }
+ };
+
+ switch (SimpleTy) {
+ case INVALID_SIMPLE_VALUE_TYPE:
+ llvm_unreachable("getSizeInBits called on extended MVT.");
case Other:
llvm_unreachable("Value type is non-standard value, Other.");
case iPTR:
@@ -329,8 +327,9 @@ namespace llvm {
"in codegen and has no size");
case Metadata:
llvm_unreachable("Value type is metadata.");
- case aarch64svcount: // FIXME: Not in the td.
- return TypeSize::Scalable(16);
+ default:
+ assert(SimpleTy < VALUETYPE_SIZE && "Unexpected value type!");
+ return SizeTable[SimpleTy - FIRST_VALUETYPE];
}
}
More information about the llvm-commits
mailing list