[llvm] 1eab92b - [CodeGen] Implement MVT::getSizeInBits with a lookup table (#65604)

via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 7 09:55:26 PDT 2023


Author: Jay Foad
Date: 2023-09-07T17:55:21+01:00
New Revision: 1eab92bda16d7fa29ab441615d8fb8c9a8555a11

URL: https://github.com/llvm/llvm-project/commit/1eab92bda16d7fa29ab441615d8fb8c9a8555a11
DIFF: https://github.com/llvm/llvm-project/commit/1eab92bda16d7fa29ab441615d8fb8c9a8555a11.diff

LOG: [CodeGen] Implement MVT::getSizeInBits with a lookup table (#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/

Added: 
    

Modified: 
    llvm/include/llvm/CodeGen/MachineValueType.h

Removed: 
    


################################################################################
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