[clang] [llvm] [mlir] [IR] Introduce `threadid` memory location (PR #241334)

via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 23 14:01:56 PST 2026


https://github.com/oigolovanova updated https://github.com/llvm/llvm-project/pull/241334

>From 9926199a8af88289c68bd9cee7dfe04e2395f51d Mon Sep 17 00:00:00 2001
From: oigolovanova <oigolovanova at yandex-team.com>
Date: Wed, 11 Nov 2026 19:37:24 +0000
Subject: [PATCH 1/2] [ModRef] Add ThreadIdMem memory location

---
 .../CodeGen/sanitize-metadata-nosanitize.c    |  18 ++--
 clang/test/CodeGenCXX/threadlocal_address.cpp |   2 +-
 clang/test/CodeGenOpenCL/convergent.cl        |   2 +-
 llvm/docs/LangRef.md                          |  11 ++-
 llvm/include/llvm/AsmParser/LLToken.h         |   1 +
 llvm/include/llvm/IR/RuntimeLibcallsImpl.td   |   1 +
 llvm/include/llvm/Support/ModRef.h            |  16 ++-
 llvm/lib/AsmParser/LLLexer.cpp                |   1 +
 llvm/lib/AsmParser/LLParser.cpp               |   2 +
 llvm/lib/Bitcode/Reader/BitcodeReader.cpp     |  91 ++++++++++--------
 llvm/lib/Bitcode/Writer/BitcodeWriter.cpp     |   2 +-
 llvm/lib/IR/Attributes.cpp                    |   3 +
 llvm/lib/Support/ModRef.cpp                   |   3 +
 .../test/Assembler/memory-attribute-errors.ll |   4 +
 llvm/test/Assembler/memory-attribute.ll       |  36 +++++++
 .../Inputs/memory-attribute-upgrade-v2.bc     | Bin 0 -> 2684 bytes
 .../Bitcode/memory-attribute-upgrade-v2.ll    |  52 ++++++++++
 .../TableGen/target-mem-intrinsic-attrs.td    |  38 ++++----
 .../Transforms/FunctionAttrs/argmemonly.ll    |  22 ++---
 .../Transforms/FunctionAttrs/nocapture.ll     |  36 +++----
 .../FunctionAttrs/read-write-scc.ll           |   4 +-
 .../Transforms/FunctionAttrs/readattrs.ll     |   2 +-
 .../Transforms/FunctionAttrs/writeonly.ll     |   4 +-
 .../GlobalOpt/disable-globals-aa.ll           |   8 +-
 .../InferFunctionAttrs/norecurse_debug.ll     |   2 +-
 .../cfi-nounwind-direct-call.ll               |   2 +-
 .../Transforms/SCCP/ipscp-drop-argmemonly.ll  |  10 +-
 llvm/unittests/Support/ModRefTest.cpp         |  21 +++-
 .../TableGen/Basic/RuntimeLibcallsEmitter.cpp |   1 +
 .../LLVMIR/LLVMToLLVMIRTranslation.cpp        |   2 +
 mlir/lib/Target/LLVMIR/ModuleImport.cpp       |   6 +-
 mlir/lib/Target/LLVMIR/ModuleTranslation.cpp  |   3 +
 .../LLVMIR/Import/function-attributes.ll      |  17 ++++
 .../test/Target/LLVMIR/Import/instructions.ll |   5 +
 34 files changed, 306 insertions(+), 122 deletions(-)
 create mode 100644 llvm/test/Bitcode/Inputs/memory-attribute-upgrade-v2.bc
 create mode 100644 llvm/test/Bitcode/memory-attribute-upgrade-v2.ll

diff --git a/clang/test/CodeGen/sanitize-metadata-nosanitize.c b/clang/test/CodeGen/sanitize-metadata-nosanitize.c
index bc071e6e541a59..6740a0d707fc58 100644
--- a/clang/test/CodeGen/sanitize-metadata-nosanitize.c
+++ b/clang/test/CodeGen/sanitize-metadata-nosanitize.c
@@ -10,7 +10,7 @@
 // CHECK: @llvm.global_ctors = appending global [2 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 2, ptr @__sanitizer_metadata_covered2.module_ctor, ptr @__sanitizer_metadata_covered2.module_ctor }, { i32, ptr, ptr } { i32 2, ptr @__sanitizer_metadata_atomics2.module_ctor, ptr @__sanitizer_metadata_atomics2.module_ctor }]
 // CHECK: @llvm.global_dtors = appending global [2 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 2, ptr @__sanitizer_metadata_covered2.module_dtor, ptr @__sanitizer_metadata_covered2.module_dtor }, { i32, ptr, ptr } { i32 2, ptr @__sanitizer_metadata_atomics2.module_dtor, ptr @__sanitizer_metadata_atomics2.module_dtor }]
 //.
-// CHECK: Function Attrs: mustprogress nofree noinline norecurse nosync nounwind willreturn memory(write, argmem: none, inaccessiblemem: none, target_mem: none)
+// CHECK: Function Attrs: mustprogress nofree noinline norecurse nosync nounwind willreturn memory(write, argmem: none, inaccessiblemem: none, threadid: none, target_mem: none)
 // CHECK-LABEL: define dso_local void @escape(
 // CHECK-SAME: ptr noundef [[P:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] !pcsections [[META6:![0-9]+]] {
 // CHECK-NEXT:  [[ENTRY:.*:]]
@@ -21,7 +21,7 @@ __attribute__((noinline, not_tail_called)) void escape(const volatile void *p) {
   sink = p;
 }
 
-// CHECK: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(write, argmem: readwrite, inaccessiblemem: none, target_mem: none)
+// CHECK: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(write, argmem: readwrite, inaccessiblemem: none, threadid: none, target_mem: none)
 // CHECK-LABEL: define dso_local i32 @normal_function(
 // CHECK-SAME: ptr noundef [[X:%.*]], ptr nofree noundef readonly captures(none) [[Y:%.*]]) local_unnamed_addr #[[ATTR1:[0-9]+]] !pcsections [[META8:![0-9]+]] {
 // CHECK-NEXT:  [[ENTRY:.*:]]
@@ -38,7 +38,7 @@ int normal_function(int *x, int *y) {
   return *y;
 }
 
-// CHECK: Function Attrs: disable_sanitizer_instrumentation mustprogress nofree norecurse nosync nounwind willreturn memory(write, argmem: readwrite, inaccessiblemem: none, target_mem: none)
+// CHECK: Function Attrs: disable_sanitizer_instrumentation mustprogress nofree norecurse nosync nounwind willreturn memory(write, argmem: readwrite, inaccessiblemem: none, threadid: none, target_mem: none)
 // CHECK-LABEL: define dso_local i32 @test_disable_sanitize_instrumentation(
 // CHECK-SAME: ptr noundef [[X:%.*]], ptr nofree noundef readonly captures(none) [[Y:%.*]]) local_unnamed_addr #[[ATTR2:[0-9]+]] {
 // CHECK-NEXT:  [[ENTRY:.*:]]
@@ -55,7 +55,7 @@ __attribute__((disable_sanitizer_instrumentation)) int test_disable_sanitize_ins
   return *y;
 }
 
-// CHECK: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(write, argmem: readwrite, inaccessiblemem: none, target_mem: none)
+// CHECK: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(write, argmem: readwrite, inaccessiblemem: none, threadid: none, target_mem: none)
 // CHECK-LABEL: define dso_local i32 @test_no_sanitize_thread(
 // CHECK-SAME: ptr noundef [[X:%.*]], ptr nofree noundef readonly captures(none) [[Y:%.*]]) local_unnamed_addr #[[ATTR3:[0-9]+]] !pcsections [[META15:![0-9]+]] {
 // CHECK-NEXT:  [[ENTRY:.*:]]
@@ -72,7 +72,7 @@ __attribute__((no_sanitize("thread"))) int test_no_sanitize_thread(int *x, int *
   return *y;
 }
 
-// CHECK: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(write, argmem: readwrite, inaccessiblemem: none, target_mem: none)
+// CHECK: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(write, argmem: readwrite, inaccessiblemem: none, threadid: none, target_mem: none)
 // CHECK-LABEL: define dso_local i32 @test_no_sanitize_all(
 // CHECK-SAME: ptr noundef [[X:%.*]], ptr nofree noundef readonly captures(none) [[Y:%.*]]) local_unnamed_addr #[[ATTR3]] !pcsections [[META15]] {
 // CHECK-NEXT:  [[ENTRY:.*:]]
@@ -89,10 +89,10 @@ __attribute__((no_sanitize("all"))) int test_no_sanitize_all(int *x, int *y) {
   return *y;
 }
 //.
-// CHECK: attributes #[[ATTR0]] = { mustprogress nofree noinline norecurse nosync nounwind willreturn memory(write, argmem: none, inaccessiblemem: none, target_mem: none) "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+cx8,+mmx,+sse,+sse2,+x87" }
-// CHECK: attributes #[[ATTR1]] = { mustprogress nofree norecurse nosync nounwind willreturn memory(write, argmem: readwrite, inaccessiblemem: none, target_mem: none) "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+cx8,+mmx,+sse,+sse2,+x87" }
-// CHECK: attributes #[[ATTR2]] = { disable_sanitizer_instrumentation mustprogress nofree norecurse nosync nounwind willreturn memory(write, argmem: readwrite, inaccessiblemem: none, target_mem: none) "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+cx8,+mmx,+sse,+sse2,+x87" }
-// CHECK: attributes #[[ATTR3]] = { mustprogress nofree norecurse nosync nounwind willreturn memory(write, argmem: readwrite, inaccessiblemem: none, target_mem: none) "min-legal-vector-width"="0" "no-trapping-math"="true" "no_sanitize_thread" "stack-protector-buffer-size"="8" "target-features"="+cx8,+mmx,+sse,+sse2,+x87" }
+// CHECK: attributes #[[ATTR0]] = { mustprogress nofree noinline norecurse nosync nounwind willreturn memory(write, argmem: none, inaccessiblemem: none, threadid: none, target_mem: none) "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+cx8,+mmx,+sse,+sse2,+x87" }
+// CHECK: attributes #[[ATTR1]] = { mustprogress nofree norecurse nosync nounwind willreturn memory(write, argmem: readwrite, inaccessiblemem: none, threadid: none, target_mem: none) "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+cx8,+mmx,+sse,+sse2,+x87" }
+// CHECK: attributes #[[ATTR2]] = { disable_sanitizer_instrumentation mustprogress nofree norecurse nosync nounwind willreturn memory(write, argmem: readwrite, inaccessiblemem: none, threadid: none, target_mem: none) "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+cx8,+mmx,+sse,+sse2,+x87" }
+// CHECK: attributes #[[ATTR3]] = { mustprogress nofree norecurse nosync nounwind willreturn memory(write, argmem: readwrite, inaccessiblemem: none, threadid: none, target_mem: none) "min-legal-vector-width"="0" "no-trapping-math"="true" "no_sanitize_thread" "stack-protector-buffer-size"="8" "target-features"="+cx8,+mmx,+sse,+sse2,+x87" }
 // CHECK: attributes #[[ATTR4:[0-9]+]] = { nounwind "target-features"="+cx8,+mmx,+sse,+sse2,+x87" }
 //.
 // CHECK: [[META0:![0-9]+]] = !{!"{{.*}}clang version {{.*}}"}
diff --git a/clang/test/CodeGenCXX/threadlocal_address.cpp b/clang/test/CodeGenCXX/threadlocal_address.cpp
index 445a75538a64ea..cf05479929a7c6 100644
--- a/clang/test/CodeGenCXX/threadlocal_address.cpp
+++ b/clang/test/CodeGenCXX/threadlocal_address.cpp
@@ -135,7 +135,7 @@ int h() {
 // NON-ZERO-GLOBAL-AS: attributes #[[ATTR3:[0-9]+]] = { convergent noinline nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
 // NON-ZERO-GLOBAL-AS: attributes #[[ATTR4]] = { convergent }
 //.
-// CHECK-O1: attributes #[[ATTR0]] = { mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, argmem: none, inaccessiblemem: none, target_mem: none) "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
+// CHECK-O1: attributes #[[ATTR0]] = { mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, argmem: none, inaccessiblemem: none, threadid: none, target_mem: none) "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
 // CHECK-O1: attributes #[[ATTR1:[0-9]+]] = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
 // CHECK-O1: attributes #[[ATTR2]] = { mustprogress nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
 // CHECK-O1: attributes #[[ATTR3:[0-9]+]] = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
diff --git a/clang/test/CodeGenOpenCL/convergent.cl b/clang/test/CodeGenOpenCL/convergent.cl
index 5217b3acd081ed..842b51b4ea5592 100644
--- a/clang/test/CodeGenOpenCL/convergent.cl
+++ b/clang/test/CodeGenOpenCL/convergent.cl
@@ -133,7 +133,7 @@ kernel void assume_convergent_asm()
   __asm__ volatile("s_barrier");
 }
 
-// CHECK: attributes #0 = { nofree noinline norecurse nosync nounwind memory(readwrite, target_mem: none)
+// CHECK: attributes #0 = { nofree noinline norecurse nosync nounwind memory(readwrite, threadid: none, target_mem: none)
 // CHECK: attributes #1 = { convergent norecurse nounwind{{[^}]*}} }
 // CHECK: attributes #2 = { convergent nounwind{{[^}]*}} }
 // CHECK: attributes #3 = { convergent noduplicate nounwind{{[^}]*}} }
diff --git a/llvm/docs/LangRef.md b/llvm/docs/LangRef.md
index e69ab5871e3c20..5a7876beec12b3 100644
--- a/llvm/docs/LangRef.md
+++ b/llvm/docs/LangRef.md
@@ -2310,7 +2310,7 @@ define void @f() "no-sse" { ... }
 :   This attribute specifies the possible memory effects of the call-site or
     function. It allows specifying the possible access kinds (`none`,
     `read`, `write`, or `readwrite`) for the possible memory location
-    kinds (`argmem`, `inaccessiblemem`, `errnomem`, `target_mem0`,
+    kinds (`argmem`, `inaccessiblemem`, `errnomem`, `threadid`, `target_mem0`,
     `target_mem1`, as well as a default).
     It is best understood by example:
 
@@ -2323,6 +2323,8 @@ define void @f() "no-sse" { ... }
       memory and only write inaccessible memory.
     - `memory(argmem: read, errnomem: write)`: May only read argument memory
       and only write errno.
+    - `memory(threadid: read)`: Does not access any memory, but the effects
+      of the call may depend on the thread it is executed on.
     - `memory(read, argmem: readwrite)`: May read any memory (default mode)
       and additionally write argument memory.
     - `memory(readwrite, argmem: none)`: May access any memory apart from
@@ -2353,6 +2355,13 @@ define void @f() "no-sse" { ... }
       accessing inaccessible memory itself). Inaccessible memory is often used
       to model control dependencies of intrinsics.
     - `errnomem`: This refers to accesses to the `errno` variable.
+    - `threadid`: This refers to the identity of the thread executing the
+      function. It is not memory that can be accessed through a pointer.
+      Reading it means that the result of the function may depend on the
+      executing thread, for example the address of a thread-local variable.
+      Writing it means that the function may return on a different thread than
+      the one it was called on, for example because a coroutine was suspended
+      and resumed on another thread.
     - `target_mem#` : These refer to target specific state that cannot be
       accessed by any other means. # is a number between 0 and 1 inclusive.
       Note: The following target_mem locations are implemented in AArch64.
diff --git a/llvm/include/llvm/AsmParser/LLToken.h b/llvm/include/llvm/AsmParser/LLToken.h
index 78e20282c84593..c428ddc83cb9b3 100644
--- a/llvm/include/llvm/AsmParser/LLToken.h
+++ b/llvm/include/llvm/AsmParser/LLToken.h
@@ -213,6 +213,7 @@ enum Kind {
   kw_target_mem0,
   kw_target_mem1,
   kw_errnomem,
+  kw_threadid,
 
   // Legacy attributes:
   kw_argmemonly,
diff --git a/llvm/include/llvm/IR/RuntimeLibcallsImpl.td b/llvm/include/llvm/IR/RuntimeLibcallsImpl.td
index 03346b17fece47..8d808a70aa611b 100644
--- a/llvm/include/llvm/IR/RuntimeLibcallsImpl.td
+++ b/llvm/include/llvm/IR/RuntimeLibcallsImpl.td
@@ -153,6 +153,7 @@ class MemoryEffects<ModRefInfo mr = ModRef> {
   ModRefInfo InaccessibleMem = mr;
   ModRefInfo ErrnoMem = mr;
   ModRefInfo Other = mr;
+  ModRefInfo ThreadIdMem = mr;
   ModRefInfo TargetMem0 = mr;
   ModRefInfo TargetMem1 = mr;
 }
diff --git a/llvm/include/llvm/Support/ModRef.h b/llvm/include/llvm/Support/ModRef.h
index 83091c617f6290..df23f9ac49b75e 100644
--- a/llvm/include/llvm/Support/ModRef.h
+++ b/llvm/include/llvm/Support/ModRef.h
@@ -66,9 +66,14 @@ enum class IRMemLocation {
   ErrnoMem = 2,
   /// Any other memory.
   Other = 3,
-  /// Represents target specific state.
-  TargetMem0 = 4,
-  TargetMem1 = 5,
+  /// The identity of the executing thread. Reading it means that the result
+  /// may depend on the current thread (e.g. the address of a thread-local
+  /// variable). Writing it means that execution may continue on a different
+  /// thread.
+  ThreadIdMem = 4,
+  /// Represents target specific state. These must be the last locations.
+  TargetMem0 = 5,
+  TargetMem1 = 6,
 
   /// Helpers to iterate all locations in the MemoryEffectsBase class.
   First = ArgMem,
@@ -160,6 +165,11 @@ template <typename LocationEnum> class MemoryEffectsBase {
     return MemoryEffectsBase(Location::Other, MR);
   }
 
+  /// Create MemoryEffectsBase that can only access the thread identity.
+  static MemoryEffectsBase threadIdMemOnly(ModRefInfo MR = ModRefInfo::ModRef) {
+    return MemoryEffectsBase(Location::ThreadIdMem, MR);
+  }
+
   /// Create MemoryEffectsBase that can only access inaccessible or argument
   /// memory.
   static MemoryEffectsBase
diff --git a/llvm/lib/AsmParser/LLLexer.cpp b/llvm/lib/AsmParser/LLLexer.cpp
index 36fcb4a7df7f25..102b94eafd3466 100644
--- a/llvm/lib/AsmParser/LLLexer.cpp
+++ b/llvm/lib/AsmParser/LLLexer.cpp
@@ -728,6 +728,7 @@ lltok::Kind LLLexer::LexIdentifier() {
   KEYWORD(target_mem);
   KEYWORD(inaccessiblemem);
   KEYWORD(errnomem);
+  KEYWORD(threadid);
   KEYWORD(argmemonly);
   KEYWORD(inaccessiblememonly);
   KEYWORD(inaccessiblemem_or_argmemonly);
diff --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp
index 6be0e010a235c5..08a29664672c38 100644
--- a/llvm/lib/AsmParser/LLParser.cpp
+++ b/llvm/lib/AsmParser/LLParser.cpp
@@ -2749,6 +2749,8 @@ static SmallVector<MemoryEffects::Location, 2> keywordToLoc(lltok::Kind Tok) {
     return {Loc::InaccessibleMem};
   case lltok::kw_errnomem:
     return {Loc::ErrnoMem};
+  case lltok::kw_threadid:
+    return {Loc::ThreadIdMem};
   case lltok::kw_target_mem0:
     return {Loc::TargetMem0};
   case lltok::kw_target_mem1:
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
index f427837bdfa5c2..76edc740a3bef4 100644
--- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -2378,6 +2378,54 @@ Error BitcodeReader::parseAttrKind(uint64_t Code, Attribute::AttrKind *Kind) {
   return Error::success();
 }
 
+/// Decode the value of a memory attribute. The top byte holds the version of
+/// the encoding, the remaining bits hold two bits per memory location. Older
+/// versions used a different set of locations and are upgraded here.
+static MemoryEffects decodeMemoryEffects(uint64_t EncodedME, const Triple &TT) {
+  const uint8_t Version = EncodedME >> 56;
+  if (Version >= 3)
+    return MemoryEffects::createFromIntValue(EncodedME & 0x00FFFFFFFFFFFFFFULL);
+
+  auto GetModRef = [EncodedME](unsigned Pos) {
+    return ModRefInfo((EncodedME >> (2 * Pos)) & 3);
+  };
+  ModRefInfo ArgMR = GetModRef(0);
+  ModRefInfo InaccessibleMR = GetModRef(1);
+  ModRefInfo ErrnoMR, OtherMR, TargetMem0MR, TargetMem1MR;
+  if (Version == 0) {
+    // Version 0 had no errno location: it was part of other memory.
+    OtherMR = GetModRef(2);
+    ErrnoMR = OtherMR;
+    TargetMem0MR = ModRefInfo::NoModRef;
+    TargetMem1MR = ModRefInfo::NoModRef;
+  } else {
+    // Versions 1 and 2 placed the target memory locations right after other
+    // memory. Some version 1 bitcode already has them.
+    ErrnoMR = GetModRef(2);
+    OtherMR = GetModRef(3);
+    TargetMem0MR = GetModRef(4);
+    TargetMem1MR = GetModRef(5);
+  }
+
+  // Before version 2, AArch64 state was encoded as inaccessible memory.
+  // Upgrade those effects to target-specific memory locations.
+  if (Version < 2 && TT.isAArch64()) {
+    TargetMem0MR |= InaccessibleMR;
+    TargetMem1MR |= InaccessibleMR;
+  }
+
+  // Before version 3, the thread identity was part of other memory.
+  ModRefInfo ThreadIdMR = OtherMR;
+
+  return MemoryEffects::argMemOnly(ArgMR) |
+         MemoryEffects::inaccessibleMemOnly(InaccessibleMR) |
+         MemoryEffects::errnoMemOnly(ErrnoMR) |
+         MemoryEffects::otherMemOnly(OtherMR) |
+         MemoryEffects::threadIdMemOnly(ThreadIdMR) |
+         MemoryEffects(IRMemLocation::TargetMem0, TargetMem0MR) |
+         MemoryEffects(IRMemLocation::TargetMem1, TargetMem1MR);
+}
+
 static bool upgradeOldMemoryAttribute(MemoryEffects &ME, uint64_t EncodedKind) {
   switch (EncodedKind) {
   case bitc::ATTR_KIND_READ_NONE:
@@ -2505,45 +2553,10 @@ Error BitcodeReader::parseAttributeGroupBlock() {
             B.addUWTableAttr(UWTableKind(Record[++i]));
           else if (Kind == Attribute::AllocKind)
             B.addAllocKindAttr(static_cast<AllocFnKind>(Record[++i]));
-          else if (Kind == Attribute::Memory) {
-            uint64_t EncodedME = Record[++i];
-            const uint8_t Version = (EncodedME >> 56);
-            if (Version == 0) {
-              // Errno memory location was previously encompassed into default
-              // memory. Ensure this is taken into account while reconstructing
-              // the memory attribute prior to its introduction.
-              ModRefInfo ArgMem = ModRefInfo((EncodedME >> 0) & 3);
-              ModRefInfo InaccessibleMem = ModRefInfo((EncodedME >> 2) & 3);
-              ModRefInfo OtherMem = ModRefInfo((EncodedME >> 4) & 3);
-              auto ME = MemoryEffects::inaccessibleMemOnly(InaccessibleMem) |
-                        MemoryEffects::argMemOnly(ArgMem) |
-                        MemoryEffects::errnoMemOnly(OtherMem) |
-                        MemoryEffects::otherMemOnly(OtherMem);
-              // Old bitcode encoded AArch64 state as inaccessible memory.
-              // Upgrade those effects to target-specific memory locations.
-              if (getTargetTriple().isAArch64())
-                ME = ME.getWithModRef(IRMemLocation::TargetMem0,
-                                      InaccessibleMem) |
-                     ME.getWithModRef(IRMemLocation::TargetMem1,
-                                      InaccessibleMem);
-              B.addMemoryAttr(ME);
-            } else {
-              // Construct the memory attribute directly from the encoded base
-              // on newer versions.
-              auto ME = MemoryEffects::createFromIntValue(
-                  EncodedME & 0x00FFFFFFFFFFFFFFULL);
-              // Upgrade to target-specific memory locations introduced in
-              // version 2.
-              if (Version == 1 && getTargetTriple().isAArch64())
-                ME = ME.getWithModRef(
-                         IRMemLocation::TargetMem0,
-                         ME.getModRef(IRMemLocation::InaccessibleMem)) |
-                     ME.getWithModRef(
-                         IRMemLocation::TargetMem1,
-                         ME.getModRef(IRMemLocation::InaccessibleMem));
-              B.addMemoryAttr(ME);
-            }
-          } else if (Kind == Attribute::Captures)
+          else if (Kind == Attribute::Memory)
+            B.addMemoryAttr(
+                decodeMemoryEffects(Record[++i], getTargetTriple()));
+          else if (Kind == Attribute::Captures)
             B.addCapturesAttr(CaptureInfo::createFromIntValue(Record[++i]));
           else if (Kind == Attribute::NoFPClass)
             B.addNoFPClassAttr(
diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
index 26e411a587c267..ec8894adac695b 100644
--- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -1104,7 +1104,7 @@ void ModuleBitcodeWriter::writeAttributeGroupTable() {
         Record.push_back(getAttrKindEncoding(Kind));
         if (Kind == Attribute::Memory) {
           // Version field for upgrading old memory effects.
-          const uint64_t Version = 2;
+          const uint64_t Version = 3;
           Record.push_back((Version << 56) | Attr.getValueAsInt());
         } else {
           Record.push_back(Attr.getValueAsInt());
diff --git a/llvm/lib/IR/Attributes.cpp b/llvm/lib/IR/Attributes.cpp
index ce86c38b44c0e1..6173469e09cc7b 100644
--- a/llvm/lib/IR/Attributes.cpp
+++ b/llvm/lib/IR/Attributes.cpp
@@ -671,6 +671,9 @@ std::string Attribute::getAsString(bool InAttrGrp) const {
         break;
       case IRMemLocation::Other:
         llvm_unreachable("This is represented as the default access kind");
+      case IRMemLocation::ThreadIdMem:
+        OS << "threadid: ";
+        break;
       case IRMemLocation::TargetMem0:
         OS << "target_mem0: ";
         break;
diff --git a/llvm/lib/Support/ModRef.cpp b/llvm/lib/Support/ModRef.cpp
index 1083c72902c0b7..8a402adaa014f3 100644
--- a/llvm/lib/Support/ModRef.cpp
+++ b/llvm/lib/Support/ModRef.cpp
@@ -49,6 +49,9 @@ raw_ostream &llvm::operator<<(raw_ostream &OS, MemoryEffects ME) {
     case IRMemLocation::Other:
       OS << "Other: ";
       break;
+    case IRMemLocation::ThreadIdMem:
+      OS << "ThreadIdMem: ";
+      break;
     case IRMemLocation::TargetMem0:
       OS << "TargetMem0: ";
       break;
diff --git a/llvm/test/Assembler/memory-attribute-errors.ll b/llvm/test/Assembler/memory-attribute-errors.ll
index cf8690e07678ec..046ac62b4e9c09 100644
--- a/llvm/test/Assembler/memory-attribute-errors.ll
+++ b/llvm/test/Assembler/memory-attribute-errors.ll
@@ -5,6 +5,7 @@
 ; RUN: not llvm-as < %t/invalid-kind.ll 2>&1 | FileCheck %s --check-prefix=INVALID-KIND
 ; RUN: not llvm-as < %t/other.ll 2>&1 | FileCheck %s --check-prefix=OTHER
 ; RUN: not llvm-as < %t/missing-colon.ll 2>&1 | FileCheck %s --check-prefix=MISSING-COLON
+; RUN: not llvm-as < %t/threadid-missing-colon.ll 2>&1 | FileCheck %s --check-prefix=THREADID-MISSING-COLON
 ; RUN: not llvm-as < %t/invalid-access-kind.ll 2>&1 | FileCheck %s --check-prefix=INVALID-ACCESS-KIND
 ; RUN: not llvm-as < %t/default-after-loc.ll 2>&1 | FileCheck %s --check-prefix=DEFAULT-AFTER-LOC
 ; RUN: not llvm-as < %t/default-after-target-loc.ll 2>&1 | FileCheck %s --check-prefix=DEFAULT-AFTER-TARGET-LOC
@@ -27,6 +28,9 @@ declare void @fn() memory(other: read)
 ;--- missing-colon.ll
 ; MISSING-COLON: error: expected ':' after location
 declare void @fn() memory(argmem)
+;--- threadid-missing-colon.ll
+; THREADID-MISSING-COLON: error: expected ':' after location
+declare void @fn() memory(threadid)
 ;--- invalid-access-kind.ll
 ; INVALID-ACCESS-KIND: error: expected access kind (none, read, write, readwrite)
 declare void @fn() memory(argmem: foo)
diff --git a/llvm/test/Assembler/memory-attribute.ll b/llvm/test/Assembler/memory-attribute.ll
index fd98384d90405b..415c75d4f01a96 100644
--- a/llvm/test/Assembler/memory-attribute.ll
+++ b/llvm/test/Assembler/memory-attribute.ll
@@ -52,6 +52,42 @@ declare void @fn_errnomem_write() memory(errnomem: write)
 ; CHECK: @fn_errnomem_readwrite()
 declare void @fn_errnomem_readwrite() memory(errnomem: readwrite)
 
+; CHECK: Function Attrs: memory(threadid: read)
+; CHECK: @fn_threadid_read()
+declare void @fn_threadid_read() memory(threadid: read)
+
+; CHECK: Function Attrs: memory(threadid: write)
+; CHECK: @fn_threadid_write()
+declare void @fn_threadid_write() memory(threadid: write)
+
+; CHECK: Function Attrs: memory(threadid: readwrite)
+; CHECK: @fn_threadid_readwrite()
+declare void @fn_threadid_readwrite() memory(threadid: readwrite)
+
+; The default access kind applies to threadid as well.
+; CHECK: Function Attrs: memory(read)
+; CHECK: @fn_read_threadid_read()
+declare void @fn_read_threadid_read() memory(read, threadid: read)
+
+; CHECK: Function Attrs: memory(readwrite, threadid: read)
+; CHECK: @fn_readwrite_threadid_read()
+declare void @fn_readwrite_threadid_read() memory(readwrite, threadid: read)
+
+; CHECK: Function Attrs: memory(read, inaccessiblemem: none, threadid: none)
+; CHECK: @fn_read_inaccessiblemem_none_threadid_none()
+declare void @fn_read_inaccessiblemem_none_threadid_none()
+    memory(read, threadid: none, inaccessiblemem: none)
+
+; CHECK: Function Attrs: memory(argmem: read, threadid: write, target_mem: read)
+; CHECK: @fn_argmem_read_threadid_write_target_mem_read()
+declare void @fn_argmem_read_threadid_write_target_mem_read()
+    memory(target_mem: read, threadid: write, argmem: read)
+
+; CHECK: Function Attrs: memory(write, threadid: read, target_mem0: none)
+; CHECK: @fn_write_threadid_read_target_mem0_none()
+declare void @fn_write_threadid_read_target_mem0_none()
+    memory(write, threadid: read, target_mem0: none)
+
 ; CHECK: Function Attrs: memory(read, argmem: readwrite)
 ; CHECK: @fn_read_argmem_readwrite()
 declare void @fn_read_argmem_readwrite() memory(read, argmem: readwrite)
diff --git a/llvm/test/Bitcode/Inputs/memory-attribute-upgrade-v2.bc b/llvm/test/Bitcode/Inputs/memory-attribute-upgrade-v2.bc
new file mode 100644
index 0000000000000000000000000000000000000000..655a1367f524ad06510bd570da84ad0d3ca2e046
GIT binary patch
literal 2684
zcmb_ee at q+q6+i#L=LF|#C#8uU?p!<2$lBs?oPnG%-fY}5N1>~eWfEDt!5Kr$LL6fZ
z23mDCrd*nNsk5?(HJxPEXv?N_B57248fq{{nM16MqIN=S6xjjtqa}eQEK0Yi-8++Q
z-5>jJU!A|_ at B6;@zVFB9z3<gJ#;;WtVORl%VQvLg`rLu{fAy1pTzI}XUHXiOF2M8(
z4674kSfN;t!3*0CKRi-$!k(7ymZ at m-PelWYrwim7t@Ow4u;N*9?Xi-9(k%mNoyXu;
zQ74N$9 at UAaOSOZFjq8pxo&o3e_{MF{ePM-0e^Ts8%Qu#qZFPgH%OaW{aMJr-`*m+8
zZFPZ&LPHNKPkx>Ds5QG0?U`%{#Pub0 at uyW}bufMOcwGO?U`$F^)PF0j+UBSeYqom8
zuGe%JwhrFgTBWM<wf&b=`(TQ9Ot_ru*KK!971Yw(<?^i}gIy-Z_Np<A1m5Cf*)L&m
z<C|?oQo9PC(yF2ffuxKWKl-h_Uk8t~-7qMSo)W*H`;)*Uwa4dNDuMJ(>3h^K^=oYB
zMhss7=|}Q*(V8l$-R)o>32dsli7#IlRLT3L*lsvmi1!oyO|`mu`QSQHx!$l{DgzSs
z#Cg9Q?^WZ$QAxEo+UMuG{9GuBhrE(*CmuS3zwC{6`nkRtIU8`IvcBRkw!X`E1%ChJ
z<;5So^Vd@^c7O5$`#DqpZLX0$H(Yo8<0j*~!?HskrmGI at Ax`DKx2QQ#SMtW8=AWN^
z at aF4_?BCTJly5W!FN_h}e|^dLhqFKH=06K=IrYwo3F$GhV at F~WhRFq^^5bim+Wp;A
z7#4oK#xR#?TvdpQL|9n#FIqwz)}Pc4MPU7Jn!xtimQBDW04P5Mw$0THtn*F_G+P0-
zsaU$c7!o+?#;{TlH_5}qWR7Sp5?PNrm;pXk8^(Kk at Xp~5#SKh(M}=0y$fT&%PNc{y
zBSb4zkY|e)XC&6N!y1!VGd;1OAAbn~>g4=>yw5M`?&178PLtV)mf|Q!DSec3eg&<#
zkV!R3UegnEdUAr*wo<QI#-f%Phxvk}W-MAWAhBdtin^Qdm%R8cFBgD0%=zP-zX|U)
z;N1 at kKy4_@HOjdTH5VA>dWR!B?yjJ_S at gGYv_whV=@DXKgvjLQt1L0CCnh80G%Nda
z++j{T%)|LP$umO^=BUIn#FxRLkNPbiNi3th;*V{dzkv(*qd_m;)5HbUTrk0Du6##%
z7gOGIp at le_w<&Wvv;<!04CK|6cEYZm)e~1E+N)V&AxC~H(zdGiGNX>_x1yGetMsuW
zO<br4?-|}(zZzEx5zzinJIxZe^yIY^`HDy at 7_28(SlRwpqfCakj5 at 3kkVg|W3l7Us
zSn{zC)`O>92<(yLeFi)*9C>kGg_g$Aq6^)pN>a0S?LuzLT#md31~@gA(Wv!8w0MAL
zVh(eLuSurNX&!v6$v7``$Z at c$0|MB<X+D`kOHIl<S=owCxkxD&b;<`W<Wr$}3c>Pz
zR(3m!7F_5dRdRiaB_<-|TyD#fp1h$aC-o#`@Rt6mR^2ZwV-9OlVjhZ`GYw;qeQ>r9
z>~wM=Kc~5T6D?E9To&E7DQ_p>6ka6hJcENTjl%#HA;Q5KNM&TeZqD)$IxA!<W1CEn
z(<5ZouDzBbT1%TLloRr+1SN}<Lm%x@<DE{fF~PkY2HA5%qM8_AGsH79j%t8Y1|p_#
z>YuD-wP5O%6uB=_)LMU#Ld!bka#ptNQmzWB&|+40L#NEmfU|GgqTOD+SI%knZB6nP
zz~N~JlYtmY%<*VVMp6U89O4yq8>RrdfT$7Tm5BD92=X|1UIqvRJ&=oK9r~0iVWSY_
zo&?ty7a*#s2PKe1ON=j@;Vow!<|H4R+As^=MaWr}m<90IwA0|G;Yb!OH=z{@EvX=_
zN|TyV=aK)g0OHxpZ~;K$^Tg>WAf!482oYDG=4(J_+VPD{av?#?rHEJ9|AtnM%t9?h
zw6i0`4YsZvzv&VjH)*TaiVO5Z2Q+YvHV*2yZ}`N=5hibHb<%E4I;w{S<(AVD>q4}6
zJPH+RJ}p#@;sdl6hbwmNgh)HX4tC*pTxeB=7NA$C&_%!!g;wKeIg2iiA^}BIl#luo
zT*wP$h3|55&|5<gAHO7E5CGHb6+DHK59zo7_8aKi2cT6I9`i#PGI*%L7K1{Nn0NI2
zj{;9UivYcgP5C*C=3Qv5PA{&Ydn<)^T}mjH!kC~6&N6TXoX~cX4(q7IvV*w_m75|#
zbB49+1+3n5p~6J30q=pZ3l#@g#rr@|&UJ!pfq96xj7zLLn9PV4n#|k?af`KgqWKxw
zD!?g=?#CbdUifAQ#dV&64u(VSppSJL at V<s|h$QqMIC_j{1|-%Y at Qb;^5`PJkvnfbl
zq*4IDUB6I?_b6drg|<VXThM~m3Sl%G#sOXaGkBkkE10Z~L0<U&g9P-GB}jLUm`;&X
zBg9lhyAUBa*Fy<|IHcnNsLChhFs1x_23=o4OW231wYve&)Bv*Hg7iwPiM)YvUbtCU
z1D5|DDUplwSIGZ+-Jyf;95{zYs%-<<@1$zop0M~mDU;X}mcB1-(AC49Fuo7pN6*1~
zlVqqxxZZ*-ox#Q+8#ve!Y&_g at m}(5Pu%0|o`16&W^2Si0E!dLZI^5RNvc?30Ae9%&
zZ+}JLKbm|;d~0%o$~+rgv6I?K9c&BgSh|X-YHfDA%gbrXM4Otcs9hd<m#LC9n>^)o
zE6tcHTHH)I%LbagRTaiA-yz?Tkk8oO=IiP)9`tpU1rPhnn%mhfPm8hKY%Vi4AMv#K
zx{bikdfM1B*6ptFlvh&5R(AzutngIPMt8Z1F}9dIbcM%L*-X=wWu46dHrVX-v!1e`
YSFp0pW9+7lZ9acjaA$kF5I7kB1huTe_y7O^

literal 0
HcmV?d00001

diff --git a/llvm/test/Bitcode/memory-attribute-upgrade-v2.ll b/llvm/test/Bitcode/memory-attribute-upgrade-v2.ll
new file mode 100644
index 00000000000000..4cafba1a2401d1
--- /dev/null
+++ b/llvm/test/Bitcode/memory-attribute-upgrade-v2.ll
@@ -0,0 +1,52 @@
+; RUN: llvm-dis < %S/Inputs/memory-attribute-upgrade-v2.bc | FileCheck %s
+
+; The input was produced by llvm-as from this file, at a revision that wrote
+; version 2 of the memory attribute encoding, which did not have the threadid
+; location and placed the target memory locations right after other memory.
+; The threadid location takes the access kind of other memory, and the target
+; memory locations must not be shifted into it.
+
+target triple = "aarch64-unknown-linux-gnu"
+
+; CHECK: ; Function Attrs: memory(target_mem0: read)
+; CHECK-NEXT: define void @test_target_mem0_read()
+define void @test_target_mem0_read() #0 {
+  ret void
+}
+
+; CHECK: ; Function Attrs: memory(read, target_mem1: write)
+; CHECK-NEXT: define void @test_read_target_mem1_write()
+define void @test_read_target_mem1_write() #1 {
+  ret void
+}
+
+; CHECK: ; Function Attrs: memory(readwrite, argmem: none, inaccessiblemem: read, errnomem: write, target_mem0: none, target_mem1: read)
+; CHECK-NEXT: define void @test_mixed()
+define void @test_mixed() #2 {
+  ret void
+}
+
+; CHECK: ; Function Attrs: memory(argmem: readwrite, target_mem: read)
+; CHECK-NEXT: define void @test_argmem_readwrite_target_mem_read()
+define void @test_argmem_readwrite_target_mem_read() #3 {
+  ret void
+}
+
+; CHECK: ; Function Attrs: memory(none)
+; CHECK-NEXT: define void @test_none()
+define void @test_none() #4 {
+  ret void
+}
+
+; CHECK: ; Function Attrs: memory(readwrite)
+; CHECK-NEXT: define void @test_readwrite()
+define void @test_readwrite() #5 {
+  ret void
+}
+
+attributes #0 = { memory(target_mem0: read) }
+attributes #1 = { memory(read, target_mem1: write) }
+attributes #2 = { memory(readwrite, argmem: none, inaccessiblemem: read, errnomem: write, target_mem0: none, target_mem1: read) }
+attributes #3 = { memory(argmem: readwrite, target_mem: read) }
+attributes #4 = { memory(none) }
+attributes #5 = { memory(readwrite) }
diff --git a/llvm/test/TableGen/target-mem-intrinsic-attrs.td b/llvm/test/TableGen/target-mem-intrinsic-attrs.td
index b3e1b5a8a55e25..f90ffa6776e777 100644
--- a/llvm/test/TableGen/target-mem-intrinsic-attrs.td
+++ b/llvm/test/TableGen/target-mem-intrinsic-attrs.td
@@ -23,41 +23,41 @@ def int_aarch64_target_mem1_read_argmem_write   : DefaultAttrsIntrinsic<[], [llv
 def int_aarch64_target_mem0_read_argmem_write   : DefaultAttrsIntrinsic<[], [llvm_i64_ty], [IntrRead<[TargetMem0]>, IntrWrite<[ArgMem]>]>;
 
 // CHECK-LABEL: case 0: // llvm.aarch64.argmem.read.target.mem1.write
-// CHECK: // ArgMem: Ref, InaccessibleMem: NoModRef, ErrnoMem: NoModRef, Other: NoModRef, TargetMem0: NoModRef, TargetMem1: Mod
-// CHECK-NEXT: Attribute::getWithMemoryEffects(C, MemoryEffects::createFromIntValue(2049)),
+// CHECK: // ArgMem: Ref, InaccessibleMem: NoModRef, ErrnoMem: NoModRef, Other: NoModRef, ThreadIdMem: NoModRef, TargetMem0: NoModRef, TargetMem1: Mod
+// CHECK-NEXT: Attribute::getWithMemoryEffects(C, MemoryEffects::createFromIntValue(8193)),
 
 // CHECK-LABEL: case 1: // llvm.aarch64.argmem.target.mem1.read.target.mem1.write
-// CHECK: // ArgMem: Ref, InaccessibleMem: NoModRef, ErrnoMem: NoModRef, Other: NoModRef, TargetMem0: NoModRef, TargetMem1: ModRef
-// CHECK-NEXT: Attribute::getWithMemoryEffects(C, MemoryEffects::createFromIntValue(3073)),
+// CHECK: // ArgMem: Ref, InaccessibleMem: NoModRef, ErrnoMem: NoModRef, Other: NoModRef, ThreadIdMem: NoModRef, TargetMem0: NoModRef, TargetMem1: ModRef
+// CHECK-NEXT: Attribute::getWithMemoryEffects(C, MemoryEffects::createFromIntValue(12289)),
 
 // CHECK-LABEL: case 2: // llvm.aarch64.get.target.mem0.mem1
-// CHECK: // ArgMem: NoModRef, InaccessibleMem: NoModRef, ErrnoMem: NoModRef, Other: NoModRef, TargetMem0: Ref, TargetMem1: Ref
-// CHECK-NEXT: Attribute::getWithMemoryEffects(C, MemoryEffects::createFromIntValue(1280)),
+// CHECK: // ArgMem: NoModRef, InaccessibleMem: NoModRef, ErrnoMem: NoModRef, Other: NoModRef, ThreadIdMem: NoModRef, TargetMem0: Ref, TargetMem1: Ref
+// CHECK-NEXT: Attribute::getWithMemoryEffects(C, MemoryEffects::createFromIntValue(5120)),
 
 // CHECK-LABEL: case 3: // llvm.aarch64.get.target.mem0.set.target.mem1
-// CHECK: // ArgMem: NoModRef, InaccessibleMem: NoModRef, ErrnoMem: NoModRef, Other: NoModRef, TargetMem0: Ref, TargetMem1: Mod
-// CHECK-NEXT: Attribute::getWithMemoryEffects(C, MemoryEffects::createFromIntValue(2304)),
+// CHECK: // ArgMem: NoModRef, InaccessibleMem: NoModRef, ErrnoMem: NoModRef, Other: NoModRef, ThreadIdMem: NoModRef, TargetMem0: Ref, TargetMem1: Mod
+// CHECK-NEXT: Attribute::getWithMemoryEffects(C, MemoryEffects::createFromIntValue(9216)),
 
 // CHECK-LABEL: case 4: // llvm.aarch64.get.target.mem1
-// CHECK: // ArgMem: NoModRef, InaccessibleMem: NoModRef, ErrnoMem: NoModRef, Other: NoModRef, TargetMem0: NoModRef, TargetMem1: Ref
-// CHECK-NEXT: Attribute::getWithMemoryEffects(C, MemoryEffects::createFromIntValue(1024)),
+// CHECK: // ArgMem: NoModRef, InaccessibleMem: NoModRef, ErrnoMem: NoModRef, Other: NoModRef, ThreadIdMem: NoModRef, TargetMem0: NoModRef, TargetMem1: Ref
+// CHECK-NEXT: Attribute::getWithMemoryEffects(C, MemoryEffects::createFromIntValue(4096)),
 
 // CHECK-LABEL: case 5: // llvm.aarch64.get.target.mem1.set.target.mem1
-// CHECK: // ArgMem: NoModRef, InaccessibleMem: NoModRef, ErrnoMem: NoModRef, Other: NoModRef, TargetMem0: NoModRef, TargetMem1: ModRef
-// CHECK-NEXT: Attribute::getWithMemoryEffects(C, MemoryEffects::createFromIntValue(3072)),
+// CHECK: // ArgMem: NoModRef, InaccessibleMem: NoModRef, ErrnoMem: NoModRef, Other: NoModRef, ThreadIdMem: NoModRef, TargetMem0: NoModRef, TargetMem1: ModRef
+// CHECK-NEXT: Attribute::getWithMemoryEffects(C, MemoryEffects::createFromIntValue(12288)),
 
 // CHECK-LABEL: case 6: // llvm.aarch64.set.inaccessible.mem
-// CHECK: // ArgMem: NoModRef, InaccessibleMem: Mod, ErrnoMem: NoModRef, Other: NoModRef, TargetMem0: NoModRef, TargetMem1: NoModRef
+// CHECK: // ArgMem: NoModRef, InaccessibleMem: Mod, ErrnoMem: NoModRef, Other: NoModRef, ThreadIdMem: NoModRef, TargetMem0: NoModRef, TargetMem1: NoModRef
 // CHECK-NEXT: Attribute::getWithMemoryEffects(C, MemoryEffects::createFromIntValue(8)),
 
 // CHECK-LABEL: case 7: // llvm.aarch64.set.target.mem0
-// CHECK: // ArgMem: NoModRef, InaccessibleMem: NoModRef, ErrnoMem: NoModRef, Other: NoModRef, TargetMem0: Mod, TargetMem1: NoModRef
-// CHECK-NEXT: Attribute::getWithMemoryEffects(C, MemoryEffects::createFromIntValue(512)),
+// CHECK: // ArgMem: NoModRef, InaccessibleMem: NoModRef, ErrnoMem: NoModRef, Other: NoModRef, ThreadIdMem: NoModRef, TargetMem0: Mod, TargetMem1: NoModRef
+// CHECK-NEXT: Attribute::getWithMemoryEffects(C, MemoryEffects::createFromIntValue(2048)),
 
 // CHECK-LABEL: case 8: // llvm.aarch64.target.mem0.read.argmem.write
-// CHECK: // ArgMem: Mod, InaccessibleMem: NoModRef, ErrnoMem: NoModRef, Other: NoModRef, TargetMem0: Ref, TargetMem1: NoModRef
-// CHECK-NEXT: Attribute::getWithMemoryEffects(C, MemoryEffects::createFromIntValue(258)),
+// CHECK: // ArgMem: Mod, InaccessibleMem: NoModRef, ErrnoMem: NoModRef, Other: NoModRef, ThreadIdMem: NoModRef, TargetMem0: Ref, TargetMem1: NoModRef
+// CHECK-NEXT: Attribute::getWithMemoryEffects(C, MemoryEffects::createFromIntValue(1026)),
 
 // CHECK-LABEL: case 9: // llvm.aarch64.target.mem1.read.argmem.write
-// CHECK: // ArgMem: Mod, InaccessibleMem: NoModRef, ErrnoMem: NoModRef, Other: NoModRef, TargetMem0: NoModRef, TargetMem1: Ref
-// CHECK-NEXT: Attribute::getWithMemoryEffects(C, MemoryEffects::createFromIntValue(1026)),
+// CHECK: // ArgMem: Mod, InaccessibleMem: NoModRef, ErrnoMem: NoModRef, Other: NoModRef, ThreadIdMem: NoModRef, TargetMem0: NoModRef, TargetMem1: Ref
+// CHECK-NEXT: Attribute::getWithMemoryEffects(C, MemoryEffects::createFromIntValue(4098)),
diff --git a/llvm/test/Transforms/FunctionAttrs/argmemonly.ll b/llvm/test/Transforms/FunctionAttrs/argmemonly.ll
index b1a44c94fd0463..08e8704bb705e5 100644
--- a/llvm/test/Transforms/FunctionAttrs/argmemonly.ll
+++ b/llvm/test/Transforms/FunctionAttrs/argmemonly.ll
@@ -56,7 +56,7 @@ entry:
 }
 
 define i32 @test_read_global() {
-; FNATTRS: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: none, inaccessiblemem: none, target_mem: none)
+; FNATTRS: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: none, inaccessiblemem: none, threadid: none, target_mem: none)
 ; FNATTRS-LABEL: define i32 @test_read_global
 ; FNATTRS-SAME: () #[[ATTR2:[0-9]+]] {
 ; FNATTRS-NEXT:  entry:
@@ -76,7 +76,7 @@ entry:
 }
 
 define i32 @test_read_loaded_ptr(ptr %ptr) {
-; FNATTRS: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read, inaccessiblemem: none, target_mem: none)
+; FNATTRS: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read, inaccessiblemem: none, threadid: none, target_mem: none)
 ; FNATTRS-LABEL: define i32 @test_read_loaded_ptr
 ; FNATTRS-SAME: (ptr nofree readonly captures(none) [[PTR:%.*]]) #[[ATTR3:[0-9]+]] {
 ; FNATTRS-NEXT:  entry:
@@ -119,7 +119,7 @@ entry:
 }
 
 define void @test_write_global() {
-; FNATTRS: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(write, argmem: none, inaccessiblemem: none, target_mem: none)
+; FNATTRS: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(write, argmem: none, inaccessiblemem: none, threadid: none, target_mem: none)
 ; FNATTRS-LABEL: define void @test_write_global
 ; FNATTRS-SAME: () #[[ATTR5:[0-9]+]] {
 ; FNATTRS-NEXT:  entry:
@@ -243,7 +243,7 @@ declare void @llvm.memcpy.p0.p0.i64(ptr, ptr, i64, i1)
 @arr = global [32 x i8] zeroinitializer
 
 define void @test_memcpy_src_global(ptr %dst) {
-; FNATTRS: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, inaccessiblemem: none, target_mem: none)
+; FNATTRS: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, inaccessiblemem: none, threadid: none, target_mem: none)
 ; FNATTRS-LABEL: define void @test_memcpy_src_global
 ; FNATTRS-SAME: (ptr nofree writeonly captures(none) initializes((0, 32)) [[DST:%.*]]) #[[ATTR11:[0-9]+]] {
 ; FNATTRS-NEXT:  entry:
@@ -263,7 +263,7 @@ entry:
 }
 
 define void @test_memcpy_dst_global(ptr %src) {
-; FNATTRS: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, inaccessiblemem: none, target_mem: none)
+; FNATTRS: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, inaccessiblemem: none, threadid: none, target_mem: none)
 ; FNATTRS-LABEL: define void @test_memcpy_dst_global
 ; FNATTRS-SAME: (ptr nofree readonly captures(none) [[SRC:%.*]]) #[[ATTR11]] {
 ; FNATTRS-NEXT:  entry:
@@ -388,7 +388,7 @@ define void @test_inaccessibleorargmemonly_readwrite(ptr %arg) {
 }
 
 define void @test_recursive_argmem_read(ptr %p) {
-; FNATTRS: Function Attrs: nofree nosync nounwind memory(read, inaccessiblemem: none, target_mem: none)
+; FNATTRS: Function Attrs: nofree nosync nounwind memory(read, inaccessiblemem: none, threadid: none, target_mem: none)
 ; FNATTRS-LABEL: define void @test_recursive_argmem_read
 ; FNATTRS-SAME: (ptr nofree readonly captures(none) [[P:%.*]]) #[[ATTR16:[0-9]+]] {
 ; FNATTRS-NEXT:    [[PVAL:%.*]] = load ptr, ptr [[P]], align 8
@@ -408,7 +408,7 @@ define void @test_recursive_argmem_read(ptr %p) {
 }
 
 define void @test_recursive_argmem_readwrite(ptr %p) {
-; FNATTRS: Function Attrs: nofree nosync nounwind memory(readwrite, inaccessiblemem: none, target_mem: none)
+; FNATTRS: Function Attrs: nofree nosync nounwind memory(readwrite, inaccessiblemem: none, threadid: none, target_mem: none)
 ; FNATTRS-LABEL: define void @test_recursive_argmem_readwrite
 ; FNATTRS-SAME: (ptr nofree captures(none) [[P:%.*]]) #[[ATTR17:[0-9]+]] {
 ; FNATTRS-NEXT:    [[PVAL:%.*]] = load ptr, ptr [[P]], align 8
@@ -454,7 +454,7 @@ define void @test_recursive_argmem_read_alloca(ptr %p) {
 }
 
 define void @test_scc_argmem_read_1(ptr %p) {
-; FNATTRS: Function Attrs: nofree nosync nounwind memory(read, inaccessiblemem: none, target_mem: none)
+; FNATTRS: Function Attrs: nofree nosync nounwind memory(read, inaccessiblemem: none, threadid: none, target_mem: none)
 ; FNATTRS-LABEL: define void @test_scc_argmem_read_1
 ; FNATTRS-SAME: (ptr nofree readonly captures(none) [[P:%.*]]) #[[ATTR16]] {
 ; FNATTRS-NEXT:    [[PVAL:%.*]] = load ptr, ptr [[P]], align 8
@@ -474,7 +474,7 @@ define void @test_scc_argmem_read_1(ptr %p) {
 }
 
 define void @test_scc_argmem_read_2(ptr %p) {
-; FNATTRS: Function Attrs: nofree nosync nounwind memory(read, inaccessiblemem: none, target_mem: none)
+; FNATTRS: Function Attrs: nofree nosync nounwind memory(read, inaccessiblemem: none, threadid: none, target_mem: none)
 ; FNATTRS-LABEL: define void @test_scc_argmem_read_2
 ; FNATTRS-SAME: (ptr nofree readonly captures(none) [[P:%.*]]) #[[ATTR16]] {
 ; FNATTRS-NEXT:    call void @test_scc_argmem_read_1(ptr [[P]])
@@ -518,7 +518,7 @@ entry:
 
 ; FIXME: This could be `memory(argmem: read)`.
 define i64 @select_different_obj(i1 %c, ptr %p, ptr %p2) {
-; FNATTRS: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read, inaccessiblemem: none, target_mem: none)
+; FNATTRS: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read, inaccessiblemem: none, threadid: none, target_mem: none)
 ; FNATTRS-LABEL: define i64 @select_different_obj
 ; FNATTRS-SAME: (i1 [[C:%.*]], ptr nofree readonly captures(none) [[P:%.*]], ptr nofree readonly captures(none) [[P2:%.*]]) #[[ATTR3]] {
 ; FNATTRS-NEXT:  entry:
@@ -567,7 +567,7 @@ join:
 
 ; FIXME: This could be `memory(argmem: read)`.
 define i64 @phi_different_obj(i1 %c, ptr %p, ptr %p2) {
-; FNATTRS: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read, inaccessiblemem: none, target_mem: none)
+; FNATTRS: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read, inaccessiblemem: none, threadid: none, target_mem: none)
 ; FNATTRS-LABEL: define i64 @phi_different_obj
 ; FNATTRS-SAME: (i1 [[C:%.*]], ptr nofree readonly captures(none) [[P:%.*]], ptr nofree readonly captures(none) [[P2:%.*]]) #[[ATTR3]] {
 ; FNATTRS-NEXT:  entry:
diff --git a/llvm/test/Transforms/FunctionAttrs/nocapture.ll b/llvm/test/Transforms/FunctionAttrs/nocapture.ll
index 247888fc81b769..caaa964d1ec2cf 100644
--- a/llvm/test/Transforms/FunctionAttrs/nocapture.ll
+++ b/llvm/test/Transforms/FunctionAttrs/nocapture.ll
@@ -20,7 +20,7 @@ define ptr @c1(ptr %q) {
 
 ; It would also be acceptable to mark %q as readnone. Update @c3 too.
 define void @c2(ptr %q) {
-; FNATTRS: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(write, argmem: none, inaccessiblemem: none, target_mem: none)
+; FNATTRS: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(write, argmem: none, inaccessiblemem: none, threadid: none, target_mem: none)
 ; FNATTRS-LABEL: define void @c2
 ; FNATTRS-SAME: (ptr [[Q:%.*]]) #[[ATTR1:[0-9]+]] {
 ; FNATTRS-NEXT:    store ptr [[Q]], ptr @g, align 8
@@ -37,7 +37,7 @@ define void @c2(ptr %q) {
 }
 
 define void @c3(ptr %q) {
-; FNATTRS: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(write, inaccessiblemem: none, target_mem: none)
+; FNATTRS: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(write, inaccessiblemem: none, threadid: none, target_mem: none)
 ; FNATTRS-LABEL: define void @c3
 ; FNATTRS-SAME: (ptr [[Q:%.*]]) #[[ATTR2:[0-9]+]] {
 ; FNATTRS-NEXT:    call void @c2(ptr [[Q]])
@@ -127,7 +127,7 @@ l1:
 @lookup_table = global [2 x i1] [ i1 0, i1 1 ]
 
 define i1 @c5(ptr %q, i32 %bitno) {
-; FNATTRS: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: none, inaccessiblemem: none, target_mem: none)
+; FNATTRS: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: none, inaccessiblemem: none, threadid: none, target_mem: none)
 ; FNATTRS-LABEL: define i1 @c5
 ; FNATTRS-SAME: (ptr [[Q:%.*]], i32 [[BITNO:%.*]]) #[[ATTR3:[0-9]+]] {
 ; FNATTRS-NEXT:    [[TMP:%.*]] = ptrtoint ptr [[Q]] to i32
@@ -222,7 +222,7 @@ define ptr @lookup_bit(ptr %q, i32 %bitno) readnone nounwind {
 }
 
 define i1 @c7(ptr %q, i32 %bitno) {
-; FNATTRS: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read, inaccessiblemem: none, target_mem: none)
+; FNATTRS: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read, inaccessiblemem: none, threadid: none, target_mem: none)
 ; FNATTRS-LABEL: define i1 @c7
 ; FNATTRS-SAME: (ptr nofree readonly [[Q:%.*]], i32 [[BITNO:%.*]]) #[[ATTR6:[0-9]+]] {
 ; FNATTRS-NEXT:    [[PTR:%.*]] = call ptr @lookup_bit(ptr [[Q]], i32 [[BITNO]])
@@ -243,7 +243,7 @@ define i1 @c7(ptr %q, i32 %bitno) {
 
 
 define i32 @nc1(ptr %q, ptr %p, i1 %b) {
-; FNATTRS: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, inaccessiblemem: none, target_mem: none)
+; FNATTRS: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, inaccessiblemem: none, threadid: none, target_mem: none)
 ; FNATTRS-LABEL: define i32 @nc1
 ; FNATTRS-SAME: (ptr [[Q:%.*]], ptr nofree captures(none) [[P:%.*]], i1 [[B:%.*]]) #[[ATTR7:[0-9]+]] {
 ; FNATTRS-NEXT:  e:
@@ -284,7 +284,7 @@ l:
 }
 
 define i32 @nc1_addrspace(ptr %q, ptr addrspace(1) %p, i1 %b) {
-; FNATTRS: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, inaccessiblemem: none, target_mem: none)
+; FNATTRS: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, inaccessiblemem: none, threadid: none, target_mem: none)
 ; FNATTRS-LABEL: define i32 @nc1_addrspace
 ; FNATTRS-SAME: (ptr [[Q:%.*]], ptr addrspace(1) nofree captures(none) [[P:%.*]], i1 [[B:%.*]]) #[[ATTR7]] {
 ; FNATTRS-NEXT:  e:
@@ -328,7 +328,7 @@ l:
 }
 
 define void @nc2(ptr %p, ptr %q) {
-; FNATTRS: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, inaccessiblemem: none, target_mem: none)
+; FNATTRS: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, inaccessiblemem: none, threadid: none, target_mem: none)
 ; FNATTRS-LABEL: define void @nc2
 ; FNATTRS-SAME: (ptr nofree captures(none) [[P:%.*]], ptr [[Q:%.*]]) #[[ATTR7]] {
 ; FNATTRS-NEXT:    [[TMP1:%.*]] = call i32 @nc1(ptr [[Q]], ptr [[P]], i1 false)
@@ -468,7 +468,7 @@ define void @self_readonly_nounwind_willreturn(ptr %p) readonly nounwind willret
 
 ; It would be acceptable to add readnone to %y1_1 and %y1_2.
 define void @test1_1(ptr %x1_1, ptr %y1_1, i1 %c) {
-; FNATTRS: Function Attrs: nofree nosync nounwind memory(write, argmem: none, inaccessiblemem: none, target_mem: none)
+; FNATTRS: Function Attrs: nofree nosync nounwind memory(write, argmem: none, inaccessiblemem: none, threadid: none, target_mem: none)
 ; FNATTRS-LABEL: define void @test1_1
 ; FNATTRS-SAME: (ptr nofree readnone captures(none) [[X1_1:%.*]], ptr [[Y1_1:%.*]], i1 [[C:%.*]]) #[[ATTR12:[0-9]+]] {
 ; FNATTRS-NEXT:    [[TMP1:%.*]] = call ptr @test1_2(ptr [[X1_1]], ptr [[Y1_1]], i1 [[C]])
@@ -488,7 +488,7 @@ define void @test1_1(ptr %x1_1, ptr %y1_1, i1 %c) {
 }
 
 define ptr @test1_2(ptr %x1_2, ptr %y1_2, i1 %c) {
-; FNATTRS: Function Attrs: nofree nosync nounwind memory(write, argmem: none, inaccessiblemem: none, target_mem: none)
+; FNATTRS: Function Attrs: nofree nosync nounwind memory(write, argmem: none, inaccessiblemem: none, threadid: none, target_mem: none)
 ; FNATTRS-LABEL: define ptr @test1_2
 ; FNATTRS-SAME: (ptr nofree readnone captures(none) [[X1_2:%.*]], ptr returned [[Y1_2:%.*]], i1 [[C:%.*]]) #[[ATTR12]] {
 ; FNATTRS-NEXT:    br i1 [[C]], label [[T:%.*]], label [[F:%.*]]
@@ -520,7 +520,7 @@ f:
 }
 
 define void @test2(ptr %x2) {
-; FNATTRS: Function Attrs: nofree nosync nounwind memory(write, argmem: none, inaccessiblemem: none, target_mem: none)
+; FNATTRS: Function Attrs: nofree nosync nounwind memory(write, argmem: none, inaccessiblemem: none, threadid: none, target_mem: none)
 ; FNATTRS-LABEL: define void @test2
 ; FNATTRS-SAME: (ptr nofree readnone captures(none) [[X2:%.*]]) #[[ATTR12]] {
 ; FNATTRS-NEXT:    call void @test2(ptr [[X2]])
@@ -540,7 +540,7 @@ define void @test2(ptr %x2) {
 }
 
 define void @test3(ptr %x3, ptr %y3, ptr %z3) {
-; FNATTRS: Function Attrs: nofree nosync nounwind memory(write, argmem: none, inaccessiblemem: none, target_mem: none)
+; FNATTRS: Function Attrs: nofree nosync nounwind memory(write, argmem: none, inaccessiblemem: none, threadid: none, target_mem: none)
 ; FNATTRS-LABEL: define void @test3
 ; FNATTRS-SAME: (ptr nofree readnone captures(none) [[X3:%.*]], ptr nofree readnone captures(none) [[Y3:%.*]], ptr nofree readnone captures(none) [[Z3:%.*]]) #[[ATTR12]] {
 ; FNATTRS-NEXT:    call void @test3(ptr [[Z3]], ptr [[Y3]], ptr [[X3]])
@@ -560,7 +560,7 @@ define void @test3(ptr %x3, ptr %y3, ptr %z3) {
 }
 
 define void @test4_1(ptr %x4_1, i1 %c) {
-; FNATTRS: Function Attrs: nofree nosync nounwind memory(write, argmem: none, inaccessiblemem: none, target_mem: none)
+; FNATTRS: Function Attrs: nofree nosync nounwind memory(write, argmem: none, inaccessiblemem: none, threadid: none, target_mem: none)
 ; FNATTRS-LABEL: define void @test4_1
 ; FNATTRS-SAME: (ptr [[X4_1:%.*]], i1 [[C:%.*]]) #[[ATTR12]] {
 ; FNATTRS-NEXT:    [[TMP1:%.*]] = call ptr @test4_2(ptr [[X4_1]], ptr [[X4_1]], ptr [[X4_1]], i1 [[C]])
@@ -580,7 +580,7 @@ define void @test4_1(ptr %x4_1, i1 %c) {
 }
 
 define ptr @test4_2(ptr %x4_2, ptr %y4_2, ptr %z4_2, i1 %c) {
-; FNATTRS: Function Attrs: nofree nosync nounwind memory(write, argmem: none, inaccessiblemem: none, target_mem: none)
+; FNATTRS: Function Attrs: nofree nosync nounwind memory(write, argmem: none, inaccessiblemem: none, threadid: none, target_mem: none)
 ; FNATTRS-LABEL: define ptr @test4_2
 ; FNATTRS-SAME: (ptr nofree readnone captures(none) [[X4_2:%.*]], ptr nofree readnone returned captures(ret: address, provenance) [[Y4_2:%.*]], ptr nofree readnone captures(none) [[Z4_2:%.*]], i1 [[C:%.*]]) #[[ATTR12]] {
 ; FNATTRS-NEXT:    br i1 [[C]], label [[T:%.*]], label [[F:%.*]]
@@ -744,7 +744,7 @@ entry:
 
 @g2 = global ptr null
 define void @captureLaunder(ptr %p) {
-; FNATTRS: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(write, argmem: none, inaccessiblemem: readwrite, target_mem: none)
+; FNATTRS: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(write, argmem: none, inaccessiblemem: readwrite, threadid: none, target_mem: none)
 ; FNATTRS-LABEL: define void @captureLaunder
 ; FNATTRS-SAME: (ptr [[P:%.*]]) #[[ATTR16:[0-9]+]] {
 ; FNATTRS-NEXT:    [[B:%.*]] = call ptr @llvm.launder.invariant.group.p0(ptr [[P]])
@@ -1042,7 +1042,7 @@ define i64 @captures_not_ret_only(ptr %p) {
 
 ;; Unlike ptrtoint, ptrtoaddr only captures the address
 define i64 @captures_ptrtoaddr_stored(ptr %p) {
-; FNATTRS: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(write, argmem: none, inaccessiblemem: none, target_mem: none)
+; FNATTRS: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(write, argmem: none, inaccessiblemem: none, threadid: none, target_mem: none)
 ; FNATTRS-LABEL: define noundef i64 @captures_ptrtoaddr_stored
 ; FNATTRS-SAME: (ptr nofree readnone captures(address) [[P:%.*]]) #[[ATTR1]] {
 ; FNATTRS-NEXT:    [[INT:%.*]] = ptrtoaddr ptr [[P]] to i64
@@ -1145,7 +1145,7 @@ define ptr @captures_used_ret(ptr %p) {
 ; Make sure this is does not produce captures(ret: ...). We need to take the
 ; return capture components into account when handling argument SCCs.
 define ptr @scc_capture_via_ret(i1 %c, ptr %p) {
-; FNATTRS: Function Attrs: nofree nosync nounwind memory(write, argmem: none, inaccessiblemem: none, target_mem: none)
+; FNATTRS: Function Attrs: nofree nosync nounwind memory(write, argmem: none, inaccessiblemem: none, threadid: none, target_mem: none)
 ; FNATTRS-LABEL: define ptr @scc_capture_via_ret
 ; FNATTRS-SAME: (i1 [[C:%.*]], ptr [[P:%.*]]) #[[ATTR12]] {
 ; FNATTRS-NEXT:    br i1 [[C]], label [[IF:%.*]], label [[ELSE:%.*]]
@@ -1247,7 +1247,7 @@ define void @dont_increase_existing_captures_scc2(ptr %p) {
 }
 
 define void @addr_only_scc(ptr %p) {
-; FNATTRS: Function Attrs: nofree nosync nounwind memory(write, argmem: read, inaccessiblemem: none, target_mem: none)
+; FNATTRS: Function Attrs: nofree nosync nounwind memory(write, argmem: read, inaccessiblemem: none, threadid: none, target_mem: none)
 ; FNATTRS-LABEL: define void @addr_only_scc
 ; FNATTRS-SAME: (ptr nofree readonly captures(address_is_null) [[P:%.*]]) #[[ATTR19:[0-9]+]] {
 ; FNATTRS-NEXT:    [[V:%.*]] = load i8, ptr [[P]], align 1
@@ -1270,7 +1270,7 @@ define void @addr_only_scc(ptr %p) {
 }
 
 define void @addr_only_scc2(ptr %p) {
-; FNATTRS: Function Attrs: nofree nosync nounwind memory(write, argmem: read, inaccessiblemem: none, target_mem: none)
+; FNATTRS: Function Attrs: nofree nosync nounwind memory(write, argmem: read, inaccessiblemem: none, threadid: none, target_mem: none)
 ; FNATTRS-LABEL: define void @addr_only_scc2
 ; FNATTRS-SAME: (ptr nofree readonly captures(address_is_null) [[P:%.*]]) #[[ATTR19]] {
 ; FNATTRS-NEXT:    [[CMP:%.*]] = icmp ne ptr [[P]], null
diff --git a/llvm/test/Transforms/FunctionAttrs/read-write-scc.ll b/llvm/test/Transforms/FunctionAttrs/read-write-scc.ll
index 36baf6be754c95..3188557864d014 100644
--- a/llvm/test/Transforms/FunctionAttrs/read-write-scc.ll
+++ b/llvm/test/Transforms/FunctionAttrs/read-write-scc.ll
@@ -4,7 +4,7 @@
 @i = global i32 0
 
 define void @foo() {
-; CHECK: Function Attrs: nofree nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none, target_mem: none)
+; CHECK: Function Attrs: nofree nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none, threadid: none, target_mem: none)
 ; CHECK-LABEL: define {{[^@]+}}@foo
 ; CHECK-SAME: () #[[ATTR0:[0-9]+]] {
 ; CHECK-NEXT:    store i32 1, ptr @i, align 4
@@ -17,7 +17,7 @@ define void @foo() {
 }
 
 define void @bar() {
-; CHECK: Function Attrs: nofree nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none, target_mem: none)
+; CHECK: Function Attrs: nofree nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none, threadid: none, target_mem: none)
 ; CHECK-LABEL: define {{[^@]+}}@bar
 ; CHECK-SAME: () #[[ATTR0]] {
 ; CHECK-NEXT:    [[I:%.*]] = load i32, ptr @i, align 4
diff --git a/llvm/test/Transforms/FunctionAttrs/readattrs.ll b/llvm/test/Transforms/FunctionAttrs/readattrs.ll
index fbd7b7436ce6d1..79da329c33a932 100644
--- a/llvm/test/Transforms/FunctionAttrs/readattrs.ll
+++ b/llvm/test/Transforms/FunctionAttrs/readattrs.ll
@@ -33,7 +33,7 @@ define void @test1_2(ptr %x1_2, ptr %y1_2, ptr %z1_2) {
 
 ; TODO: Missing with attributor-light: argmem: none, inaccessiblemem: none
 define ptr @test2(ptr %p) {
-; FNATTRS: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(write, argmem: none, inaccessiblemem: none, target_mem: none)
+; FNATTRS: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(write, argmem: none, inaccessiblemem: none, threadid: none, target_mem: none)
 ; FNATTRS-LABEL: define {{[^@]+}}@test2
 ; FNATTRS-SAME: (ptr nofree readnone returned captures(ret: address, provenance) [[P:%.*]]) #[[ATTR0:[0-9]+]] {
 ; FNATTRS-NEXT:    store i32 0, ptr @x, align 4
diff --git a/llvm/test/Transforms/FunctionAttrs/writeonly.ll b/llvm/test/Transforms/FunctionAttrs/writeonly.ll
index 9d6fa0ef0efe8a..891868d9a7a99b 100644
--- a/llvm/test/Transforms/FunctionAttrs/writeonly.ll
+++ b/llvm/test/Transforms/FunctionAttrs/writeonly.ll
@@ -38,7 +38,7 @@ nouses-argworn-funro_entry:
 @d-ccc = internal global %_type_of_d-ccc <{ ptr null, i8 1, i8 13, i8 0, i8 -127 }>, align 8
 
 define void @nouses-argworn-funwo(ptr writeonly %.aaa) {
-; FNATTRS: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(write, argmem: none, inaccessiblemem: none, target_mem: none)
+; FNATTRS: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(write, argmem: none, inaccessiblemem: none, threadid: none, target_mem: none)
 ; FNATTRS-LABEL: define {{[^@]+}}@nouses-argworn-funwo
 ; FNATTRS-SAME: (ptr nofree readnone captures(none) [[DOTAAA:%.*]]) #[[ATTR2:[0-9]+]] {
 ; FNATTRS-NEXT:  nouses-argworn-funwo_entry:
@@ -76,7 +76,7 @@ define void @test_store(ptr %p) {
 
 @G = external global ptr
 define i8 @test_store_capture(ptr %p) {
-; FNATTRS: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, argmem: read, inaccessiblemem: none, target_mem: none)
+; FNATTRS: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, argmem: read, inaccessiblemem: none, threadid: none, target_mem: none)
 ; FNATTRS-LABEL: define {{[^@]+}}@test_store_capture
 ; FNATTRS-SAME: (ptr [[P:%.*]]) #[[ATTR4:[0-9]+]] {
 ; FNATTRS-NEXT:    store ptr [[P]], ptr @G, align 8
diff --git a/llvm/test/Transforms/GlobalOpt/disable-globals-aa.ll b/llvm/test/Transforms/GlobalOpt/disable-globals-aa.ll
index df620416154d72..a9f9c1f14b526c 100644
--- a/llvm/test/Transforms/GlobalOpt/disable-globals-aa.ll
+++ b/llvm/test/Transforms/GlobalOpt/disable-globals-aa.ll
@@ -44,11 +44,11 @@ define i8 @dummy() !prof !0 {
 
 !0 = !{!"function_entry_count", i32 10}
 ;.
-; WITHGLOBALSAA: attributes #[[ATTR0:[0-9]+]] = { mustprogress nofree norecurse nosync nounwind willreturn memory(write, inaccessiblemem: none, target_mem: none) }
-; WITHGLOBALSAA: attributes #[[ATTR1:[0-9]+]] = { mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: none, inaccessiblemem: none, target_mem: none) }
+; WITHGLOBALSAA: attributes #[[ATTR0:[0-9]+]] = { mustprogress nofree norecurse nosync nounwind willreturn memory(write, inaccessiblemem: none, threadid: none, target_mem: none) }
+; WITHGLOBALSAA: attributes #[[ATTR1:[0-9]+]] = { mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: none, inaccessiblemem: none, threadid: none, target_mem: none) }
 ;.
-; NOGLOBALSAA: attributes #[[ATTR0:[0-9]+]] = { mustprogress nofree norecurse nosync nounwind willreturn memory(write, argmem: readwrite, inaccessiblemem: none, target_mem: none) }
-; NOGLOBALSAA: attributes #[[ATTR1:[0-9]+]] = { mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: none, inaccessiblemem: none, target_mem: none) }
+; NOGLOBALSAA: attributes #[[ATTR0:[0-9]+]] = { mustprogress nofree norecurse nosync nounwind willreturn memory(write, argmem: readwrite, inaccessiblemem: none, threadid: none, target_mem: none) }
+; NOGLOBALSAA: attributes #[[ATTR1:[0-9]+]] = { mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: none, inaccessiblemem: none, threadid: none, target_mem: none) }
 ;.
 ; WITHGLOBALSAA: [[META0:![0-9]+]] = !{!"function_entry_count", i32 10}
 ; WITHGLOBALSAA: [[PROF1]] = !{!"unknown", !"globalopt"}
diff --git a/llvm/test/Transforms/InferFunctionAttrs/norecurse_debug.ll b/llvm/test/Transforms/InferFunctionAttrs/norecurse_debug.ll
index 0a0fdc0d4d42af..0ff58c1125152c 100644
--- a/llvm/test/Transforms/InferFunctionAttrs/norecurse_debug.ll
+++ b/llvm/test/Transforms/InferFunctionAttrs/norecurse_debug.ll
@@ -52,5 +52,5 @@ attributes #1 = { nounwind readnone speculatable }
 !28 = !DILocation(line: 9, column: 18, scope: !2)
 !29 = !DILocation(line: 10, column: 1, scope: !2)
 
-; CHECK: attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, argmem: write, inaccessiblemem: none, target_mem: none) }
+; CHECK: attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, argmem: write, inaccessiblemem: none, threadid: none, target_mem: none) }
 ; CHECK-NOT: foo.coefficient1
diff --git a/llvm/test/Transforms/LowerTypeTests/cfi-nounwind-direct-call.ll b/llvm/test/Transforms/LowerTypeTests/cfi-nounwind-direct-call.ll
index c626a5f4d59c9c..4ed6a8ac3c3dc9 100644
--- a/llvm/test/Transforms/LowerTypeTests/cfi-nounwind-direct-call.ll
+++ b/llvm/test/Transforms/LowerTypeTests/cfi-nounwind-direct-call.ll
@@ -117,7 +117,7 @@ attributes #6 = { noreturn nounwind }
 ; CHECK-NEXT:    ret i32 [[DOT]]
 ;
 ;
-; CHECK: Function Attrs: minsize mustprogress nofree norecurse nosync nounwind optsize willreturn memory(write, argmem: none, inaccessiblemem: none, target_mem: none)
+; CHECK: Function Attrs: minsize mustprogress nofree norecurse nosync nounwind optsize willreturn memory(write, argmem: none, inaccessiblemem: none, threadid: none, target_mem: none)
 ; CHECK-LABEL: define dso_local noundef range(i32 0, 2) i32 @_Z10call_catchi
 ; CHECK-SAME: (i32 noundef [[NUM:%.*]]) local_unnamed_addr #[[ATTR1:[0-9]+]] !type [[META4]] !type [[META5]] !type [[META6]] {
 ; CHECK-NEXT:  entry:
diff --git a/llvm/test/Transforms/SCCP/ipscp-drop-argmemonly.ll b/llvm/test/Transforms/SCCP/ipscp-drop-argmemonly.ll
index 4e7597e9302073..a03cb5e8382741 100644
--- a/llvm/test/Transforms/SCCP/ipscp-drop-argmemonly.ll
+++ b/llvm/test/Transforms/SCCP/ipscp-drop-argmemonly.ll
@@ -14,7 +14,7 @@
 ; CHECK: @[[G:[a-zA-Z0-9_$"\\.-]+]] = internal global i32 0
 ;.
 define internal void @ptrarg.1(ptr %arg, i32 %val) argmemonly nounwind {
-; CHECK: Function Attrs: nounwind memory(readwrite, inaccessiblemem: none, target_mem: none)
+; CHECK: Function Attrs: nounwind memory(readwrite, inaccessiblemem: none, threadid: none, target_mem: none)
 ; CHECK-LABEL: @ptrarg.1(
 ; CHECK-NEXT:    store i32 10, ptr @g, align 4
 ; CHECK-NEXT:    ret void
@@ -62,7 +62,7 @@ define void @caller.2(ptr %ptr) {
 ; Here the pointer argument %arg will be replaced by a constant. We need to
 ; drop inaccessiblemem_or_argmemonly.
 define internal void @ptrarg.3(ptr %arg, i32 %val) inaccessiblemem_or_argmemonly nounwind {
-; CHECK: Function Attrs: nounwind memory(readwrite, target_mem: none)
+; CHECK: Function Attrs: nounwind memory(readwrite, threadid: none, target_mem: none)
 ; CHECK-LABEL: @ptrarg.3(
 ; CHECK-NEXT:    store i32 10, ptr @g, align 4
 ; CHECK-NEXT:    ret void
@@ -110,7 +110,7 @@ define void @caller.4(ptr %ptr) {
 ; Here the pointer argument %arg will be replaced by a constant. We need to
 ; drop inaccessiblemem_or_argmemonly.
 define internal void @ptrarg.5(ptr %arg, i32 %val) argmemonly inaccessiblemem_or_argmemonly nounwind {
-; CHECK: Function Attrs: nounwind memory(readwrite, inaccessiblemem: none, target_mem: none)
+; CHECK: Function Attrs: nounwind memory(readwrite, inaccessiblemem: none, threadid: none, target_mem: none)
 ; CHECK-LABEL: @ptrarg.5(
 ; CHECK-NEXT:    store i32 10, ptr @g, align 4
 ; CHECK-NEXT:    ret void
@@ -163,9 +163,9 @@ define i32 @caller.6.cs.attributes(i32 %n) {
 }
 
 ;.
-; CHECK: attributes #[[ATTR0]] = { nounwind memory(readwrite, inaccessiblemem: none, target_mem: none) }
+; CHECK: attributes #[[ATTR0]] = { nounwind memory(readwrite, inaccessiblemem: none, threadid: none, target_mem: none) }
 ; CHECK: attributes #[[ATTR1:[0-9]+]] = { nounwind memory(argmem: readwrite) }
-; CHECK: attributes #[[ATTR2]] = { nounwind memory(readwrite, target_mem: none) }
+; CHECK: attributes #[[ATTR2]] = { nounwind memory(readwrite, threadid: none, target_mem: none) }
 ; CHECK: attributes #[[ATTR3:[0-9]+]] = { nounwind memory(argmem: readwrite, inaccessiblemem: readwrite) }
 ; CHECK: attributes #[[ATTR4]] = { nounwind }
 ;.
diff --git a/llvm/unittests/Support/ModRefTest.cpp b/llvm/unittests/Support/ModRefTest.cpp
index 128501bf2d9572..a03d1c22c82884 100644
--- a/llvm/unittests/Support/ModRefTest.cpp
+++ b/llvm/unittests/Support/ModRefTest.cpp
@@ -21,7 +21,26 @@ TEST(ModRefTest, PrintMemoryEffects) {
   raw_string_ostream OS(S);
   OS << MemoryEffects::none();
   EXPECT_EQ(S, "ArgMem: NoModRef, InaccessibleMem: NoModRef, ErrnoMem: "
-               "NoModRef, Other: NoModRef, TargetMem0: NoModRef, TargetMem1: NoModRef");
+               "NoModRef, Other: NoModRef, ThreadIdMem: NoModRef, TargetMem0: "
+               "NoModRef, TargetMem1: NoModRef");
+}
+
+TEST(ModRefTest, ThreadIdMem) {
+  MemoryEffects ME = MemoryEffects::threadIdMemOnly(ModRefInfo::Ref);
+  EXPECT_EQ(ME.getModRef(IRMemLocation::ThreadIdMem), ModRefInfo::Ref);
+  EXPECT_EQ(ME.getModRef(IRMemLocation::Other), ModRefInfo::NoModRef);
+  EXPECT_EQ(ME.getModRef(IRMemLocation::TargetMem0), ModRefInfo::NoModRef);
+  EXPECT_EQ(ME.getModRef(IRMemLocation::TargetMem1), ModRefInfo::NoModRef);
+  EXPECT_TRUE(ME.onlyReadsMemory());
+  EXPECT_FALSE(ME.onlyAccessesInaccessibleMem());
+
+  EXPECT_EQ(MemoryEffects::readOnly().getModRef(IRMemLocation::ThreadIdMem),
+            ModRefInfo::Ref);
+  EXPECT_EQ(MemoryEffects::argMemOnly().getModRef(IRMemLocation::ThreadIdMem),
+            ModRefInfo::NoModRef);
+  EXPECT_EQ(MemoryEffects::inaccessibleMemOnly().getModRef(
+                IRMemLocation::ThreadIdMem),
+            ModRefInfo::NoModRef);
 }
 
 } // namespace
diff --git a/llvm/utils/TableGen/Basic/RuntimeLibcallsEmitter.cpp b/llvm/utils/TableGen/Basic/RuntimeLibcallsEmitter.cpp
index 045dad66dda36c..1d25e147fce816 100644
--- a/llvm/utils/TableGen/Basic/RuntimeLibcallsEmitter.cpp
+++ b/llvm/utils/TableGen/Basic/RuntimeLibcallsEmitter.cpp
@@ -637,6 +637,7 @@ static std::optional<uint32_t> getMemoryEffects(const Record *R) {
       {IRMemLocation::InaccessibleMem, "InaccessibleMem"},
       {IRMemLocation::ErrnoMem, "ErrnoMem"},
       {IRMemLocation::Other, "Other"},
+      {IRMemLocation::ThreadIdMem, "ThreadIdMem"},
       {IRMemLocation::TargetMem0, "TargetMem0"},
       {IRMemLocation::TargetMem1, "TargetMem1"},
   };
diff --git a/mlir/lib/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.cpp b/mlir/lib/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.cpp
index 1ed860f2aba167..956858b83d9032 100644
--- a/mlir/lib/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.cpp
+++ b/mlir/lib/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.cpp
@@ -608,6 +608,8 @@ convertOperationImpl(Operation &opInst, llvm::IRBuilderBase &builder,
               convertModRefInfoToLLVM(memAttr.getInaccessibleMem())) |
           llvm::MemoryEffects(llvm::MemoryEffects::Location::Other,
                               convertModRefInfoToLLVM(memAttr.getOther())) |
+          llvm::MemoryEffects(llvm::MemoryEffects::Location::ThreadIdMem,
+                              convertModRefInfoToLLVM(memAttr.getOther())) |
           llvm::MemoryEffects(llvm::MemoryEffects::Location::ErrnoMem,
                               convertModRefInfoToLLVM(memAttr.getErrnoMem())) |
           llvm::MemoryEffects(
diff --git a/mlir/lib/Target/LLVMIR/ModuleImport.cpp b/mlir/lib/Target/LLVMIR/ModuleImport.cpp
index 0223c1e3343c7f..b30d8e2dded480 100644
--- a/mlir/lib/Target/LLVMIR/ModuleImport.cpp
+++ b/mlir/lib/Target/LLVMIR/ModuleImport.cpp
@@ -2928,7 +2928,8 @@ static void processMemoryEffects(llvm::Function *func, LLVMFuncOp funcOp) {
   llvm::MemoryEffects memEffects = func->getMemoryEffects();
 
   auto othermem = convertModRefInfoFromLLVM(
-      memEffects.getModRef(llvm::MemoryEffects::Location::Other));
+      memEffects.getModRef(llvm::MemoryEffects::Location::Other) |
+      memEffects.getModRef(llvm::MemoryEffects::Location::ThreadIdMem));
   auto argMem = convertModRefInfoFromLLVM(
       memEffects.getModRef(llvm::MemoryEffects::Location::ArgMem));
   auto inaccessibleMem = convertModRefInfoFromLLVM(
@@ -3392,7 +3393,8 @@ LogicalResult ModuleImport::convertCallAttributes(llvm::CallInst *inst,
 
   llvm::MemoryEffects memEffects = inst->getMemoryEffects();
   ModRefInfo othermem = convertModRefInfoFromLLVM(
-      memEffects.getModRef(llvm::MemoryEffects::Location::Other));
+      memEffects.getModRef(llvm::MemoryEffects::Location::Other) |
+      memEffects.getModRef(llvm::MemoryEffects::Location::ThreadIdMem));
   ModRefInfo argMem = convertModRefInfoFromLLVM(
       memEffects.getModRef(llvm::MemoryEffects::Location::ArgMem));
   ModRefInfo inaccessibleMem = convertModRefInfoFromLLVM(
diff --git a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
index 41ead15f4ecb0d..189a3ca1388bfa 100644
--- a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
+++ b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
@@ -1822,6 +1822,9 @@ static void convertFunctionMemoryAttributes(LLVMFuncOp func,
   newMemEffects |=
       llvm::MemoryEffects(llvm::MemoryEffects::Location::Other,
                           convertModRefInfoToLLVM(memEffects.getOther()));
+  newMemEffects |=
+      llvm::MemoryEffects(llvm::MemoryEffects::Location::ThreadIdMem,
+                          convertModRefInfoToLLVM(memEffects.getOther()));
   newMemEffects |=
       llvm::MemoryEffects(llvm::MemoryEffects::Location::ErrnoMem,
                           convertModRefInfoToLLVM(memEffects.getErrnoMem()));
diff --git a/mlir/test/Target/LLVMIR/Import/function-attributes.ll b/mlir/test/Target/LLVMIR/Import/function-attributes.ll
index 86eaf58701b42b..5b2aa68e3ebbce 100644
--- a/mlir/test/Target/LLVMIR/Import/function-attributes.ll
+++ b/mlir/test/Target/LLVMIR/Import/function-attributes.ll
@@ -251,6 +251,23 @@ define void @func_memory() memory(readwrite, argmem: none) {
 
 ; // -----
 
+; The thread identity is not modeled separately and is folded into other memory.
+; CHECK-LABEL: @func_memory_threadid_write
+; CHECK-SAME:  attributes {memory_effects = #llvm.memory_effects<other = write, argMem = none, inaccessibleMem = none, errnoMem = none, targetMem0 = none, targetMem1 = none>}
+define void @func_memory_threadid_write() memory(threadid: write) {
+  ret void
+}
+
+; // -----
+
+; CHECK-LABEL: @func_memory_read_threadid_write
+; CHECK-SAME:  attributes {memory_effects = #llvm.memory_effects<other = readwrite, argMem = read, inaccessibleMem = read, errnoMem = read, targetMem0 = read, targetMem1 = read>}
+define void @func_memory_read_threadid_write() memory(read, threadid: write) {
+  ret void
+}
+
+; // -----
+
 ; CHECK-LABEL: @passthrough_combined
 ; CHECK-SAME: attributes {passthrough = [
 ; CHECK-DAG: ["alignstack", "16"]
diff --git a/mlir/test/Target/LLVMIR/Import/instructions.ll b/mlir/test/Target/LLVMIR/Import/instructions.ll
index 5dcb112cb10e63..d2abfbf63e8957 100644
--- a/mlir/test/Target/LLVMIR/Import/instructions.ll
+++ b/mlir/test/Target/LLVMIR/Import/instructions.ll
@@ -1035,6 +1035,11 @@ define void @call_memory_effects() {
   call void @f() memory(write, argmem: none)
 ; CHECK: llvm.call @f() {memory_effects = #llvm.memory_effects<other = readwrite, argMem = readwrite, inaccessibleMem = read, errnoMem = readwrite, targetMem0 = readwrite, targetMem1 = readwrite>}
   call void @f() memory(readwrite, inaccessiblemem: read)
+; The thread identity is not modeled separately and is folded into other memory.
+; CHECK: llvm.call @f() {memory_effects = #llvm.memory_effects<other = write, argMem = none, inaccessibleMem = none, errnoMem = none, targetMem0 = none, targetMem1 = none>}
+  call void @f() memory(threadid: write)
+; CHECK: llvm.call @f() {memory_effects = #llvm.memory_effects<other = readwrite, argMem = read, inaccessibleMem = read, errnoMem = read, targetMem0 = read, targetMem1 = read>}
+  call void @f() memory(read, threadid: write)
 ; CHECK: llvm.call @f()
 ; CHECK-NOT: #llvm.memory_effects
 ; CHECK-SAME: : () -> ()

>From 99b9ba7d242cd379745f1faa999a731a541f0a1b Mon Sep 17 00:00:00 2001
From: oigolovanova <oigolovanova at yandex-team.com>
Date: Mon, 23 Nov 2026 21:50:41 +0000
Subject: [PATCH 2/2] Use LF line endings

---
 llvm/unittests/Support/ModRefTest.cpp | 92 +++++++++++++--------------
 1 file changed, 46 insertions(+), 46 deletions(-)

diff --git a/llvm/unittests/Support/ModRefTest.cpp b/llvm/unittests/Support/ModRefTest.cpp
index a03d1c22c82884..7b16dd857a5c3d 100644
--- a/llvm/unittests/Support/ModRefTest.cpp
+++ b/llvm/unittests/Support/ModRefTest.cpp
@@ -1,46 +1,46 @@
-//===- llvm/unittest/Support/ModRefTest.cpp - ModRef tests ----------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#include "llvm/Support/ModRef.h"
-#include "llvm/Support/raw_ostream.h"
-#include "gtest/gtest.h"
-#include <string>
-
-using namespace llvm;
-
-namespace {
-
-// Verify that printing a MemoryEffects does not end with a ,.
-TEST(ModRefTest, PrintMemoryEffects) {
-  std::string S;
-  raw_string_ostream OS(S);
-  OS << MemoryEffects::none();
-  EXPECT_EQ(S, "ArgMem: NoModRef, InaccessibleMem: NoModRef, ErrnoMem: "
-               "NoModRef, Other: NoModRef, ThreadIdMem: NoModRef, TargetMem0: "
-               "NoModRef, TargetMem1: NoModRef");
-}
-
-TEST(ModRefTest, ThreadIdMem) {
-  MemoryEffects ME = MemoryEffects::threadIdMemOnly(ModRefInfo::Ref);
-  EXPECT_EQ(ME.getModRef(IRMemLocation::ThreadIdMem), ModRefInfo::Ref);
-  EXPECT_EQ(ME.getModRef(IRMemLocation::Other), ModRefInfo::NoModRef);
-  EXPECT_EQ(ME.getModRef(IRMemLocation::TargetMem0), ModRefInfo::NoModRef);
-  EXPECT_EQ(ME.getModRef(IRMemLocation::TargetMem1), ModRefInfo::NoModRef);
-  EXPECT_TRUE(ME.onlyReadsMemory());
-  EXPECT_FALSE(ME.onlyAccessesInaccessibleMem());
-
-  EXPECT_EQ(MemoryEffects::readOnly().getModRef(IRMemLocation::ThreadIdMem),
-            ModRefInfo::Ref);
-  EXPECT_EQ(MemoryEffects::argMemOnly().getModRef(IRMemLocation::ThreadIdMem),
-            ModRefInfo::NoModRef);
-  EXPECT_EQ(MemoryEffects::inaccessibleMemOnly().getModRef(
-                IRMemLocation::ThreadIdMem),
-            ModRefInfo::NoModRef);
-}
-
-} // namespace
+//===- llvm/unittest/Support/ModRefTest.cpp - ModRef tests ----------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/Support/ModRef.h"
+#include "llvm/Support/raw_ostream.h"
+#include "gtest/gtest.h"
+#include <string>
+
+using namespace llvm;
+
+namespace {
+
+// Verify that printing a MemoryEffects does not end with a ,.
+TEST(ModRefTest, PrintMemoryEffects) {
+  std::string S;
+  raw_string_ostream OS(S);
+  OS << MemoryEffects::none();
+  EXPECT_EQ(S, "ArgMem: NoModRef, InaccessibleMem: NoModRef, ErrnoMem: "
+               "NoModRef, Other: NoModRef, ThreadIdMem: NoModRef, TargetMem0: "
+               "NoModRef, TargetMem1: NoModRef");
+}
+
+TEST(ModRefTest, ThreadIdMem) {
+  MemoryEffects ME = MemoryEffects::threadIdMemOnly(ModRefInfo::Ref);
+  EXPECT_EQ(ME.getModRef(IRMemLocation::ThreadIdMem), ModRefInfo::Ref);
+  EXPECT_EQ(ME.getModRef(IRMemLocation::Other), ModRefInfo::NoModRef);
+  EXPECT_EQ(ME.getModRef(IRMemLocation::TargetMem0), ModRefInfo::NoModRef);
+  EXPECT_EQ(ME.getModRef(IRMemLocation::TargetMem1), ModRefInfo::NoModRef);
+  EXPECT_TRUE(ME.onlyReadsMemory());
+  EXPECT_FALSE(ME.onlyAccessesInaccessibleMem());
+
+  EXPECT_EQ(MemoryEffects::readOnly().getModRef(IRMemLocation::ThreadIdMem),
+            ModRefInfo::Ref);
+  EXPECT_EQ(MemoryEffects::argMemOnly().getModRef(IRMemLocation::ThreadIdMem),
+            ModRefInfo::NoModRef);
+  EXPECT_EQ(MemoryEffects::inaccessibleMemOnly().getModRef(
+                IRMemLocation::ThreadIdMem),
+            ModRefInfo::NoModRef);
+}
+
+} // namespace



More information about the cfe-commits mailing list