[llvm] [Instrumentor] Add subtype IDs to complement type IDs for vectors/arrays (PR #205466)

Johannes Doerfert via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 23 18:46:55 PDT 2026


https://github.com/jdoerfert created https://github.com/llvm/llvm-project/pull/205466

If the type of an argument passed to the instrumentation is a vector or array, we still want to filter on the underlying type, and the instrumentation might also need to know. Thus, we can now pass a subtype ID, which is -1 except if it's a vector or array, then it's the element type ID. Structs need to be handled differently.

>From 822c2682b0266721e550abc2205fc669e2e3722d Mon Sep 17 00:00:00 2001
From: Johannes Doerfert <jdoerfert.llvm at gmail.com>
Date: Tue, 23 Jun 2026 16:36:41 -0700
Subject: [PATCH] [Instrumentor] Add subtype IDs to complement type IDs for
 vectors/arrays

If the type of an argument passed to the instrumentation is a vector or
array, we still want to filter on the underlying type, and the
instrumentation might also need to know. Thus, we can now pass a subtype
ID, which is -1 except if it's a vector or array, then it's the element
type ID. Structs need to be handled differently.
---
 .../llvm/Transforms/IPO/Instrumentor.h        | 18 ++++
 .../IPO/InstrumentorRuntimeHelper.h           |  4 +-
 llvm/lib/Transforms/IPO/Instrumentor.cpp      | 97 +++++++++++++++++--
 .../IPO/InstrumentorStubPrinter.cpp           |  9 +-
 .../Instrumentor/alloca_and_function.ll       |  8 +-
 .../test/Instrumentation/Instrumentor/cast.ll |  2 +-
 .../Instrumentor/cast_crash.ll                |  4 +-
 .../Instrumentor/default_config.json          | 20 ++++
 .../Instrumentation/Instrumentor/default_rt.c | 44 ++++-----
 .../Instrumentor/generate_rt.ll               |  1 +
 .../Instrumentor/module_and_globals.ll        | 20 ++--
 .../Instrumentor/numeric_subtypeid.ll         | 39 ++++++++
 .../numeric_subtypeid_config.json             | 19 ++++
 .../Instrumentor/rt_config.json               | 16 +++
 14 files changed, 249 insertions(+), 52 deletions(-)
 create mode 100644 llvm/test/Instrumentation/Instrumentor/numeric_subtypeid.ll
 create mode 100644 llvm/test/Instrumentation/Instrumentor/numeric_subtypeid_config.json

diff --git a/llvm/include/llvm/Transforms/IPO/Instrumentor.h b/llvm/include/llvm/Transforms/IPO/Instrumentor.h
index b08edfde66fbc..843cfe5e90c8c 100644
--- a/llvm/include/llvm/Transforms/IPO/Instrumentor.h
+++ b/llvm/include/llvm/Transforms/IPO/Instrumentor.h
@@ -65,6 +65,7 @@ struct IRTArg {
     POTENTIALLY_INDIRECT = 1 << 3,
     INDIRECT_HAS_SIZE = 1 << 4,
     VALUE_PACK = 1 << 5,
+    TYPEID = 1 << 6,
     LAST,
   };
 
@@ -909,6 +910,7 @@ struct StoreIO : public InstructionIO<Instruction::Store> {
     PassStoredValueSize,
     PassAlignment,
     PassValueTypeId,
+    PassValueSubTypeId,
     PassAtomicityOrdering,
     PassSyncScopeId,
     PassIsVolatile,
@@ -958,6 +960,9 @@ struct StoreIO : public InstructionIO<Instruction::Store> {
   LLVM_ABI static Value *getValueTypeId(Value &V, Type &Ty,
                                         InstrumentationConfig &IConf,
                                         InstrumentorIRBuilderTy &IIRB);
+  LLVM_ABI static Value *getValueSubTypeId(Value &V, Type &Ty,
+                                           InstrumentationConfig &IConf,
+                                           InstrumentorIRBuilderTy &IIRB);
   LLVM_ABI static Value *getAtomicityOrdering(Value &V, Type &Ty,
                                               InstrumentationConfig &IConf,
                                               InstrumentorIRBuilderTy &IIRB);
@@ -1002,6 +1007,7 @@ struct LoadIO : public InstructionIO<Instruction::Load> {
     PassValueSize,
     PassAlignment,
     PassValueTypeId,
+    PassValueSubTypeId,
     PassAtomicityOrdering,
     PassSyncScopeId,
     PassIsVolatile,
@@ -1051,6 +1057,9 @@ struct LoadIO : public InstructionIO<Instruction::Load> {
   LLVM_ABI static Value *getValueTypeId(Value &V, Type &Ty,
                                         InstrumentationConfig &IConf,
                                         InstrumentorIRBuilderTy &IIRB);
+  LLVM_ABI static Value *getValueSubTypeId(Value &V, Type &Ty,
+                                           InstrumentationConfig &IConf,
+                                           InstrumentorIRBuilderTy &IIRB);
   LLVM_ABI static Value *getAtomicityOrdering(Value &V, Type &Ty,
                                               InstrumentationConfig &IConf,
                                               InstrumentorIRBuilderTy &IIRB);
@@ -1089,10 +1098,12 @@ struct CastIO final
   enum ConfigKind {
     PassInput,
     PassInputTypeId,
+    PassInputSubTypeId,
     PassInputSize,
     PassResult,
     ReplaceResult,
     PassResultTypeId,
+    PassResultSubTypeId,
     PassResultSize,
     PassOpcode,
     PassId,
@@ -1114,12 +1125,18 @@ struct CastIO final
   LLVM_ABI static Value *getInputTypeId(Value &V, Type &Ty,
                                         InstrumentationConfig &IConf,
                                         InstrumentorIRBuilderTy &IIRB);
+  LLVM_ABI static Value *getInputSubTypeId(Value &V, Type &Ty,
+                                           InstrumentationConfig &IConf,
+                                           InstrumentorIRBuilderTy &IIRB);
   LLVM_ABI static Value *getInputSize(Value &V, Type &Ty,
                                       InstrumentationConfig &IConf,
                                       InstrumentorIRBuilderTy &IIRB);
   LLVM_ABI static Value *getResultTypeId(Value &V, Type &Ty,
                                          InstrumentationConfig &IConf,
                                          InstrumentorIRBuilderTy &IIRB);
+  LLVM_ABI static Value *getResultSubTypeId(Value &V, Type &Ty,
+                                            InstrumentationConfig &IConf,
+                                            InstrumentorIRBuilderTy &IIRB);
   LLVM_ABI static Value *getResultSize(Value &V, Type &Ty,
                                        InstrumentationConfig &IConf,
                                        InstrumentorIRBuilderTy &IIRB);
@@ -1151,6 +1168,7 @@ struct NumericIO final
 
   enum ConfigKind {
     PassTypeId,
+    PassSubTypeId,
     PassSize,
     PassOpcode,
     PassResult,
diff --git a/llvm/include/llvm/Transforms/IPO/InstrumentorRuntimeHelper.h b/llvm/include/llvm/Transforms/IPO/InstrumentorRuntimeHelper.h
index 641096f2c0e22..5ec3b756b43bd 100644
--- a/llvm/include/llvm/Transforms/IPO/InstrumentorRuntimeHelper.h
+++ b/llvm/include/llvm/Transforms/IPO/InstrumentorRuntimeHelper.h
@@ -151,8 +151,10 @@ enum LLVMTypeID {
 };
 
 /// Get the string name of an LLVM Type ID.
-static inline const char *getLLVMTypeIDName(uint32_t type_id) {
+static inline const char *getLLVMTypeIDName(int32_t type_id) {
   switch (type_id) {
+  case -1:
+    return "none";
   case HalfTyID:
     return "half";
   case BFloatTyID:
diff --git a/llvm/lib/Transforms/IPO/Instrumentor.cpp b/llvm/lib/Transforms/IPO/Instrumentor.cpp
index f603306b36254..c93c3e061c2d0 100644
--- a/llvm/lib/Transforms/IPO/Instrumentor.cpp
+++ b/llvm/lib/Transforms/IPO/Instrumentor.cpp
@@ -154,6 +154,19 @@ Constant *getCI(Type *IT, Ty Val, bool IsSigned = false) {
   return ConstantInt::get(IT, Val, IsSigned);
 }
 
+Constant *getSubTypeID(Type &OpTy, Type &ReqTy) {
+  switch (OpTy.getTypeID()) {
+  case Type::TypeID::ArrayTyID:
+  case Type::TypeID::FixedVectorTyID:
+  case Type::TypeID::ScalableVectorTyID:
+    return getCI(&ReqTy, OpTy.getContainedType(0)->getTypeID());
+  default:
+    break;
+  }
+
+  return getCI(&ReqTy, -1, /*IsSigned=*/true);
+}
+
 /// The core of the instrumentor pass, which instruments the module as the
 /// instrumentation configuration mandates.
 class InstrumentorImpl final {
@@ -1011,6 +1024,11 @@ static Value *getTypeId(Value &V, Type &Ty, InstrumentationConfig &IConf,
   return getCI(&Ty, V.getType()->getTypeID());
 }
 
+static Value *getSubTypeId(Value &V, Type &Ty, InstrumentationConfig &IConf,
+                           InstrumentorIRBuilderTy &IIRB) {
+  return getSubTypeID(*V.getType(), Ty);
+}
+
 static Value *getSize(Value &V, Type &Ty, InstrumentationConfig &IConf,
                       InstrumentorIRBuilderTy &IIRB) {
   auto &I = cast<Instruction>(V);
@@ -1139,9 +1157,15 @@ void StoreIO::init(InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB,
   }
   if (Config.has(PassValueTypeId)) {
     IRTArgs.push_back(IRTArg(IIRB.Int32Ty, "value_type_id",
-                             "The type id of the stored value.", IRTArg::NONE,
+                             "The type id of the stored value.", IRTArg::TYPEID,
                              getValueTypeId));
   }
+  if (Config.has(PassValueSubTypeId)) {
+    IRTArgs.push_back(IRTArg(
+        IIRB.Int32Ty, "value_sub_type_id",
+        "The type id of the stored value (for arrays and vectors, or -1).",
+        IRTArg::TYPEID, getValueSubTypeId));
+  }
   if (Config.has(PassAtomicityOrdering)) {
     IRTArgs.push_back(IRTArg(IIRB.Int32Ty, "atomicity_ordering",
                              "The atomicity ordering of the store.",
@@ -1213,6 +1237,13 @@ Value *StoreIO::getValueTypeId(Value &V, Type &Ty, InstrumentationConfig &IConf,
   return getCI(&Ty, SI.getValueOperand()->getType()->getTypeID());
 }
 
+Value *StoreIO::getValueSubTypeId(Value &V, Type &Ty,
+                                  InstrumentationConfig &IConf,
+                                  InstrumentorIRBuilderTy &IIRB) {
+  auto &SI = cast<StoreInst>(V);
+  return getSubTypeID(*SI.getValueOperand()->getType(), Ty);
+}
+
 Value *StoreIO::getAtomicityOrdering(Value &V, Type &Ty,
                                      InstrumentationConfig &IConf,
                                      InstrumentorIRBuilderTy &IIRB) {
@@ -1276,9 +1307,15 @@ void LoadIO::init(InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB,
   }
   if (Config.has(PassValueTypeId)) {
     IRTArgs.push_back(IRTArg(IIRB.Int32Ty, "value_type_id",
-                             "The type id of the loaded value.", IRTArg::NONE,
+                             "The type id of the loaded value.", IRTArg::TYPEID,
                              getValueTypeId));
   }
+  if (Config.has(PassValueSubTypeId)) {
+    IRTArgs.push_back(IRTArg(
+        IIRB.Int32Ty, "value_sub_type_id",
+        "The sub type id of the loaded value (for arrays and vectors, or -1).",
+        IRTArg::TYPEID, getValueSubTypeId));
+  }
   if (Config.has(PassAtomicityOrdering)) {
     IRTArgs.push_back(IRTArg(IIRB.Int32Ty, "atomicity_ordering",
                              "The atomicity ordering of the load.",
@@ -1349,6 +1386,13 @@ Value *LoadIO::getValueTypeId(Value &V, Type &Ty, InstrumentationConfig &IConf,
   return getCI(&Ty, LI.getType()->getTypeID());
 }
 
+Value *LoadIO::getValueSubTypeId(Value &V, Type &Ty,
+                                 InstrumentationConfig &IConf,
+                                 InstrumentorIRBuilderTy &IIRB) {
+  auto &LI = cast<LoadInst>(V);
+  return getSubTypeID(*LI.getType(), Ty);
+}
+
 Value *LoadIO::getAtomicityOrdering(Value &V, Type &Ty,
                                     InstrumentationConfig &IConf,
                                     InstrumentorIRBuilderTy &IIRB) {
@@ -1625,12 +1669,21 @@ void CastIO::init(InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB,
     Config = *UserConfig;
   bool IsPRE = getLocationKind() == InstrumentationLocation::INSTRUCTION_PRE;
   if (Config.has(PassInput))
-    IRTArgs.push_back(IRTArg(IIRB.Int64Ty, "input", "Input value of the cast.",
-                             IRTArg::POTENTIALLY_INDIRECT, getInput));
+    IRTArgs.push_back(
+        IRTArg(IIRB.Int64Ty, "input", "Input value of the cast.",
+               IRTArg::POTENTIALLY_INDIRECT |
+                   (Config.has(PassResultSize) ? IRTArg::INDIRECT_HAS_SIZE
+                                               : IRTArg::NONE),
+               getInput));
   if (Config.has(PassInputTypeId))
     IRTArgs.push_back(IRTArg(IIRB.Int32Ty, "input_type_id",
-                             "The type id of the input value.", IRTArg::NONE,
+                             "The type id of the input value.", IRTArg::TYPEID,
                              getInputTypeId));
+  if (Config.has(PassInputSubTypeId))
+    IRTArgs.push_back(IRTArg(
+        IIRB.Int32Ty, "input_sub_type_id",
+        "The sub type id of the input value (for arrays and vectors, or -1).",
+        IRTArg::TYPEID, getInputSubTypeId));
   if (Config.has(PassInputSize))
     IRTArgs.push_back(IRTArg(IIRB.Int32Ty, "input_size",
                              "The size of the input value.", IRTArg::NONE,
@@ -1638,12 +1691,19 @@ void CastIO::init(InstrumentationConfig &IConf, InstrumentorIRBuilderTy &IIRB,
   if (!IsPRE && Config.has(PassResult))
     IRTArgs.push_back(
         IRTArg(IIRB.Int64Ty, "result", "Result of the cast.",
-               IRTArg::REPLACABLE | IRTArg::POTENTIALLY_INDIRECT, getValue,
-               Config.has(ReplaceResult) ? replaceValue : nullptr));
+               (IRTArg::REPLACABLE | IRTArg::POTENTIALLY_INDIRECT) |
+                   (Config.has(PassResultSize) ? IRTArg::INDIRECT_HAS_SIZE
+                                               : IRTArg::NONE),
+               getValue, Config.has(ReplaceResult) ? replaceValue : nullptr));
   if (Config.has(PassResultTypeId))
     IRTArgs.push_back(IRTArg(IIRB.Int32Ty, "result_type_id",
-                             "The type id of the result value.", IRTArg::NONE,
+                             "The type id of the result value.", IRTArg::TYPEID,
                              getResultTypeId));
+  if (Config.has(PassResultSubTypeId))
+    IRTArgs.push_back(IRTArg(
+        IIRB.Int32Ty, "result_sub_type_id",
+        "The sub type id of the result value (for arrays and vectors, or -1).",
+        IRTArg::TYPEID, getResultSubTypeId));
   if (Config.has(PassResultSize))
     IRTArgs.push_back(IRTArg(IIRB.Int32Ty, "result_size",
                              "The size of the result value.", IRTArg::NONE,
@@ -1669,6 +1729,13 @@ Value *CastIO::getInputTypeId(Value &V, Type &Ty, InstrumentationConfig &IConf,
   return getCI(&Ty, CI.getSrcTy()->getTypeID());
 }
 
+Value *CastIO::getInputSubTypeId(Value &V, Type &Ty,
+                                 InstrumentationConfig &IConf,
+                                 InstrumentorIRBuilderTy &IIRB) {
+  auto &CI = cast<CastInst>(V);
+  return getSubTypeID(*CI.getSrcTy(), Ty);
+}
+
 Value *CastIO::getInputSize(Value &V, Type &Ty, InstrumentationConfig &IConf,
                             InstrumentorIRBuilderTy &IIRB) {
   auto &CI = cast<CastInst>(V);
@@ -1682,6 +1749,13 @@ Value *CastIO::getResultTypeId(Value &V, Type &Ty, InstrumentationConfig &IConf,
   return getCI(&Ty, CI.getDestTy()->getTypeID());
 }
 
+Value *CastIO::getResultSubTypeId(Value &V, Type &Ty,
+                                  InstrumentationConfig &IConf,
+                                  InstrumentorIRBuilderTy &IIRB) {
+  auto &CI = cast<CastInst>(V);
+  return getSubTypeID(*CI.getDestTy(), Ty);
+}
+
 Value *CastIO::getResultSize(Value &V, Type &Ty, InstrumentationConfig &IConf,
                              InstrumentorIRBuilderTy &IIRB) {
   auto &CI = cast<CastInst>(V);
@@ -1770,8 +1844,13 @@ void NumericIO::init(InstrumentationConfig &IConf,
       (Config.has(PassSize) ? IRTArg::INDIRECT_HAS_SIZE : IRTArg::NONE);
   if (Config.has(PassTypeId))
     IRTArgs.push_back(IRTArg(IIRB.Int32Ty, "type_id",
-                             "The operation's type id.", IRTArg::NONE,
+                             "The operation's type id.", IRTArg::TYPEID,
                              getTypeId));
+  if (Config.has(PassSubTypeId))
+    IRTArgs.push_back(
+        IRTArg(IIRB.Int32Ty, "sub_type_id",
+               "The operation's sub type id (for arrays and vectors, or -1).",
+               IRTArg::TYPEID, getSubTypeId));
   if (Config.has(PassSize))
     IRTArgs.push_back(IRTArg(IIRB.Int32Ty, "size", "The operation's type size.",
                              IRTArg::NONE, getSize));
diff --git a/llvm/lib/Transforms/IPO/InstrumentorStubPrinter.cpp b/llvm/lib/Transforms/IPO/InstrumentorStubPrinter.cpp
index d892ad5de1f2e..a2c5c7660e61f 100644
--- a/llvm/lib/Transforms/IPO/InstrumentorStubPrinter.cpp
+++ b/llvm/lib/Transforms/IPO/InstrumentorStubPrinter.cpp
@@ -53,6 +53,8 @@ static std::pair<std::string, std::string> getAsCType(Type *Ty,
 /// type \p Ty. The flags in \p Flags describe the properties of the argument.
 /// See IRTArg::IRArgFlagTy.
 static std::string getPrintfFormatString(Type *Ty, unsigned Flags) {
+  if (Flags & IRTArg::TYPEID)
+    return "%s";
   if (Ty->isIntegerTy()) {
     if (Ty->getIntegerBitWidth() > 32) {
       assert(Ty->getIntegerBitWidth() == 64);
@@ -90,7 +92,12 @@ std::pair<std::string, std::string> IRTCallDescription::createCBodies() const {
     if (!First)
       AddToFormats(", ");
     First = false;
-    AddToArgs(", " + IRArg.Name);
+
+    if (!(IRArg.Flags & IRTArg::TYPEID)) {
+      AddToArgs(", " + IRArg.Name);
+    } else {
+      AddToArgs(", getLLVMTypeIDName(" + IRArg.Name + ")");
+    }
     AddToFormats(IRArg.Name + ": ");
     if (NumReplaceableArgs == 1 && (IRArg.Flags & IRTArg::REPLACABLE)) {
       DirectReturnValue = IRArg.Name;
diff --git a/llvm/test/Instrumentation/Instrumentor/alloca_and_function.ll b/llvm/test/Instrumentation/Instrumentor/alloca_and_function.ll
index f98dee743c09d..a2afecda64ebf 100644
--- a/llvm/test/Instrumentation/Instrumentor/alloca_and_function.ll
+++ b/llvm/test/Instrumentation/Instrumentor/alloca_and_function.ll
@@ -9,14 +9,12 @@ target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16
 
 declare void @use(ptr)
 
-;.
 ; CHECK: @llvm.global_ctors = appending global [1 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 1000, ptr @__instrumentor_ctor, ptr null }]
 ; CHECK: @__instrumentor_.str = private unnamed_addr constant [8 x i8] c"<stdin>\00", align 1
 ; CHECK: @__instrumentor_.str.1 = private unnamed_addr constant [1 x i8] zeroinitializer, align 1
 ; CHECK: @llvm.global_dtors = appending global [1 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 1000, ptr @__instrumentor_dtor, ptr null }]
 ; CHECK: @__instrumentor_.str.2 = private unnamed_addr constant [4 x i8] c"foo\00", align 1
 ; CHECK: @__instrumentor_value_pack = internal global <{ i32, i32, [6 x i8], i16, i32, i32, [4 x i8], float }> <{ i32 2, i32 12, [6 x i8] zeroinitializer, i16 0, i32 4, i32 2, [4 x i8] zeroinitializer, float 0.000000e+00 }>
-;.
 define float @foo(i16 %a, float %b) {
 ; CHECK-LABEL: define float @foo(
 ; CHECK-SAME: i16 [[A:%.*]], float [[B:%.*]]) {
@@ -37,9 +35,9 @@ define float @foo(i16 %a, float %b) {
 ; CHECK-NEXT:    [[TMP9:%.*]] = call ptr @__instrumentor_post_alloca(ptr [[TMP8]], i64 2, i64 16, i32 -3) #[[ATTR1]]
 ; CHECK-NEXT:    [[TMP15:%.*]] = call ptr @__instrumentor_post_base_pointer_info(ptr [[TMP9]], i32 2, i32 -4) #[[ATTR1]]
 ; CHECK-NEXT:    [[TMP10:%.*]] = zext i16 [[TMP4]] to i64
-; CHECK-NEXT:    [[TMP11:%.*]] = call ptr @__instrumentor_pre_store(ptr [[TMP9]], i32 0, ptr [[TMP15]], i64 [[TMP10]], i64 2, i64 2, i32 12, i32 0, i8 1, i8 0, i32 4) #[[ATTR1]]
+; CHECK-NEXT:    [[TMP11:%.*]] = call ptr @__instrumentor_pre_store(ptr [[TMP9]], i32 0, ptr [[TMP15]], i64 [[TMP10]], i64 2, i64 2, i32 12, i32 -1, i32 0, i8 1, i8 0, i32 4) #[[ATTR1]]
 ; CHECK-NEXT:    store i16 [[TMP4]], ptr [[TMP11]], align 2
-; CHECK-NEXT:    call void @__instrumentor_post_store(ptr [[TMP9]], i32 0, ptr [[TMP15]], i64 [[TMP10]], i64 2, i64 2, i32 12, i32 0, i8 1, i8 0, i32 -4) #[[ATTR1]]
+; CHECK-NEXT:    call void @__instrumentor_post_store(ptr [[TMP9]], i32 0, ptr [[TMP15]], i64 [[TMP10]], i64 2, i64 2, i32 12, i32 -1, i32 0, i8 1, i8 0, i32 -4) #[[ATTR1]]
 ; CHECK-NEXT:    call void @use(ptr [[TMP9]])
 ; CHECK-NEXT:    call void @llvm.memcpy.p0.p0.i64(ptr align 8 [[TMP0]], ptr @__instrumentor_value_pack, i64 32, i1 false)
 ; CHECK-NEXT:    [[TMP12:%.*]] = getelementptr inbounds nuw <{ i32, i32, [6 x i8], i16, i32, i32, [4 x i8], float }>, ptr [[TMP0]], i32 0, i32 3
@@ -55,7 +53,5 @@ entry:
   call void @use(ptr %0)
   ret float %b
 }
-;.
 ; CHECK: attributes #[[ATTR0:[0-9]+]] = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
 ; CHECK: attributes #[[ATTR1]] = { willreturn }
-;.
diff --git a/llvm/test/Instrumentation/Instrumentor/cast.ll b/llvm/test/Instrumentation/Instrumentor/cast.ll
index a8b1c96ec3878..77d9e0452784d 100644
--- a/llvm/test/Instrumentation/Instrumentor/cast.ll
+++ b/llvm/test/Instrumentation/Instrumentor/cast.ll
@@ -282,7 +282,7 @@ define i128 @test_ext(i32 %p1) {
 ; CHECK-NEXT:    [[I1:%.*]] = zext i32 [[P1]] to i128
 ; CHECK-NEXT:    store i64 [[TMP3]], ptr [[TMP2]], align 4
 ; CHECK-NEXT:    store i128 [[I1]], ptr [[TMP1]], align 4
-; CHECK-NEXT:    call void @__instrumentor_post_cast_ind(ptr [[TMP2]], i32 8, i32 12, i32 4, ptr [[TMP1]], i32 16, i32 12, i32 16, i32 40) #[[ATTR0]]
+; CHECK-NEXT:    call void @__instrumentor_post_cast_ind(ptr [[TMP2]], i32 12, i32 4, ptr [[TMP1]], i32 12, i32 16, i32 40) #[[ATTR0]]
 ; CHECK-NEXT:    [[TMP4:%.*]] = load i128, ptr [[TMP1]], align 4
 ; CHECK-NEXT:    ret i128 [[TMP4]]
 ;
diff --git a/llvm/test/Instrumentation/Instrumentor/cast_crash.ll b/llvm/test/Instrumentation/Instrumentor/cast_crash.ll
index ff4bde8b8f852..f9bf05c9c0cca 100644
--- a/llvm/test/Instrumentation/Instrumentor/cast_crash.ll
+++ b/llvm/test/Instrumentation/Instrumentor/cast_crash.ll
@@ -14,11 +14,11 @@ define i128 @test_ext(i32 %p1) {
 ; CHECK-NEXT:    [[TMP4:%.*]] = getelementptr inbounds i8, ptr [[TMP1]], i32 12
 ; CHECK-NEXT:    [[TMP5:%.*]] = load i32, ptr [[TMP4]], align 4
 ; CHECK-NEXT:    [[TMP6:%.*]] = zext i32 [[TMP5]] to i64
-; CHECK-NEXT:    call void @__instrumentor_pre_cast(i64 [[TMP6]], i32 12, i32 4, i32 12, i32 16, i32 40, i32 3) #[[ATTR1]]
+; CHECK-NEXT:    call void @__instrumentor_pre_cast(i64 [[TMP6]], i32 12, i32 -1, i32 4, i32 12, i32 -1, i32 16, i32 40, i32 3) #[[ATTR1]]
 ; CHECK-NEXT:    [[I1:%.*]] = zext i32 [[TMP5]] to i128
 ; CHECK-NEXT:    store i64 [[TMP6]], ptr [[TMP2]], align 4
 ; CHECK-NEXT:    store i128 [[I1]], ptr [[TMP1]], align 4
-; CHECK-NEXT:    call void @__instrumentor_post_cast_ind(ptr [[TMP2]], i32 8, i32 12, i32 4, ptr [[TMP1]], i32 16, i32 12, i32 16, i32 40, i32 -3) #[[ATTR1]]
+; CHECK-NEXT:    call void @__instrumentor_post_cast_ind(ptr [[TMP2]], i32 12, i32 -1, i32 4, ptr [[TMP1]], i32 12, i32 -1, i32 16, i32 40, i32 -3) #[[ATTR1]]
 ; CHECK-NEXT:    [[TMP7:%.*]] = load i128, ptr [[TMP1]], align 4
 ; CHECK-NEXT:    call void @llvm.memcpy.p0.p0.i64(ptr align 8 [[TMP1]], ptr @__instrumentor_value_pack, i64 16, i1 false)
 ; CHECK-NEXT:    [[TMP8:%.*]] = getelementptr inbounds nuw <{ i32, i32, [4 x i8], i32 }>, ptr [[TMP1]], i32 0, i32 3
diff --git a/llvm/test/Instrumentation/Instrumentor/default_config.json b/llvm/test/Instrumentation/Instrumentor/default_config.json
index 08bde4a265450..12c95b9407bcf 100644
--- a/llvm/test/Instrumentation/Instrumentor/default_config.json
+++ b/llvm/test/Instrumentation/Instrumentor/default_config.json
@@ -168,6 +168,8 @@
       "alignment.description": "The known access alignment.",
       "value_type_id": true,
       "value_type_id.description": "The type id of the loaded value.",
+      "value_sub_type_id": true,
+      "value_sub_type_id.description": "The sub type id of the loaded value (for arrays and vectors, or -1).",
       "atomicity_ordering": true,
       "atomicity_ordering.description": "The atomicity ordering of the load.",
       "sync_scope_id": true,
@@ -196,6 +198,8 @@
       "alignment.description": "The known access alignment.",
       "value_type_id": true,
       "value_type_id.description": "The type id of the stored value.",
+      "value_sub_type_id": true,
+      "value_sub_type_id.description": "The type id of the stored value (for arrays and vectors, or -1).",
       "atomicity_ordering": true,
       "atomicity_ordering.description": "The atomicity ordering of the store.",
       "sync_scope_id": true,
@@ -213,10 +217,14 @@
       "input.description": "Input value of the cast.",
       "input_type_id": true,
       "input_type_id.description": "The type id of the input value.",
+      "input_sub_type_id": true,
+      "input_sub_type_id.description": "The sub type id of the input value (for arrays and vectors, or -1).",
       "input_size": true,
       "input_size.description": "The size of the input value.",
       "result_type_id": true,
       "result_type_id.description": "The type id of the result value.",
+      "result_sub_type_id": true,
+      "result_sub_type_id.description": "The sub type id of the result value (for arrays and vectors, or -1).",
       "result_size": true,
       "result_size.description": "The size of the result value.",
       "opcode": true,
@@ -230,6 +238,8 @@
       "filter.description": "Static property filter to exclude instrumentation.",
       "type_id": true,
       "type_id.description": "The operation's type id.",
+      "sub_type_id": true,
+      "sub_type_id.description": "The operation's sub type id (for arrays and vectors, or -1).",
       "size": true,
       "size.description": "The operation's type size.",
       "opcode": true,
@@ -278,6 +288,8 @@
       "alignment.description": "The known access alignment.",
       "value_type_id": true,
       "value_type_id.description": "The type id of the loaded value.",
+      "value_sub_type_id": true,
+      "value_sub_type_id.description": "The sub type id of the loaded value (for arrays and vectors, or -1).",
       "atomicity_ordering": true,
       "atomicity_ordering.description": "The atomicity ordering of the load.",
       "sync_scope_id": true,
@@ -305,6 +317,8 @@
       "alignment.description": "The known access alignment.",
       "value_type_id": true,
       "value_type_id.description": "The type id of the stored value.",
+      "value_sub_type_id": true,
+      "value_sub_type_id.description": "The type id of the stored value (for arrays and vectors, or -1).",
       "atomicity_ordering": true,
       "atomicity_ordering.description": "The atomicity ordering of the store.",
       "sync_scope_id": true,
@@ -322,6 +336,8 @@
       "input.description": "Input value of the cast.",
       "input_type_id": true,
       "input_type_id.description": "The type id of the input value.",
+      "input_sub_type_id": true,
+      "input_sub_type_id.description": "The sub type id of the input value (for arrays and vectors, or -1).",
       "input_size": true,
       "input_size.description": "The size of the input value.",
       "result": true,
@@ -329,6 +345,8 @@
       "result.description": "Result of the cast.",
       "result_type_id": true,
       "result_type_id.description": "The type id of the result value.",
+      "result_sub_type_id": true,
+      "result_sub_type_id.description": "The sub type id of the result value (for arrays and vectors, or -1).",
       "result_size": true,
       "result_size.description": "The size of the result value.",
       "opcode": true,
@@ -342,6 +360,8 @@
       "filter.description": "Static property filter to exclude instrumentation.",
       "type_id": true,
       "type_id.description": "The operation's type id.",
+      "sub_type_id": true,
+      "sub_type_id.description": "The operation's sub type id (for arrays and vectors, or -1).",
       "size": true,
       "size.description": "The operation's type size.",
       "opcode": true,
diff --git a/llvm/test/Instrumentation/Instrumentor/default_rt.c b/llvm/test/Instrumentation/Instrumentor/default_rt.c
index 9ecb188605e1e..bce5fa9c63a1e 100644
--- a/llvm/test/Instrumentation/Instrumentor/default_rt.c
+++ b/llvm/test/Instrumentation/Instrumentor/default_rt.c
@@ -82,27 +82,27 @@ void __instrumentor_pre_unreachable(int32_t id) {
   printf("unreachable pre -- id: %" PRId32 "\n", id);
 }
 
-void *__instrumentor_pre_load(void *pointer, int32_t pointer_as, void *base_pointer_info, int64_t value_size, int64_t alignment, int32_t value_type_id, int32_t atomicity_ordering, int8_t sync_scope_id, int8_t is_volatile, int32_t id) {
-  printf("load pre -- pointer: %p, pointer_as: %" PRId32 ", base_pointer_info: %p, value_size: %" PRId64 ", alignment: %" PRId64 ", value_type_id: %" PRId32 ", atomicity_ordering: %" PRId32 ", sync_scope_id: %" PRId32 ", is_volatile: %" PRId32 ", id: %" PRId32 "\n", pointer, pointer_as, base_pointer_info, value_size, alignment, value_type_id, atomicity_ordering, sync_scope_id, is_volatile, id);
+void *__instrumentor_pre_load(void *pointer, int32_t pointer_as, void *base_pointer_info, int64_t value_size, int64_t alignment, int32_t value_type_id, int32_t value_sub_type_id, int32_t atomicity_ordering, int8_t sync_scope_id, int8_t is_volatile, int32_t id) {
+  printf("load pre -- pointer: %p, pointer_as: %" PRId32 ", base_pointer_info: %p, value_size: %" PRId64 ", alignment: %" PRId64 ", value_type_id: %s, value_sub_type_id: %s, atomicity_ordering: %" PRId32 ", sync_scope_id: %" PRId32 ", is_volatile: %" PRId32 ", id: %" PRId32 "\n", pointer, pointer_as, base_pointer_info, value_size, alignment, getLLVMTypeIDName(value_type_id), getLLVMTypeIDName(value_sub_type_id), atomicity_ordering, sync_scope_id, is_volatile, id);
   return pointer;
 }
 
-void *__instrumentor_pre_store(void *pointer, int32_t pointer_as, void *base_pointer_info, int64_t value, int64_t value_size, int64_t alignment, int32_t value_type_id, int32_t atomicity_ordering, int8_t sync_scope_id, int8_t is_volatile, int32_t id) {
-  printf("store pre -- pointer: %p, pointer_as: %" PRId32 ", base_pointer_info: %p, value: %" PRId64 ", value_size: %" PRId64 ", alignment: %" PRId64 ", value_type_id: %" PRId32 ", atomicity_ordering: %" PRId32 ", sync_scope_id: %" PRId32 ", is_volatile: %" PRId32 ", id: %" PRId32 "\n", pointer, pointer_as, base_pointer_info, value, value_size, alignment, value_type_id, atomicity_ordering, sync_scope_id, is_volatile, id);
+void *__instrumentor_pre_store(void *pointer, int32_t pointer_as, void *base_pointer_info, int64_t value, int64_t value_size, int64_t alignment, int32_t value_type_id, int32_t value_sub_type_id, int32_t atomicity_ordering, int8_t sync_scope_id, int8_t is_volatile, int32_t id) {
+  printf("store pre -- pointer: %p, pointer_as: %" PRId32 ", base_pointer_info: %p, value: %" PRId64 ", value_size: %" PRId64 ", alignment: %" PRId64 ", value_type_id: %s, value_sub_type_id: %s, atomicity_ordering: %" PRId32 ", sync_scope_id: %" PRId32 ", is_volatile: %" PRId32 ", id: %" PRId32 "\n", pointer, pointer_as, base_pointer_info, value, value_size, alignment, getLLVMTypeIDName(value_type_id), getLLVMTypeIDName(value_sub_type_id), atomicity_ordering, sync_scope_id, is_volatile, id);
   return pointer;
 }
 
-void *__instrumentor_pre_store_ind(void *pointer, int32_t pointer_as, void *base_pointer_info, int64_t *value_ptr, int64_t value_size, int64_t alignment, int32_t value_type_id, int32_t atomicity_ordering, int8_t sync_scope_id, int8_t is_volatile, int32_t id) {
-  printf("store pre -- pointer: %p, pointer_as: %" PRId32 ", base_pointer_info: %p, value: %p, value_size: %" PRId64 ", alignment: %" PRId64 ", value_type_id: %" PRId32 ", atomicity_ordering: %" PRId32 ", sync_scope_id: %" PRId32 ", is_volatile: %" PRId32 ", id: %" PRId32 "\n", pointer, pointer_as, base_pointer_info, value_ptr, value_size, alignment, value_type_id, atomicity_ordering, sync_scope_id, is_volatile, id);
+void *__instrumentor_pre_store_ind(void *pointer, int32_t pointer_as, void *base_pointer_info, int64_t *value_ptr, int64_t value_size, int64_t alignment, int32_t value_type_id, int32_t value_sub_type_id, int32_t atomicity_ordering, int8_t sync_scope_id, int8_t is_volatile, int32_t id) {
+  printf("store pre -- pointer: %p, pointer_as: %" PRId32 ", base_pointer_info: %p, value: %p, value_size: %" PRId64 ", alignment: %" PRId64 ", value_type_id: %s, value_sub_type_id: %s, atomicity_ordering: %" PRId32 ", sync_scope_id: %" PRId32 ", is_volatile: %" PRId32 ", id: %" PRId32 "\n", pointer, pointer_as, base_pointer_info, value_ptr, value_size, alignment, getLLVMTypeIDName(value_type_id), getLLVMTypeIDName(value_sub_type_id), atomicity_ordering, sync_scope_id, is_volatile, id);
   return pointer;
 }
 
-void __instrumentor_pre_cast(int64_t input, int32_t input_type_id, int32_t input_size, int32_t result_type_id, int32_t result_size, int32_t opcode, int32_t id) {
-  printf("cast pre -- input: %" PRId64 ", input_type_id: %" PRId32 ", input_size: %" PRId32 ", result_type_id: %" PRId32 ", result_size: %" PRId32 ", opcode: %" PRId32 ", id: %" PRId32 "\n", input, input_type_id, input_size, result_type_id, result_size, opcode, id);
+void __instrumentor_pre_cast(int64_t input, int32_t input_type_id, int32_t input_sub_type_id, int32_t input_size, int32_t result_type_id, int32_t result_sub_type_id, int32_t result_size, int32_t opcode, int32_t id) {
+  printf("cast pre -- input: %" PRId64 ", input_type_id: %s, input_sub_type_id: %s, input_size: %" PRId32 ", result_type_id: %s, result_sub_type_id: %s, result_size: %" PRId32 ", opcode: %" PRId32 ", id: %" PRId32 "\n", input, getLLVMTypeIDName(input_type_id), getLLVMTypeIDName(input_sub_type_id), input_size, getLLVMTypeIDName(result_type_id), getLLVMTypeIDName(result_sub_type_id), result_size, opcode, id);
 }
 
-void __instrumentor_pre_cast_ind(int64_t *input_ptr, int32_t input_size, int32_t input_type_id, int32_t input_size, int32_t result_type_id, int32_t result_size, int32_t opcode, int32_t id) {
-  printf("cast pre -- input: %p, input_size: %" PRId32 ", input_type_id: %" PRId32 ", input_size: %" PRId32 ", result_type_id: %" PRId32 ", result_size: %" PRId32 ", opcode: %" PRId32 ", id: %" PRId32 "\n", input_ptr, input_size, input_type_id, input_size, result_type_id, result_size, opcode, id);
+void __instrumentor_pre_cast_ind(int64_t *input_ptr, int32_t input_type_id, int32_t input_sub_type_id, int32_t input_size, int32_t result_type_id, int32_t result_sub_type_id, int32_t result_size, int32_t opcode, int32_t id) {
+  printf("cast pre -- input: %p, input_type_id: %s, input_sub_type_id: %s, input_size: %" PRId32 ", result_type_id: %s, result_sub_type_id: %s, result_size: %" PRId32 ", opcode: %" PRId32 ", id: %" PRId32 "\n", input_ptr, getLLVMTypeIDName(input_type_id), getLLVMTypeIDName(input_sub_type_id), input_size, getLLVMTypeIDName(result_type_id), getLLVMTypeIDName(result_sub_type_id), result_size, opcode, id);
 }
 
 void *__instrumentor_post_alloca(void *address, int64_t size, int64_t alignment, int32_t id) {
@@ -110,30 +110,30 @@ void *__instrumentor_post_alloca(void *address, int64_t size, int64_t alignment,
   return address;
 }
 
-int64_t __instrumentor_post_load(void *pointer, int32_t pointer_as, void *base_pointer_info, int64_t value, int64_t value_size, int64_t alignment, int32_t value_type_id, int32_t atomicity_ordering, int8_t sync_scope_id, int8_t is_volatile, int32_t id) {
-  printf("load post -- pointer: %p, pointer_as: %" PRId32 ", base_pointer_info: %p, value: %" PRId64 ", value_size: %" PRId64 ", alignment: %" PRId64 ", value_type_id: %" PRId32 ", atomicity_ordering: %" PRId32 ", sync_scope_id: %" PRId32 ", is_volatile: %" PRId32 ", id: %" PRId32 "\n", pointer, pointer_as, base_pointer_info, value, value_size, alignment, value_type_id, atomicity_ordering, sync_scope_id, is_volatile, id);
+int64_t __instrumentor_post_load(void *pointer, int32_t pointer_as, void *base_pointer_info, int64_t value, int64_t value_size, int64_t alignment, int32_t value_type_id, int32_t value_sub_type_id, int32_t atomicity_ordering, int8_t sync_scope_id, int8_t is_volatile, int32_t id) {
+  printf("load post -- pointer: %p, pointer_as: %" PRId32 ", base_pointer_info: %p, value: %" PRId64 ", value_size: %" PRId64 ", alignment: %" PRId64 ", value_type_id: %s, value_sub_type_id: %s, atomicity_ordering: %" PRId32 ", sync_scope_id: %" PRId32 ", is_volatile: %" PRId32 ", id: %" PRId32 "\n", pointer, pointer_as, base_pointer_info, value, value_size, alignment, getLLVMTypeIDName(value_type_id), getLLVMTypeIDName(value_sub_type_id), atomicity_ordering, sync_scope_id, is_volatile, id);
   return value;
 }
 
-void __instrumentor_post_load_ind(void *pointer, int32_t pointer_as, void *base_pointer_info, int64_t *value_ptr, int64_t value_size, int64_t alignment, int32_t value_type_id, int32_t atomicity_ordering, int8_t sync_scope_id, int8_t is_volatile, int32_t id) {
-  printf("load post -- pointer: %p, pointer_as: %" PRId32 ", base_pointer_info: %p, value: %p, value_size: %" PRId64 ", alignment: %" PRId64 ", value_type_id: %" PRId32 ", atomicity_ordering: %" PRId32 ", sync_scope_id: %" PRId32 ", is_volatile: %" PRId32 ", id: %" PRId32 "\n", pointer, pointer_as, base_pointer_info, value_ptr, value_size, alignment, value_type_id, atomicity_ordering, sync_scope_id, is_volatile, id);
+void __instrumentor_post_load_ind(void *pointer, int32_t pointer_as, void *base_pointer_info, int64_t *value_ptr, int64_t value_size, int64_t alignment, int32_t value_type_id, int32_t value_sub_type_id, int32_t atomicity_ordering, int8_t sync_scope_id, int8_t is_volatile, int32_t id) {
+  printf("load post -- pointer: %p, pointer_as: %" PRId32 ", base_pointer_info: %p, value: %p, value_size: %" PRId64 ", alignment: %" PRId64 ", value_type_id: %s, value_sub_type_id: %s, atomicity_ordering: %" PRId32 ", sync_scope_id: %" PRId32 ", is_volatile: %" PRId32 ", id: %" PRId32 "\n", pointer, pointer_as, base_pointer_info, value_ptr, value_size, alignment, getLLVMTypeIDName(value_type_id), getLLVMTypeIDName(value_sub_type_id), atomicity_ordering, sync_scope_id, is_volatile, id);
 }
 
-void __instrumentor_post_store(void *pointer, int32_t pointer_as, void *base_pointer_info, int64_t value, int64_t value_size, int64_t alignment, int32_t value_type_id, int32_t atomicity_ordering, int8_t sync_scope_id, int8_t is_volatile, int32_t id) {
-  printf("store post -- pointer: %p, pointer_as: %" PRId32 ", base_pointer_info: %p, value: %" PRId64 ", value_size: %" PRId64 ", alignment: %" PRId64 ", value_type_id: %" PRId32 ", atomicity_ordering: %" PRId32 ", sync_scope_id: %" PRId32 ", is_volatile: %" PRId32 ", id: %" PRId32 "\n", pointer, pointer_as, base_pointer_info, value, value_size, alignment, value_type_id, atomicity_ordering, sync_scope_id, is_volatile, id);
+void __instrumentor_post_store(void *pointer, int32_t pointer_as, void *base_pointer_info, int64_t value, int64_t value_size, int64_t alignment, int32_t value_type_id, int32_t value_sub_type_id, int32_t atomicity_ordering, int8_t sync_scope_id, int8_t is_volatile, int32_t id) {
+  printf("store post -- pointer: %p, pointer_as: %" PRId32 ", base_pointer_info: %p, value: %" PRId64 ", value_size: %" PRId64 ", alignment: %" PRId64 ", value_type_id: %s, value_sub_type_id: %s, atomicity_ordering: %" PRId32 ", sync_scope_id: %" PRId32 ", is_volatile: %" PRId32 ", id: %" PRId32 "\n", pointer, pointer_as, base_pointer_info, value, value_size, alignment, getLLVMTypeIDName(value_type_id), getLLVMTypeIDName(value_sub_type_id), atomicity_ordering, sync_scope_id, is_volatile, id);
 }
 
-void __instrumentor_post_store_ind(void *pointer, int32_t pointer_as, void *base_pointer_info, int64_t *value_ptr, int64_t value_size, int64_t alignment, int32_t value_type_id, int32_t atomicity_ordering, int8_t sync_scope_id, int8_t is_volatile, int32_t id) {
-  printf("store post -- pointer: %p, pointer_as: %" PRId32 ", base_pointer_info: %p, value: %p, value_size: %" PRId64 ", alignment: %" PRId64 ", value_type_id: %" PRId32 ", atomicity_ordering: %" PRId32 ", sync_scope_id: %" PRId32 ", is_volatile: %" PRId32 ", id: %" PRId32 "\n", pointer, pointer_as, base_pointer_info, value_ptr, value_size, alignment, value_type_id, atomicity_ordering, sync_scope_id, is_volatile, id);
+void __instrumentor_post_store_ind(void *pointer, int32_t pointer_as, void *base_pointer_info, int64_t *value_ptr, int64_t value_size, int64_t alignment, int32_t value_type_id, int32_t value_sub_type_id, int32_t atomicity_ordering, int8_t sync_scope_id, int8_t is_volatile, int32_t id) {
+  printf("store post -- pointer: %p, pointer_as: %" PRId32 ", base_pointer_info: %p, value: %p, value_size: %" PRId64 ", alignment: %" PRId64 ", value_type_id: %s, value_sub_type_id: %s, atomicity_ordering: %" PRId32 ", sync_scope_id: %" PRId32 ", is_volatile: %" PRId32 ", id: %" PRId32 "\n", pointer, pointer_as, base_pointer_info, value_ptr, value_size, alignment, getLLVMTypeIDName(value_type_id), getLLVMTypeIDName(value_sub_type_id), atomicity_ordering, sync_scope_id, is_volatile, id);
 }
 
-int64_t __instrumentor_post_cast(int64_t input, int32_t input_type_id, int32_t input_size, int64_t result, int32_t result_type_id, int32_t result_size, int32_t opcode, int32_t id) {
-  printf("cast post -- input: %" PRId64 ", input_type_id: %" PRId32 ", input_size: %" PRId32 ", result: %" PRId64 ", result_type_id: %" PRId32 ", result_size: %" PRId32 ", opcode: %" PRId32 ", id: %" PRId32 "\n", input, input_type_id, input_size, result, result_type_id, result_size, opcode, id);
+int64_t __instrumentor_post_cast(int64_t input, int32_t input_type_id, int32_t input_sub_type_id, int32_t input_size, int64_t result, int32_t result_type_id, int32_t result_sub_type_id, int32_t result_size, int32_t opcode, int32_t id) {
+  printf("cast post -- input: %" PRId64 ", input_type_id: %s, input_sub_type_id: %s, input_size: %" PRId32 ", result: %" PRId64 ", result_type_id: %s, result_sub_type_id: %s, result_size: %" PRId32 ", opcode: %" PRId32 ", id: %" PRId32 "\n", input, getLLVMTypeIDName(input_type_id), getLLVMTypeIDName(input_sub_type_id), input_size, result, getLLVMTypeIDName(result_type_id), getLLVMTypeIDName(result_sub_type_id), result_size, opcode, id);
   return result;
 }
 
-void __instrumentor_post_cast_ind(int64_t *input_ptr, int32_t input_size, int32_t input_type_id, int32_t input_size, int64_t *result_ptr, int32_t result_size, int32_t result_type_id, int32_t result_size, int32_t opcode, int32_t id) {
-  printf("cast post -- input: %p, input_size: %" PRId32 ", input_type_id: %" PRId32 ", input_size: %" PRId32 ", result: %p, result_size: %" PRId32 ", result_type_id: %" PRId32 ", result_size: %" PRId32 ", opcode: %" PRId32 ", id: %" PRId32 "\n", input_ptr, input_size, input_type_id, input_size, result_ptr, result_size, result_type_id, result_size, opcode, id);
+void __instrumentor_post_cast_ind(int64_t *input_ptr, int32_t input_type_id, int32_t input_sub_type_id, int32_t input_size, int64_t *result_ptr, int32_t result_type_id, int32_t result_sub_type_id, int32_t result_size, int32_t opcode, int32_t id) {
+  printf("cast post -- input: %p, input_type_id: %s, input_sub_type_id: %s, input_size: %" PRId32 ", result: %p, result_type_id: %s, result_sub_type_id: %s, result_size: %" PRId32 ", opcode: %" PRId32 ", id: %" PRId32 "\n", input_ptr, getLLVMTypeIDName(input_type_id), getLLVMTypeIDName(input_sub_type_id), input_size, result_ptr, getLLVMTypeIDName(result_type_id), getLLVMTypeIDName(result_sub_type_id), result_size, opcode, id);
 }
 
 void *__instrumentor_post_base_pointer_info(void *base_pointer, int32_t base_pointer_kind, int32_t id) {
diff --git a/llvm/test/Instrumentation/Instrumentor/generate_rt.ll b/llvm/test/Instrumentation/Instrumentor/generate_rt.ll
index 533561b73ce39..1e72becdcd34c 100644
--- a/llvm/test/Instrumentation/Instrumentor/generate_rt.ll
+++ b/llvm/test/Instrumentation/Instrumentor/generate_rt.ll
@@ -1,3 +1,4 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6
 ; RUN: rm -rf %t && mkdir -p %t && cd %t
 ; RUN: opt < %s -passes=instrumentor -instrumentor-read-config-files=%S/rt_config.json -S
 ; RUN: diff -b default_rt.c %S/default_rt.c
diff --git a/llvm/test/Instrumentation/Instrumentor/module_and_globals.ll b/llvm/test/Instrumentation/Instrumentor/module_and_globals.ll
index c76eb47030648..64cb0737d0863 100644
--- a/llvm/test/Instrumentation/Instrumentor/module_and_globals.ll
+++ b/llvm/test/Instrumentation/Instrumentor/module_and_globals.ll
@@ -39,34 +39,34 @@ entry:
 ; CHECK-NEXT:    [[TMP1:%.*]] = call ptr @__instrumentor_post_base_pointer_info(ptr [[Y_SHADOW_LOAD]], i32 2, i32 -10) #[[ATTR0]]
 ; CHECK-NEXT:    [[X_SHADOW_LOAD:%.*]] = load ptr, ptr @__instrumentor_shadow.X, align 8
 ; CHECK-NEXT:    [[TMP2:%.*]] = call ptr @__instrumentor_post_base_pointer_info(ptr [[X_SHADOW_LOAD]], i32 2, i32 -9) #[[ATTR0]]
-; CHECK-NEXT:    [[TMP10:%.*]] = call ptr @__instrumentor_pre_load(ptr [[X_SHADOW_LOAD]], i32 0, ptr [[TMP2]], i64 4, i64 4, i32 12, i32 0, i8 1, i8 0, i32 9) #[[ATTR0]]
+; CHECK-NEXT:    [[TMP10:%.*]] = call ptr @__instrumentor_pre_load(ptr [[X_SHADOW_LOAD]], i32 0, ptr [[TMP2]], i64 4, i64 4, i32 12, i32 -1, i32 0, i8 1, i8 0, i32 9) #[[ATTR0]]
 ; CHECK-NEXT:    [[TMP11:%.*]] = load i32, ptr [[TMP10]], align 4
 ; CHECK-NEXT:    [[TMP12:%.*]] = zext i32 [[TMP11]] to i64
-; CHECK-NEXT:    [[TMP13:%.*]] = call i64 @__instrumentor_post_load(ptr [[X_SHADOW_LOAD]], i32 0, ptr [[TMP2]], i64 [[TMP12]], i64 4, i64 4, i32 12, i32 0, i8 1, i8 0, i32 -9) #[[ATTR0]]
+; CHECK-NEXT:    [[TMP13:%.*]] = call i64 @__instrumentor_post_load(ptr [[X_SHADOW_LOAD]], i32 0, ptr [[TMP2]], i64 [[TMP12]], i64 4, i64 4, i32 12, i32 -1, i32 0, i8 1, i8 0, i32 -9) #[[ATTR0]]
 ; CHECK-NEXT:    [[TMP14:%.*]] = trunc i64 [[TMP13]] to i32
-; CHECK-NEXT:    [[TMP8:%.*]] = call ptr @__instrumentor_pre_load(ptr [[Y_SHADOW_LOAD]], i32 0, ptr [[TMP1]], i64 4, i64 4, i32 12, i32 0, i8 1, i8 0, i32 10) #[[ATTR0]]
+; CHECK-NEXT:    [[TMP8:%.*]] = call ptr @__instrumentor_pre_load(ptr [[Y_SHADOW_LOAD]], i32 0, ptr [[TMP1]], i64 4, i64 4, i32 12, i32 -1, i32 0, i8 1, i8 0, i32 10) #[[ATTR0]]
 ; CHECK-NEXT:    [[TMP4:%.*]] = load i32, ptr [[TMP8]], align 4
 ; CHECK-NEXT:    [[TMP15:%.*]] = zext i32 [[TMP4]] to i64
-; CHECK-NEXT:    [[TMP21:%.*]] = call i64 @__instrumentor_post_load(ptr [[Y_SHADOW_LOAD]], i32 0, ptr [[TMP1]], i64 [[TMP15]], i64 4, i64 4, i32 12, i32 0, i8 1, i8 0, i32 -10) #[[ATTR0]]
+; CHECK-NEXT:    [[TMP21:%.*]] = call i64 @__instrumentor_post_load(ptr [[Y_SHADOW_LOAD]], i32 0, ptr [[TMP1]], i64 [[TMP15]], i64 4, i64 4, i32 12, i32 -1, i32 0, i8 1, i8 0, i32 -10) #[[ATTR0]]
 ; CHECK-NEXT:    [[TMP25:%.*]] = trunc i64 [[TMP21]] to i32
-; CHECK-NEXT:    [[TMP26:%.*]] = call ptr @__instrumentor_pre_load(ptr [[Z_SHADOW_LOAD]], i32 0, ptr [[TMP0]], i64 4, i64 4, i32 12, i32 0, i8 1, i8 0, i32 11) #[[ATTR0]]
+; CHECK-NEXT:    [[TMP26:%.*]] = call ptr @__instrumentor_pre_load(ptr [[Z_SHADOW_LOAD]], i32 0, ptr [[TMP0]], i64 4, i64 4, i32 12, i32 -1, i32 0, i8 1, i8 0, i32 11) #[[ATTR0]]
 ; CHECK-NEXT:    [[TMP9:%.*]] = load i32, ptr [[TMP26]], align 4
 ; CHECK-NEXT:    [[TMP16:%.*]] = zext i32 [[TMP9]] to i64
-; CHECK-NEXT:    [[TMP27:%.*]] = call i64 @__instrumentor_post_load(ptr [[Z_SHADOW_LOAD]], i32 0, ptr [[TMP0]], i64 [[TMP16]], i64 4, i64 4, i32 12, i32 0, i8 1, i8 0, i32 -11) #[[ATTR0]]
+; CHECK-NEXT:    [[TMP27:%.*]] = call i64 @__instrumentor_post_load(ptr [[Z_SHADOW_LOAD]], i32 0, ptr [[TMP0]], i64 [[TMP16]], i64 4, i64 4, i32 12, i32 -1, i32 0, i8 1, i8 0, i32 -11) #[[ATTR0]]
 ; CHECK-NEXT:    [[TMP28:%.*]] = trunc i64 [[TMP27]] to i32
 ; CHECK-NEXT:    [[TMP29:%.*]] = zext i32 [[TMP14]] to i64
 ; CHECK-NEXT:    [[TMP30:%.*]] = zext i32 [[TMP25]] to i64
-; CHECK-NEXT:    call void @__instrumentor_pre_numeric(i32 12, i32 4, i32 14, i64 [[TMP29]], i64 [[TMP30]], i64 1, i32 12) #[[ATTR0]]
+; CHECK-NEXT:    call void @__instrumentor_pre_numeric(i32 12, i32 -1, i32 4, i32 14, i64 [[TMP29]], i64 [[TMP30]], i64 1, i32 12) #[[ATTR0]]
 ; CHECK-NEXT:    [[ADD:%.*]] = add nsw i32 [[TMP14]], [[TMP25]]
 ; CHECK-NEXT:    [[TMP17:%.*]] = zext i32 [[ADD]] to i64
-; CHECK-NEXT:    [[TMP18:%.*]] = call i64 @__instrumentor_post_numeric(i32 12, i32 4, i32 14, i64 [[TMP29]], i64 [[TMP30]], i64 [[TMP17]], i64 1, i32 -12) #[[ATTR0]]
+; CHECK-NEXT:    [[TMP18:%.*]] = call i64 @__instrumentor_post_numeric(i32 12, i32 -1, i32 4, i32 14, i64 [[TMP29]], i64 [[TMP30]], i64 [[TMP17]], i64 1, i32 -12) #[[ATTR0]]
 ; CHECK-NEXT:    [[TMP19:%.*]] = trunc i64 [[TMP18]] to i32
 ; CHECK-NEXT:    [[TMP20:%.*]] = zext i32 [[TMP19]] to i64
 ; CHECK-NEXT:    [[TMP24:%.*]] = zext i32 [[TMP28]] to i64
-; CHECK-NEXT:    call void @__instrumentor_pre_numeric(i32 12, i32 4, i32 14, i64 [[TMP20]], i64 [[TMP24]], i64 1, i32 13) #[[ATTR0]]
+; CHECK-NEXT:    call void @__instrumentor_pre_numeric(i32 12, i32 -1, i32 4, i32 14, i64 [[TMP20]], i64 [[TMP24]], i64 1, i32 13) #[[ATTR0]]
 ; CHECK-NEXT:    [[ADD3:%.*]] = add nsw i32 [[TMP19]], [[TMP28]]
 ; CHECK-NEXT:    [[TMP22:%.*]] = zext i32 [[ADD3]] to i64
-; CHECK-NEXT:    [[TMP23:%.*]] = call i64 @__instrumentor_post_numeric(i32 12, i32 4, i32 14, i64 [[TMP20]], i64 [[TMP24]], i64 [[TMP22]], i64 1, i32 -13) #[[ATTR0]]
+; CHECK-NEXT:    [[TMP23:%.*]] = call i64 @__instrumentor_post_numeric(i32 12, i32 -1, i32 4, i32 14, i64 [[TMP20]], i64 [[TMP24]], i64 [[TMP22]], i64 1, i32 -13) #[[ATTR0]]
 ; CHECK-NEXT:    [[ADD2:%.*]] = trunc i64 [[TMP23]] to i32
 ; CHECK-NEXT:    call void @__instrumentor_post_function(ptr @foo, ptr @__instrumentor_.str.5, i32 0, ptr null, i8 0, i32 -15) #[[ATTR0]]
 ; CHECK-NEXT:    ret i32 [[ADD2]]
diff --git a/llvm/test/Instrumentation/Instrumentor/numeric_subtypeid.ll b/llvm/test/Instrumentation/Instrumentor/numeric_subtypeid.ll
new file mode 100644
index 0000000000000..4f6b40f19c995
--- /dev/null
+++ b/llvm/test/Instrumentation/Instrumentor/numeric_subtypeid.ll
@@ -0,0 +1,39 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6
+; Test that the sub_type_id parameter is correctly passed to instrumentation for vector types
+; RUN: opt < %s -passes=instrumentor -instrumentor-read-config-files=%S/numeric_subtypeid_config.json -S | FileCheck %s
+
+define <4 x float> @test_vector_fadd(<4 x float> %a, <4 x float> %b) {
+; CHECK-LABEL: define <4 x float> @test_vector_fadd(
+; CHECK-SAME: <4 x float> [[A:%.*]], <4 x float> [[B:%.*]]) {
+; CHECK-NEXT:  [[ENTRY:.*:]]
+; CHECK-NEXT:    [[TMP0:%.*]] = alloca <4 x float>, align 16
+; CHECK-NEXT:    [[TMP1:%.*]] = alloca <4 x float>, align 16
+; CHECK-NEXT:    [[TMP2:%.*]] = alloca <4 x float>, align 16
+; CHECK-NEXT:    [[RES:%.*]] = fadd <4 x float> [[A]], [[B]]
+; CHECK-NEXT:    store <4 x float> [[A]], ptr [[TMP2]], align 16
+; CHECK-NEXT:    store <4 x float> [[B]], ptr [[TMP1]], align 16
+; CHECK-NEXT:    store <4 x float> [[RES]], ptr [[TMP0]], align 16
+; CHECK-NEXT:    call void @__instrumentor_post_numeric_ind(i32 18, i32 2, i32 16, i32 15, ptr [[TMP2]], ptr [[TMP1]], ptr [[TMP0]], i64 0, i32 -1) #[[ATTR0:[0-9]+]]
+; CHECK-NEXT:    ret <4 x float> [[RES]]
+;
+entry:
+  %res = fadd <4 x float> %a, %b
+  ret <4 x float> %res
+}
+
+define double @test_scalar_fadd(double %a, double %b) {
+; CHECK-LABEL: define double @test_scalar_fadd(
+; CHECK-SAME: double [[A:%.*]], double [[B:%.*]]) {
+; CHECK-NEXT:  [[ENTRY:.*:]]
+; CHECK-NEXT:    [[RES:%.*]] = fadd double [[A]], [[B]]
+; CHECK-NEXT:    [[TMP0:%.*]] = bitcast double [[A]] to i64
+; CHECK-NEXT:    [[TMP1:%.*]] = bitcast double [[B]] to i64
+; CHECK-NEXT:    [[TMP2:%.*]] = bitcast double [[RES]] to i64
+; CHECK-NEXT:    call void @__instrumentor_post_numeric(i32 3, i32 -1, i32 8, i32 15, i64 [[TMP0]], i64 [[TMP1]], i64 [[TMP2]], i64 0, i32 -2) #[[ATTR0]]
+; CHECK-NEXT:    ret double [[RES]]
+;
+entry:
+  %res = fadd double %a, %b
+  ret double %res
+}
+
diff --git a/llvm/test/Instrumentation/Instrumentor/numeric_subtypeid_config.json b/llvm/test/Instrumentation/Instrumentor/numeric_subtypeid_config.json
new file mode 100644
index 0000000000000..8f3ddc0e8cdd8
--- /dev/null
+++ b/llvm/test/Instrumentation/Instrumentor/numeric_subtypeid_config.json
@@ -0,0 +1,19 @@
+{
+  "configuration": {
+    "runtime_prefix": "__instrumentor_"
+  },
+  "instruction_post": {
+    "numeric": {
+      "enabled": true,
+      "type_id": true,
+      "sub_type_id": true,
+      "size": true,
+      "opcode": true,
+      "left": true,
+      "right": true,
+      "result": true,
+      "flags": true,
+      "id": true
+    }
+  }
+}
diff --git a/llvm/test/Instrumentation/Instrumentor/rt_config.json b/llvm/test/Instrumentation/Instrumentor/rt_config.json
index bcd6708cb5e15..42d0f0b047309 100644
--- a/llvm/test/Instrumentation/Instrumentor/rt_config.json
+++ b/llvm/test/Instrumentation/Instrumentor/rt_config.json
@@ -168,6 +168,8 @@
       "alignment.description": "The known access alignment.",
       "value_type_id": true,
       "value_type_id.description": "The type id of the loaded value.",
+      "value_sub_type_id": true,
+      "value_sub_type_id.description": "The sub type id of the loaded value (for arrays and vectors, or -1).",
       "atomicity_ordering": true,
       "atomicity_ordering.description": "The atomicity ordering of the load.",
       "sync_scope_id": true,
@@ -196,6 +198,8 @@
       "alignment.description": "The known access alignment.",
       "value_type_id": true,
       "value_type_id.description": "The type id of the stored value.",
+      "value_sub_type_id": true,
+      "value_sub_type_id.description": "The type id of the stored value (for arrays and vectors, or -1).",
       "atomicity_ordering": true,
       "atomicity_ordering.description": "The atomicity ordering of the store.",
       "sync_scope_id": true,
@@ -213,10 +217,14 @@
       "input.description": "Input value of the cast.",
       "input_type_id": true,
       "input_type_id.description": "The type id of the input value.",
+      "input_sub_type_id": true,
+      "input_sub_type_id.description": "The sub type id of the input value (for arrays and vectors, or -1).",
       "input_size": true,
       "input_size.description": "The size of the input value.",
       "result_type_id": true,
       "result_type_id.description": "The type id of the result value.",
+      "result_sub_type_id": true,
+      "result_sub_type_id.description": "The sub type id of the result value (for arrays and vectors, or -1).",
       "result_size": true,
       "result_size.description": "The size of the result value.",
       "opcode": true,
@@ -259,6 +267,8 @@
       "alignment.description": "The known access alignment.",
       "value_type_id": true,
       "value_type_id.description": "The type id of the loaded value.",
+      "value_sub_type_id": true,
+      "value_sub_type_id.description": "The sub type id of the loaded value (for arrays and vectors, or -1).",
       "atomicity_ordering": true,
       "atomicity_ordering.description": "The atomicity ordering of the load.",
       "sync_scope_id": true,
@@ -286,6 +296,8 @@
       "alignment.description": "The known access alignment.",
       "value_type_id": true,
       "value_type_id.description": "The type id of the stored value.",
+      "value_sub_type_id": true,
+      "value_sub_type_id.description": "The type id of the stored value (for arrays and vectors, or -1).",
       "atomicity_ordering": true,
       "atomicity_ordering.description": "The atomicity ordering of the store.",
       "sync_scope_id": true,
@@ -303,6 +315,8 @@
       "input.description": "Input value of the cast.",
       "input_type_id": true,
       "input_type_id.description": "The type id of the input value.",
+      "input_sub_type_id": true,
+      "input_sub_type_id.description": "The sub type id of the input value (for arrays and vectors, or -1).",
       "input_size": true,
       "input_size.description": "The size of the input value.",
       "result": true,
@@ -310,6 +324,8 @@
       "result.description": "Result of the cast.",
       "result_type_id": true,
       "result_type_id.description": "The type id of the result value.",
+      "result_sub_type_id": true,
+      "result_sub_type_id.description": "The sub type id of the result value (for arrays and vectors, or -1).",
       "result_size": true,
       "result_size.description": "The size of the result value.",
       "opcode": true,



More information about the llvm-commits mailing list