https://github.com/jhuber6 created 
https://github.com/llvm/llvm-project/pull/244727

Summary:
This adds a `-csan-minimal` flag. Accesses are checked with an inlined
value comparison, and the runtime is reduced to race reporting. The
result is the smallest instrumentation that still detects races, at
the cost of coverage.


>From 146a379df2a6124eacdda49aecf403db275b0272 Mon Sep 17 00:00:00 2001
From: Joseph Huber <[email protected]>
Date: Fri, 20 Nov 2026 15:49:36 -0600
Subject: [PATCH] [compiler-rt][CSan] Add a minimal value-check configuration

Summary:
This adds a `-csan-minimal` flag. Accesses are checked with an inlined
value comparison, and the runtime is reduced to race reporting. The
result is the smallest instrumentation that still detects races, at
the cost of coverage.
---
 clang/docs/ConcurrencySanitizer.md            |   4 +-
 clang/test/CodeGen/csan-minimal.c             |  28 +
 compiler-rt/lib/csan/csan.cpp                 |  18 +
 compiler-rt/lib/csan/csan_gpu.cpp             |  10 +
 .../llvm/Analysis/TargetLibraryInfo.td        |   3 +
 llvm/lib/Analysis/TargetLibraryInfo.cpp       |   8 +
 .../Instrumentation/ConcurrencySanitizer.cpp  | 229 ++++++++-
 llvm/lib/Transforms/Utils/BuildLibCalls.cpp   |   8 +
 .../ConcurrencySanitizer/minimal.ll           | 485 ++++++++++++++++++
 .../ConcurrencySanitizer/minimal_target.ll    |  82 +++
 .../Transforms/InferFunctionAttrs/annotate.ll |   6 +
 .../Transforms/InferFunctionAttrs/no-proto.ll |   3 +
 .../Analysis/TargetLibraryInfoTest.cpp        |   1 +
 13 files changed, 876 insertions(+), 9 deletions(-)
 create mode 100644 clang/test/CodeGen/csan-minimal.c
 create mode 100644 llvm/test/Instrumentation/ConcurrencySanitizer/minimal.ll
 create mode 100644 
llvm/test/Instrumentation/ConcurrencySanitizer/minimal_target.ll

diff --git a/clang/docs/ConcurrencySanitizer.md 
b/clang/docs/ConcurrencySanitizer.md
index 5a9d2b1edabbcb..aa9ba6433c02a7 100644
--- a/clang/docs/ConcurrencySanitizer.md
+++ b/clang/docs/ConcurrencySanitizer.md
@@ -119,7 +119,9 @@ void check_access(volatile void *addr, u32 size, u32 type) {
 
 The probability of detecting a race and the overhead of the sanitizer is
 directly related to the probability of sampling and the length of the delay. 
The
-watchpoint table can be omitted to make a minimal detector with less coverage.
+minimal configuration, selected with `-mllvm -csan-minimal`, inlines the value
+comparison and reduces the runtime to race reporting. This trades race coverage
+for a smaller runtime.
 
 ## `__SANITIZE_CONCURRENCY__`
 
diff --git a/clang/test/CodeGen/csan-minimal.c 
b/clang/test/CodeGen/csan-minimal.c
new file mode 100644
index 00000000000000..143132fc1442c2
--- /dev/null
+++ b/clang/test/CodeGen/csan-minimal.c
@@ -0,0 +1,28 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 6
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -fsanitize=concurrency 
-mllvm -csan-minimal -o - %s | FileCheck %s
+
+// CHECK-LABEL: define dso_local i32 @instrumented(
+// CHECK-SAME: ptr noundef [[A:%.*]]) #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  [[ENTRY:.*:]]
+// CHECK-NEXT:    [[A_ADDR:%.*]] = alloca ptr, align 8
+// CHECK-NEXT:    store ptr [[A]], ptr [[A_ADDR]], align 8
+// CHECK-NEXT:    [[TMP0:%.*]] = load ptr, ptr [[A_ADDR]], align 8
+// CHECK-NEXT:    [[CSAN_OLD:%.*]] = load volatile i32, ptr [[TMP0]], align 4, 
!nosanitize [[META2:![0-9]+]]
+// CHECK-NEXT:    [[TMP1:%.*]] = call i32 @usleep(i32 80)
+// CHECK-NEXT:    [[CSAN_NEW:%.*]] = load volatile i32, ptr [[TMP0]], align 4, 
!nosanitize [[META2]]
+// CHECK-NEXT:    [[CSAN_CHANGED:%.*]] = icmp ne i32 [[CSAN_OLD]], [[CSAN_NEW]]
+// CHECK-NEXT:    br i1 [[CSAN_CHANGED]], label %[[BB2:.*]], label %[[BB3:.*]]
+// CHECK:       [[BB2]]:
+// CHECK-NEXT:    call void @__csan_report_race(ptr [[TMP0]], i64 4, i32 0)
+// CHECK-NEXT:    br label %[[BB3]]
+// CHECK:       [[BB3]]:
+// CHECK-NEXT:    fence syncscope("singlethread") acq_rel
+// CHECK-NEXT:    [[TMP4:%.*]] = load i32, ptr [[TMP0]], align 4
+// CHECK-NEXT:    ret i32 [[TMP4]]
+//
+int instrumented(int *a) {
+  return *a;
+}
+//.
+// CHECK: [[META2]] = !{}
+//.
diff --git a/compiler-rt/lib/csan/csan.cpp b/compiler-rt/lib/csan/csan.cpp
index 0925b6beba3542..9290de14446ac1 100644
--- a/compiler-rt/lib/csan/csan.cpp
+++ b/compiler-rt/lib/csan/csan.cpp
@@ -233,6 +233,19 @@ NOINLINE static void SetupWatchpoint(const volatile void 
*Ptr, uptr Size,
   GetHostWatchpoints().Remove(WP);
 }
 
+static void ReportRace(const volatile void *Ptr, uptr Size, int Type, uptr PC,
+                       uptr BP) {
+  if (UNLIKELY(!Ptr || !Size))
+    return;
+  Initialize();
+  if (UNLIKELY(DisableCount))
+    return;
+  ScopedDisable Disable;
+  const AccessInfo AI = MakeAccessInfo(Ptr, Size, Type, PC, BP);
+  // Equal values suppress the value-change line; the caller already compared.
+  ReportUnknownOrigin(AI, 0, 0);
+}
+
 ALWAYS_INLINE static void CheckAccess(const volatile void *Ptr, uptr Size,
                                       int Type, uptr PC, uptr BP) {
   if (UNLIKELY(!Ptr || !Size))
@@ -325,6 +338,11 @@ INTERFACE void __csan_write_range(void *Addr, uptr Size, 
int Flags) {
   __csan::CheckAccess(Addr, Size, AccessFlags(Flags, true), pc, bp);
 }
 
+INTERFACE NOINLINE void __csan_report_race(void *Addr, uptr Size, int Type) {
+  GET_CALLER_PC_BP;
+  __csan::ReportRace(Addr, Size, Type, pc, bp);
+}
+
 // TODO: Handle thread reordering checks like KCSAN.
 INTERFACE void __csan_atomic_thread_fence(int) {}
 INTERFACE void __csan_atomic_signal_fence(int) {}
diff --git a/compiler-rt/lib/csan/csan_gpu.cpp 
b/compiler-rt/lib/csan/csan_gpu.cpp
index cd881dd3362a2a..690fe66d4a5bb9 100644
--- a/compiler-rt/lib/csan/csan_gpu.cpp
+++ b/compiler-rt/lib/csan/csan_gpu.cpp
@@ -452,5 +452,15 @@ INTERFACE void __csan_write_range(void *addr, uptr size, 
int flags) {
   check_access(addr, size, access_flags(flags, true), GET_CALLER_PC());
 }
 
+INTERFACE NOINLINE void __csan_report_race(void *addr, uptr size,
+                                           int access_type) {
+  const uptr pc = GET_CALLER_PC();
+  if (!addr || !size)
+    return;
+  const u32 report_size = size > ~u32(0) ? ~u32(0) : static_cast<u32>(size);
+  report(CSAN_RACE_UNKNOWN_ORIGIN, reinterpret_cast<uptr>(addr), report_size,
+         access_type, pc);
+}
+
 INTERFACE void __csan_atomic_thread_fence(int) {}
 INTERFACE void __csan_atomic_signal_fence(int) {}
diff --git a/llvm/include/llvm/Analysis/TargetLibraryInfo.td 
b/llvm/include/llvm/Analysis/TargetLibraryInfo.td
index beaa5d1a69a0a8..1f5788789f6a5f 100644
--- a/llvm/include/llvm/Analysis/TargetLibraryInfo.td
+++ b/llvm/include/llvm/Analysis/TargetLibraryInfo.td
@@ -1649,6 +1649,9 @@ def unlink : TargetLibCall<"unlink", Int, [Ptr]>;
 /// int unsetenv(const char *name);
 def unsetenv : TargetLibCall<"unsetenv", Int, [Ptr]>;
 
+/// int usleep(useconds_t useconds);
+def usleep : TargetLibCall<"usleep", Int, [Int]>;
+
 /// int utime(const char *path, const struct utimbuf *times);
 def utime : TargetLibCall<"utime", Int, [Ptr, Ptr]>;
 
diff --git a/llvm/lib/Analysis/TargetLibraryInfo.cpp 
b/llvm/lib/Analysis/TargetLibraryInfo.cpp
index 30c9ecc35700e7..a88cd34055ac8f 100644
--- a/llvm/lib/Analysis/TargetLibraryInfo.cpp
+++ b/llvm/lib/Analysis/TargetLibraryInfo.cpp
@@ -159,6 +159,9 @@ static void initializeLibCalls(TargetLibraryInfoImpl &TLI, 
const Triple &T,
   TLI.setUnavailable(LibFunc_fputs_unlocked);
   TLI.setUnavailable(LibFunc_fgets_unlocked);
 
+  // POSIX usleep. Enabled below for hosted libcs that provide it.
+  TLI.setUnavailable(LibFunc_usleep);
+
   // There is really no runtime library on AMDGPU.
   if (T.isAMDGPU()) {
     TLI.disableAllFunctions();
@@ -708,6 +711,11 @@ static void initializeLibCalls(TargetLibraryInfoImpl &TLI, 
const Triple &T,
     TLI.setAvailable(LibFunc_fgets_unlocked);
   }
 
+  if (T.isOSLinux() || T.isOSDarwin() || T.isOSFreeBSD() || T.isOSNetBSD() ||
+      T.isOSOpenBSD() || T.isOSDragonFly() || T.isOSSolaris() || T.isOSAIX() ||
+      T.isOSHaiku() || T.isWindowsCygwinEnvironment())
+    TLI.setAvailable(LibFunc_usleep);
+
   if (T.isPS()) {
     // PS4/PS5 do have memalign.
     TLI.setAvailable(LibFunc_memalign);
diff --git a/llvm/lib/Transforms/Instrumentation/ConcurrencySanitizer.cpp 
b/llvm/lib/Transforms/Instrumentation/ConcurrencySanitizer.cpp
index 995dc45c272543..f93def8aa4b737 100644
--- a/llvm/lib/Transforms/Instrumentation/ConcurrencySanitizer.cpp
+++ b/llvm/lib/Transforms/Instrumentation/ConcurrencySanitizer.cpp
@@ -26,6 +26,8 @@
 #include "llvm/IR/Instructions.h"
 #include "llvm/IR/IntrinsicInst.h"
 #include "llvm/IR/Intrinsics.h"
+#include "llvm/IR/IntrinsicsAMDGPU.h"
+#include "llvm/IR/IntrinsicsNVPTX.h"
 #include "llvm/IR/Module.h"
 #include "llvm/ProfileData/InstrProf.h"
 #include "llvm/Support/AMDGPUAddrSpace.h"
@@ -33,6 +35,8 @@
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/NVPTXAddrSpace.h"
 #include "llvm/TargetParser/Triple.h"
+#include "llvm/Transforms/Utils/BasicBlockUtils.h"
+#include "llvm/Transforms/Utils/BuildLibCalls.h"
 #include "llvm/Transforms/Utils/EscapeEnumerator.h"
 #include "llvm/Transforms/Utils/Instrumentation.h"
 #include "llvm/Transforms/Utils/Local.h"
@@ -65,6 +69,10 @@ static cl::opt<bool> ClDistinguishVolatile(
     "csan-distinguish-volatile", cl::init(false),
     cl::desc("Treat aligned volatile accesses up to 8 bytes as atomic"),
     cl::Hidden);
+static cl::opt<bool>
+    ClMinimal("csan-minimal", cl::init(false),
+              cl::desc("Inline value checks with a report-only runtime"),
+              cl::Hidden);
 STATISTIC(NumInstrumentedReads, "Number of instrumented reads");
 STATISTIC(NumInstrumentedWrites, "Number of instrumented writes");
 STATISTIC(NumOmittedReadsBeforeWrite,
@@ -104,7 +112,8 @@ enum class AccessFlags : unsigned {
   None = 0,
   Atomic = 1u << 0,
   Compound = 1u << 1,
-  LLVM_MARK_AS_BITMASK_ENUM(Compound),
+  Write = 1u << 2,
+  LLVM_MARK_AS_BITMASK_ENUM(Write),
 };
 
 static bool isAtomicMemoryAccess(const Instruction *I) {
@@ -202,6 +211,13 @@ struct ConcurrencySanitizer {
   bool insertAccessProbe(Instruction *I, Value *Addr, Type *AccessTy,
                          const DataLayout &DL, bool IsWrite, bool IsCompound,
                          bool IsAtomic);
+  bool insertTypedValueCheck(Instruction *I, Value *Addr, Type *AccessTy,
+                             const DataLayout &DL, bool IsWrite);
+  bool insertRangeValueCheck(Instruction *I, Value *Addr, Value *ByteSize,
+                             bool IsWrite);
+  bool emitValueCheck(Instruction *I, Value *Addr, Type *LoadTy,
+                      Value *ByteSize, Align Alignment, bool IsWrite);
+  void insertInlineDelay(Instruction *InsertBefore);
   bool shouldInstrumentAddress(Value *Addr) const;
   bool shouldInstrumentAccess(Instruction *I) const;
   void insertFuncEntryExit(Function &F);
@@ -211,6 +227,7 @@ struct ConcurrencySanitizer {
   }
 
   Module *Mod = nullptr;
+  const TargetLibraryInfo *LibInfo = nullptr;
   Type *IntptrTy = nullptr;
   IntegerType *FlagsTy = nullptr;
 
@@ -242,6 +259,8 @@ struct ConcurrencySanitizer {
   FunctionCallee CsanAtomicThreadFence;
   // void __csan_atomic_signal_fence(i32);
   FunctionCallee CsanAtomicSignalFence;
+  // void __csan_report_race(ptr, intptr, i32);
+  FunctionCallee CsanReportRace;
 };
 
 void insertModuleCtor(Module &M) {
@@ -279,6 +298,10 @@ void ConcurrencySanitizer::initialize(Module &M, const 
TargetLibraryInfo &TLI) {
   IRBuilder<> IRB(M);
   Type *VoidTy = IRB.getVoidTy();
   Type *PtrTy = IRB.getPtrTy();
+  AttributeList ReportAttrs = Attr.addFnAttribute(Ctx, Attribute::NoInline)
+                                  .addFnAttribute(Ctx, Attribute::Cold);
+  CsanReportRace = M.getOrInsertFunction("__csan_report_race", ReportAttrs,
+                                         VoidTy, PtrTy, IntptrTy, FlagsTy);
   CsanFuncEntry =
       M.getOrInsertFunction("__csan_func_entry", Attr, VoidTy, PtrTy);
   CsanFuncExit = M.getOrInsertFunction("__csan_func_exit", Attr, VoidTy);
@@ -330,6 +353,7 @@ bool ConcurrencySanitizer::sanitizeFunction(Function &F,
     return false;
 
   Mod = F.getParent();
+  LibInfo = &TLI;
   MemoryAccessLists Acc;
   collectMemoryAccesses(F, Acc);
 
@@ -337,13 +361,16 @@ bool ConcurrencySanitizer::sanitizeFunction(Function &F,
       F.hasFnAttribute("sanitize_concurrency_no_checking_at_run_time");
   const bool SanitizeFunction =
       F.hasFnAttribute(Attribute::SanitizeConcurrency) && !SuppressChecking;
+  const bool CheckAtomics = ClInstrumentAtomics && !ClMinimal;
   const bool MayInstrument =
       SanitizeFunction &&
       ((ClInstrumentMemoryAccesses && !Acc.LoadsAndStores.empty()) ||
-       (ClInstrumentAtomics && !Acc.AtomicAccesses.empty()) ||
+       (CheckAtomics && !Acc.AtomicAccesses.empty()) ||
        (ClInstrumentMemIntrinsics && !Acc.MemIntrinCalls.empty()));
-  const bool NeedsRuntimeIgnores = SuppressChecking && Acc.HasCalls;
-  const bool NeedsFuncEntryExit = ClInstrumentFuncEntryExit && Acc.HasCalls;
+  const bool NeedsRuntimeIgnores =
+      SuppressChecking && Acc.HasCalls && !ClMinimal;
+  const bool NeedsFuncEntryExit =
+      ClInstrumentFuncEntryExit && Acc.HasCalls && !ClMinimal;
   if (!MayInstrument && !NeedsRuntimeIgnores && !NeedsFuncEntryExit)
     return false;
 
@@ -355,7 +382,7 @@ bool ConcurrencySanitizer::sanitizeFunction(Function &F,
     for (Instruction *I : Acc.LoadsAndStores)
       Res |= instrumentLoadOrStore(I, DL);
 
-  if (ClInstrumentAtomics && SanitizeFunction)
+  if (CheckAtomics && SanitizeFunction)
     for (Instruction *I : Acc.AtomicAccesses)
       Res |= instrumentAtomic(I, DL);
 
@@ -368,7 +395,7 @@ bool ConcurrencySanitizer::sanitizeFunction(Function &F,
     Res = true;
   }
 
-  if ((Res || Acc.HasCalls) && ClInstrumentFuncEntryExit) {
+  if (!ClMinimal && (Res || Acc.HasCalls) && ClInstrumentFuncEntryExit) {
     insertFuncEntryExit(F);
     Res = true;
   }
@@ -442,9 +469,14 @@ bool 
ConcurrencySanitizer::instrumentLoadOrStore(Instruction *I,
                                                  const DataLayout &DL) {
   const bool IsWrite = isa<StoreInst>(I);
   Value *Addr = getLoadStorePointerOperand(I);
-  if (!insertAccessProbe(I, Addr, getLoadStoreType(I), DL, IsWrite,
-                         /*IsCompound=*/false, /*IsAtomic=*/false))
+  Type *AccessTy = getLoadStoreType(I);
+  if (ClMinimal) {
+    if (!insertTypedValueCheck(I, Addr, AccessTy, DL, IsWrite))
+      return false;
+  } else if (!insertAccessProbe(I, Addr, AccessTy, DL, IsWrite,
+                                /*IsCompound=*/false, /*IsAtomic=*/false)) {
     return false;
+  }
   if (IsWrite)
     ++NumInstrumentedWrites;
   else
@@ -521,6 +553,22 @@ bool 
ConcurrencySanitizer::instrumentMemIntrinsic(IntrinsicInst *II,
     TypeSize Size = DL.getTypeAllocSize(MSP->getValue()->getType());
     Len = IRB.CreateMul(Len, IRB.CreateTypeSize(IntptrTy, Size));
   }
+  if (ClMinimal) {
+    if (MI && MI->isAtomic())
+      return false;
+    bool Changed = false;
+    if (InstrumentRead &&
+        insertRangeValueCheck(II, Src, Len, /*IsWrite=*/false)) {
+      ++NumInstrumentedReads;
+      Changed = true;
+    }
+    if (InstrumentWrite &&
+        insertRangeValueCheck(II, Dst, Len, /*IsWrite=*/true)) {
+      ++NumInstrumentedWrites;
+      Changed = true;
+    }
+    return Changed;
+  }
   Constant *Flags =
       getFlags(MI && MI->isAtomic() ? AccessFlags::Atomic : AccessFlags::None);
   if (InstrumentRead) {
@@ -534,6 +582,171 @@ bool 
ConcurrencySanitizer::instrumentMemIntrinsic(IntrinsicInst *II,
   return true;
 }
 
+// Builds a loop that spins until a timed deadline is complete.
+static void insertDeadlineLoop(Instruction *InsertBefore, Value *End,
+                               Intrinsic::ID Clock, Intrinsic::ID Wait,
+                               Value *WaitArg) {
+  BasicBlock *Pre = InsertBefore->getParent();
+  BasicBlock *Check =
+      Pre->splitBasicBlock(InsertBefore->getIterator(), "csan.delay");
+  BasicBlock *Done =
+      Check->splitBasicBlock(InsertBefore->getIterator(), "csan.delay.done");
+  BasicBlock *Body = BasicBlock::Create(Pre->getContext(), "csan.delay.body",
+                                        Pre->getParent(), Done);
+
+  Instruction *ToDone = Check->getTerminator();
+  InstrumentationIRBuilder C(ToDone);
+  Value *Now = C.CreateIntrinsic(Clock, {});
+  C.CreateCondBr(C.CreateICmpULT(Now, End, "csan.delaying"), Body, Done);
+  ToDone->eraseFromParent();
+
+  IRBuilder<> B(Body);
+  InstrumentationIRBuilder::ensureDebugInfo(B, *Pre->getParent());
+  if (WaitArg)
+    B.CreateIntrinsic(Wait, {WaitArg});
+  else
+    B.CreateIntrinsic(Wait, {});
+  B.CreateBr(Check);
+}
+
+void ConcurrencySanitizer::insertInlineDelay(Instruction *InsertBefore) {
+  Module *M = InsertBefore->getModule();
+  InstrumentationIRBuilder IRB(InsertBefore);
+  if (M->getTargetTriple().isAMDGPU()) {
+    // 1000 ticks is 10us at the 100MHz rate the device sampler assumes.
+    // s_sleep(15) is the yield that sampler uses between polls.
+    constexpr uint64_t AmdgpuDelayTicks = 1000;
+    Value *End =
+        IRB.CreateAdd(IRB.CreateIntrinsic(Intrinsic::readsteadycounter, {}),
+                      IRB.getInt64(AmdgpuDelayTicks), "csan.delay.end");
+    IRB.CreateIntrinsic(Intrinsic::amdgcn_s_sleep, {IRB.getInt32(2)});
+    insertDeadlineLoop(InsertBefore, End, Intrinsic::readsteadycounter,
+                       Intrinsic::amdgcn_s_sleep, IRB.getInt32(15));
+    return;
+  }
+  if (M->getTargetTriple().isNVPTX()) {
+    // The operand is nanoseconds. 10us is the device sampler's upper delay.
+    constexpr unsigned NvptxDelayNs = 10000;
+    IRB.CreateIntrinsic(Intrinsic::nvvm_nanosleep,
+                        {IRB.getInt32(NvptxDelayNs)});
+    return;
+  }
+
+  // Default udelay of the host sampler.
+  constexpr unsigned HostDelayUs = 80;
+  FunctionCallee USleep;
+  if (isLibFuncEmittable(M, LibInfo, LibFunc_usleep)) {
+    USleep = getOrInsertLibFunc(M, *LibInfo, LibFunc_usleep, IRB.getInt32Ty(),
+                                IRB.getInt32Ty());
+    inferNonMandatoryLibFuncAttrs(M, LibInfo->getName(LibFunc_usleep),
+                                  *LibInfo);
+  } else {
+    USleep =
+        M->getOrInsertFunction("usleep", IRB.getInt32Ty(), IRB.getInt32Ty());
+  }
+  CallInst *CI = IRB.CreateCall(USleep, {IRB.getInt32(HostDelayUs)});
+  if (auto *F = dyn_cast<Function>(USleep.getCallee()))
+    CI->setCallingConv(F->getCallingConv());
+}
+
+// A memcpy has no value type. Read at most 8 bytes, or one byte when the
+// length is not a constant.
+static Type *rangeSampleTy(LLVMContext &Ctx, Value *ByteSize) {
+  uint64_t Bytes = 1;
+  if (auto *C = dyn_cast<ConstantInt>(ByteSize)) {
+    Bytes = C->getZExtValue();
+    if (Bytes > 8)
+      Bytes = 8;
+  }
+  return Type::getIntNTy(Ctx, Bytes * 8);
+}
+
+bool ConcurrencySanitizer::insertTypedValueCheck(Instruction *I, Value *Addr,
+                                                 Type *AccessTy,
+                                                 const DataLayout &DL,
+                                                 bool IsWrite) {
+  if (Addr->isSwiftError() || !AccessTy->isSized())
+    return false;
+  TypeSize StoreSize = DL.getTypeStoreSize(AccessTy);
+  if (StoreSize.isZero())
+    return false;
+
+  // icmp has no aggregate form. Load the stored bytes as an integer.
+  Type *LoadTy = AccessTy;
+  if (!AccessTy->isIntOrIntVectorTy() && !AccessTy->isPtrOrPtrVectorTy() &&
+      !AccessTy->isFPOrFPVectorTy()) {
+    TypeSize Bits = DL.getTypeStoreSizeInBits(AccessTy);
+    if (!Bits.isFixed())
+      return false;
+    LoadTy = Type::getIntNTy(AccessTy->getContext(), Bits.getFixedValue());
+  }
+
+  InstrumentationIRBuilder IRB(I);
+  Value *ByteSize = IRB.CreateTypeSize(IntptrTy, StoreSize);
+  return emitValueCheck(I, Addr, LoadTy, ByteSize, getLoadStoreAlignment(I),
+                        IsWrite);
+}
+
+bool ConcurrencySanitizer::insertRangeValueCheck(Instruction *I, Value *Addr,
+                                                 Value *ByteSize,
+                                                 bool IsWrite) {
+  if (auto *C = dyn_cast<ConstantInt>(ByteSize)) {
+    if (C->isZero())
+      return false;
+  } else {
+    // A dynamic length may be zero.
+    InstrumentationIRBuilder IRB(I);
+    I = SplitBlockAndInsertIfThen(IRB.CreateIsNotNull(ByteSize), I,
+                                  /*Unreachable=*/false);
+  }
+  return emitValueCheck(I, Addr, rangeSampleTy(I->getContext(), ByteSize),
+                        ByteSize, Align(1), IsWrite);
+}
+
+bool ConcurrencySanitizer::emitValueCheck(Instruction *I, Value *Addr,
+                                          Type *LoadTy, Value *ByteSize,
+                                          Align Alignment, bool IsWrite) {
+  const DataLayout &DL = I->getModule()->getDataLayout();
+  MDNode *NoSanitize = MDNode::get(I->getContext(), {});
+  InstrumentationIRBuilder IRB(I);
+  LoadInst *Old = IRB.CreateAlignedLoad(LoadTy, Addr, Alignment,
+                                        /*isVolatile=*/true, "csan.old");
+  Old->setMetadata(LLVMContext::MD_nosanitize, NoSanitize);
+
+  insertInlineDelay(I);
+
+  InstrumentationIRBuilder After(I);
+  LoadInst *New = After.CreateAlignedLoad(LoadTy, Addr, Alignment,
+                                          /*isVolatile=*/true, "csan.new");
+  New->setMetadata(LLVMContext::MD_nosanitize, NoSanitize);
+
+  // Compare the raw bits. A scalable vector has no fixed integer width.
+  TypeSize Bits = DL.getTypeSizeInBits(LoadTy);
+  Type *BitTy;
+  if (Bits.isScalable())
+    BitTy = LoadTy->isPtrOrPtrVectorTy()
+                ? DL.getIntPtrType(LoadTy)
+                : VectorType::getInteger(cast<VectorType>(LoadTy));
+  else
+    BitTy = After.getIntNTy(Bits.getFixedValue());
+  Value *Changed = After.CreateICmpNE(
+      After.CreateBitPreservingCastChain(DL, Old, BitTy),
+      After.CreateBitPreservingCastChain(DL, New, BitTy), "csan.changed");
+  if (BitTy->isVectorTy())
+    Changed = After.CreateOrReduce(Changed);
+
+  Instruction *ReportTerm =
+      SplitBlockAndInsertIfThen(Changed, I, /*Unreachable=*/false);
+  InstrumentationIRBuilder Report(ReportTerm);
+  Report.CreateCall(CsanReportRace, {getCallbackAddress(Report, Addr), 
ByteSize,
+                                     getFlags(IsWrite ? AccessFlags::Write
+                                                      : AccessFlags::None)});
+
+  InstrumentationIRBuilder Tail(I);
+  Tail.CreateFence(AtomicOrdering::AcquireRelease, SyncScope::SingleThread);
+  return true;
+}
+
 bool ConcurrencySanitizer::insertAccessProbe(Instruction *I, Value *Addr,
                                              Type *AccessTy,
                                              const DataLayout &DL, bool 
IsWrite,
diff --git a/llvm/lib/Transforms/Utils/BuildLibCalls.cpp 
b/llvm/lib/Transforms/Utils/BuildLibCalls.cpp
index 824b64c5c5a309..4d397f65610b72 100644
--- a/llvm/lib/Transforms/Utils/BuildLibCalls.cpp
+++ b/llvm/lib/Transforms/Utils/BuildLibCalls.cpp
@@ -981,6 +981,10 @@ bool llvm::inferNonMandatoryLibFuncAttrs(Function &F,
     Changed |= setDoesNotCapture(F, 0);
     Changed |= setOnlyReadsMemory(F, 0);
     break;
+  case LibFunc_usleep:
+    Changed |= setRetAndArgsNoUndef(F);
+    Changed |= setDoesNotThrow(F);
+    break;
   case LibFunc_utime:
   case LibFunc_utimes:
     Changed |= setRetAndArgsNoUndef(F);
@@ -1582,6 +1586,10 @@ FunctionCallee llvm::getOrInsertLibFunc(Module *M, const 
TargetLibraryInfo &TLI,
   case LibFunc_bcmp:
     setRetExtAttr(*F, TLI);
     break;
+  case LibFunc_usleep:
+    setArgExtAttr(*F, 0, TLI, /*Signed=*/false);
+    setRetExtAttr(*F, TLI);
+    break;
   case LibFunc_calloc:
   case LibFunc_fwrite:
   case LibFunc_malloc:
diff --git a/llvm/test/Instrumentation/ConcurrencySanitizer/minimal.ll 
b/llvm/test/Instrumentation/ConcurrencySanitizer/minimal.ll
new file mode 100644
index 00000000000000..5a46eb54b664a4
--- /dev/null
+++ b/llvm/test/Instrumentation/ConcurrencySanitizer/minimal.ll
@@ -0,0 +1,485 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt < %s -passes='function(csan)' -csan-minimal -S 
-mtriple=x86_64-unknown-linux-gnu | FileCheck %s
+
+target datalayout = 
"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+define i8 @load_i8(ptr %a) sanitize_concurrency {
+; CHECK-LABEL: @load_i8(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    [[CSAN_OLD:%.*]] = load volatile i8, ptr [[A:%.*]], align 1, 
!nosanitize [[META0:![0-9]+]]
+; CHECK-NEXT:    [[TMP0:%.*]] = call i32 @usleep(i32 80)
+; CHECK-NEXT:    [[CSAN_NEW:%.*]] = load volatile i8, ptr [[A]], align 1, 
!nosanitize [[META0]]
+; CHECK-NEXT:    [[CSAN_CHANGED:%.*]] = icmp ne i8 [[CSAN_OLD]], [[CSAN_NEW]]
+; CHECK-NEXT:    br i1 [[CSAN_CHANGED]], label [[TMP1:%.*]], label [[TMP2:%.*]]
+; CHECK:       1:
+; CHECK-NEXT:    call void @__csan_report_race(ptr [[A]], i64 1, i32 0)
+; CHECK-NEXT:    br label [[TMP2]]
+; CHECK:       2:
+; CHECK-NEXT:    fence syncscope("singlethread") acq_rel
+; CHECK-NEXT:    [[V:%.*]] = load i8, ptr [[A]], align 1
+; CHECK-NEXT:    ret i8 [[V]]
+;
+entry:
+  %v = load i8, ptr %a, align 1
+  ret i8 %v
+}
+
+define i16 @load_i16(ptr %a) sanitize_concurrency {
+; CHECK-LABEL: @load_i16(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    [[CSAN_OLD:%.*]] = load volatile i16, ptr [[A:%.*]], align 2, 
!nosanitize [[META0]]
+; CHECK-NEXT:    [[TMP0:%.*]] = call i32 @usleep(i32 80)
+; CHECK-NEXT:    [[CSAN_NEW:%.*]] = load volatile i16, ptr [[A]], align 2, 
!nosanitize [[META0]]
+; CHECK-NEXT:    [[CSAN_CHANGED:%.*]] = icmp ne i16 [[CSAN_OLD]], [[CSAN_NEW]]
+; CHECK-NEXT:    br i1 [[CSAN_CHANGED]], label [[TMP1:%.*]], label [[TMP2:%.*]]
+; CHECK:       1:
+; CHECK-NEXT:    call void @__csan_report_race(ptr [[A]], i64 2, i32 0)
+; CHECK-NEXT:    br label [[TMP2]]
+; CHECK:       2:
+; CHECK-NEXT:    fence syncscope("singlethread") acq_rel
+; CHECK-NEXT:    [[V:%.*]] = load i16, ptr [[A]], align 2
+; CHECK-NEXT:    ret i16 [[V]]
+;
+entry:
+  %v = load i16, ptr %a, align 2
+  ret i16 %v
+}
+
+define i32 @load_i32(ptr %a) sanitize_concurrency {
+; CHECK-LABEL: @load_i32(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    [[CSAN_OLD:%.*]] = load volatile i32, ptr [[A:%.*]], align 4, 
!nosanitize [[META0]]
+; CHECK-NEXT:    [[TMP0:%.*]] = call i32 @usleep(i32 80)
+; CHECK-NEXT:    [[CSAN_NEW:%.*]] = load volatile i32, ptr [[A]], align 4, 
!nosanitize [[META0]]
+; CHECK-NEXT:    [[CSAN_CHANGED:%.*]] = icmp ne i32 [[CSAN_OLD]], [[CSAN_NEW]]
+; CHECK-NEXT:    br i1 [[CSAN_CHANGED]], label [[TMP1:%.*]], label [[TMP2:%.*]]
+; CHECK:       1:
+; CHECK-NEXT:    call void @__csan_report_race(ptr [[A]], i64 4, i32 0)
+; CHECK-NEXT:    br label [[TMP2]]
+; CHECK:       2:
+; CHECK-NEXT:    fence syncscope("singlethread") acq_rel
+; CHECK-NEXT:    [[V:%.*]] = load i32, ptr [[A]], align 4
+; CHECK-NEXT:    ret i32 [[V]]
+;
+entry:
+  %v = load i32, ptr %a, align 4
+  ret i32 %v
+}
+
+define i64 @load_i64(ptr %a) sanitize_concurrency {
+; CHECK-LABEL: @load_i64(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    [[CSAN_OLD:%.*]] = load volatile i64, ptr [[A:%.*]], align 8, 
!nosanitize [[META0]]
+; CHECK-NEXT:    [[TMP0:%.*]] = call i32 @usleep(i32 80)
+; CHECK-NEXT:    [[CSAN_NEW:%.*]] = load volatile i64, ptr [[A]], align 8, 
!nosanitize [[META0]]
+; CHECK-NEXT:    [[CSAN_CHANGED:%.*]] = icmp ne i64 [[CSAN_OLD]], [[CSAN_NEW]]
+; CHECK-NEXT:    br i1 [[CSAN_CHANGED]], label [[TMP1:%.*]], label [[TMP2:%.*]]
+; CHECK:       1:
+; CHECK-NEXT:    call void @__csan_report_race(ptr [[A]], i64 8, i32 0)
+; CHECK-NEXT:    br label [[TMP2]]
+; CHECK:       2:
+; CHECK-NEXT:    fence syncscope("singlethread") acq_rel
+; CHECK-NEXT:    [[V:%.*]] = load i64, ptr [[A]], align 8
+; CHECK-NEXT:    ret i64 [[V]]
+;
+entry:
+  %v = load i64, ptr %a, align 8
+  ret i64 %v
+}
+
+define void @store_i32(ptr %a, i32 %v) sanitize_concurrency {
+; CHECK-LABEL: @store_i32(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    [[CSAN_OLD:%.*]] = load volatile i32, ptr [[A:%.*]], align 4, 
!nosanitize [[META0]]
+; CHECK-NEXT:    [[TMP0:%.*]] = call i32 @usleep(i32 80)
+; CHECK-NEXT:    [[CSAN_NEW:%.*]] = load volatile i32, ptr [[A]], align 4, 
!nosanitize [[META0]]
+; CHECK-NEXT:    [[CSAN_CHANGED:%.*]] = icmp ne i32 [[CSAN_OLD]], [[CSAN_NEW]]
+; CHECK-NEXT:    br i1 [[CSAN_CHANGED]], label [[TMP1:%.*]], label [[TMP2:%.*]]
+; CHECK:       1:
+; CHECK-NEXT:    call void @__csan_report_race(ptr [[A]], i64 4, i32 4)
+; CHECK-NEXT:    br label [[TMP2]]
+; CHECK:       2:
+; CHECK-NEXT:    fence syncscope("singlethread") acq_rel
+; CHECK-NEXT:    store i32 [[V:%.*]], ptr [[A]], align 4
+; CHECK-NEXT:    ret void
+;
+entry:
+  store i32 %v, ptr %a, align 4
+  ret void
+}
+
+define float @load_float(ptr %a) sanitize_concurrency {
+; CHECK-LABEL: @load_float(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    [[CSAN_OLD:%.*]] = load volatile float, ptr [[A:%.*]], align 
4, !nosanitize [[META0]]
+; CHECK-NEXT:    [[TMP0:%.*]] = call i32 @usleep(i32 80)
+; CHECK-NEXT:    [[CSAN_NEW:%.*]] = load volatile float, ptr [[A]], align 4, 
!nosanitize [[META0]]
+; CHECK-NEXT:    [[TMP1:%.*]] = bitcast float [[CSAN_OLD]] to i32
+; CHECK-NEXT:    [[TMP2:%.*]] = bitcast float [[CSAN_NEW]] to i32
+; CHECK-NEXT:    [[CSAN_CHANGED:%.*]] = icmp ne i32 [[TMP1]], [[TMP2]]
+; CHECK-NEXT:    br i1 [[CSAN_CHANGED]], label [[TMP3:%.*]], label [[TMP4:%.*]]
+; CHECK:       3:
+; CHECK-NEXT:    call void @__csan_report_race(ptr [[A]], i64 4, i32 0)
+; CHECK-NEXT:    br label [[TMP4]]
+; CHECK:       4:
+; CHECK-NEXT:    fence syncscope("singlethread") acq_rel
+; CHECK-NEXT:    [[V:%.*]] = load float, ptr [[A]], align 4
+; CHECK-NEXT:    ret float [[V]]
+;
+entry:
+  %v = load float, ptr %a, align 4
+  ret float %v
+}
+
+define double @load_double(ptr %a) sanitize_concurrency {
+; CHECK-LABEL: @load_double(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    [[CSAN_OLD:%.*]] = load volatile double, ptr [[A:%.*]], align 
8, !nosanitize [[META0]]
+; CHECK-NEXT:    [[TMP0:%.*]] = call i32 @usleep(i32 80)
+; CHECK-NEXT:    [[CSAN_NEW:%.*]] = load volatile double, ptr [[A]], align 8, 
!nosanitize [[META0]]
+; CHECK-NEXT:    [[TMP1:%.*]] = bitcast double [[CSAN_OLD]] to i64
+; CHECK-NEXT:    [[TMP2:%.*]] = bitcast double [[CSAN_NEW]] to i64
+; CHECK-NEXT:    [[CSAN_CHANGED:%.*]] = icmp ne i64 [[TMP1]], [[TMP2]]
+; CHECK-NEXT:    br i1 [[CSAN_CHANGED]], label [[TMP3:%.*]], label [[TMP4:%.*]]
+; CHECK:       3:
+; CHECK-NEXT:    call void @__csan_report_race(ptr [[A]], i64 8, i32 0)
+; CHECK-NEXT:    br label [[TMP4]]
+; CHECK:       4:
+; CHECK-NEXT:    fence syncscope("singlethread") acq_rel
+; CHECK-NEXT:    [[V:%.*]] = load double, ptr [[A]], align 8
+; CHECK-NEXT:    ret double [[V]]
+;
+entry:
+  %v = load double, ptr %a, align 8
+  ret double %v
+}
+
+define ptr @load_ptr(ptr %a) sanitize_concurrency {
+; CHECK-LABEL: @load_ptr(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    [[CSAN_OLD:%.*]] = load volatile ptr, ptr [[A:%.*]], align 8, 
!nosanitize [[META0]]
+; CHECK-NEXT:    [[TMP0:%.*]] = call i32 @usleep(i32 80)
+; CHECK-NEXT:    [[CSAN_NEW:%.*]] = load volatile ptr, ptr [[A]], align 8, 
!nosanitize [[META0]]
+; CHECK-NEXT:    [[TMP1:%.*]] = ptrtoint ptr [[CSAN_OLD]] to i64
+; CHECK-NEXT:    [[TMP2:%.*]] = ptrtoint ptr [[CSAN_NEW]] to i64
+; CHECK-NEXT:    [[CSAN_CHANGED:%.*]] = icmp ne i64 [[TMP1]], [[TMP2]]
+; CHECK-NEXT:    br i1 [[CSAN_CHANGED]], label [[TMP3:%.*]], label [[TMP4:%.*]]
+; CHECK:       3:
+; CHECK-NEXT:    call void @__csan_report_race(ptr [[A]], i64 8, i32 0)
+; CHECK-NEXT:    br label [[TMP4]]
+; CHECK:       4:
+; CHECK-NEXT:    fence syncscope("singlethread") acq_rel
+; CHECK-NEXT:    [[V:%.*]] = load ptr, ptr [[A]], align 8
+; CHECK-NEXT:    ret ptr [[V]]
+;
+entry:
+  %v = load ptr, ptr %a, align 8
+  ret ptr %v
+}
+
+define <4 x i32> @load_v4i32(ptr %a) sanitize_concurrency {
+; CHECK-LABEL: @load_v4i32(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    [[CSAN_OLD:%.*]] = load volatile <4 x i32>, ptr [[A:%.*]], 
align 16, !nosanitize [[META0]]
+; CHECK-NEXT:    [[TMP0:%.*]] = call i32 @usleep(i32 80)
+; CHECK-NEXT:    [[CSAN_NEW:%.*]] = load volatile <4 x i32>, ptr [[A]], align 
16, !nosanitize [[META0]]
+; CHECK-NEXT:    [[TMP1:%.*]] = bitcast <4 x i32> [[CSAN_OLD]] to i128
+; CHECK-NEXT:    [[TMP2:%.*]] = bitcast <4 x i32> [[CSAN_NEW]] to i128
+; CHECK-NEXT:    [[CSAN_CHANGED:%.*]] = icmp ne i128 [[TMP1]], [[TMP2]]
+; CHECK-NEXT:    br i1 [[CSAN_CHANGED]], label [[TMP3:%.*]], label [[TMP4:%.*]]
+; CHECK:       3:
+; CHECK-NEXT:    call void @__csan_report_race(ptr [[A]], i64 16, i32 0)
+; CHECK-NEXT:    br label [[TMP4]]
+; CHECK:       4:
+; CHECK-NEXT:    fence syncscope("singlethread") acq_rel
+; CHECK-NEXT:    [[V:%.*]] = load <4 x i32>, ptr [[A]], align 16
+; CHECK-NEXT:    ret <4 x i32> [[V]]
+;
+entry:
+  %v = load <4 x i32>, ptr %a, align 16
+  ret <4 x i32> %v
+}
+
+define <4 x float> @load_v4f32(ptr %a) sanitize_concurrency {
+; CHECK-LABEL: @load_v4f32(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    [[CSAN_OLD:%.*]] = load volatile <4 x float>, ptr [[A:%.*]], 
align 16, !nosanitize [[META0]]
+; CHECK-NEXT:    [[TMP0:%.*]] = call i32 @usleep(i32 80)
+; CHECK-NEXT:    [[CSAN_NEW:%.*]] = load volatile <4 x float>, ptr [[A]], 
align 16, !nosanitize [[META0]]
+; CHECK-NEXT:    [[TMP1:%.*]] = bitcast <4 x float> [[CSAN_OLD]] to i128
+; CHECK-NEXT:    [[TMP2:%.*]] = bitcast <4 x float> [[CSAN_NEW]] to i128
+; CHECK-NEXT:    [[CSAN_CHANGED:%.*]] = icmp ne i128 [[TMP1]], [[TMP2]]
+; CHECK-NEXT:    br i1 [[CSAN_CHANGED]], label [[TMP3:%.*]], label [[TMP4:%.*]]
+; CHECK:       3:
+; CHECK-NEXT:    call void @__csan_report_race(ptr [[A]], i64 16, i32 0)
+; CHECK-NEXT:    br label [[TMP4]]
+; CHECK:       4:
+; CHECK-NEXT:    fence syncscope("singlethread") acq_rel
+; CHECK-NEXT:    [[V:%.*]] = load <4 x float>, ptr [[A]], align 16
+; CHECK-NEXT:    ret <4 x float> [[V]]
+;
+entry:
+  %v = load <4 x float>, ptr %a, align 16
+  ret <4 x float> %v
+}
+
+define <2 x ptr> @load_v2ptr(ptr %a) sanitize_concurrency {
+; CHECK-LABEL: @load_v2ptr(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    [[CSAN_OLD:%.*]] = load volatile <2 x ptr>, ptr [[A:%.*]], 
align 16, !nosanitize [[META0]]
+; CHECK-NEXT:    [[TMP0:%.*]] = call i32 @usleep(i32 80)
+; CHECK-NEXT:    [[CSAN_NEW:%.*]] = load volatile <2 x ptr>, ptr [[A]], align 
16, !nosanitize [[META0]]
+; CHECK-NEXT:    [[TMP1:%.*]] = ptrtoint <2 x ptr> [[CSAN_OLD]] to <2 x i64>
+; CHECK-NEXT:    [[TMP2:%.*]] = bitcast <2 x i64> [[TMP1]] to i128
+; CHECK-NEXT:    [[TMP3:%.*]] = ptrtoint <2 x ptr> [[CSAN_NEW]] to <2 x i64>
+; CHECK-NEXT:    [[TMP4:%.*]] = bitcast <2 x i64> [[TMP3]] to i128
+; CHECK-NEXT:    [[CSAN_CHANGED:%.*]] = icmp ne i128 [[TMP2]], [[TMP4]]
+; CHECK-NEXT:    br i1 [[CSAN_CHANGED]], label [[TMP5:%.*]], label [[TMP6:%.*]]
+; CHECK:       5:
+; CHECK-NEXT:    call void @__csan_report_race(ptr [[A]], i64 16, i32 0)
+; CHECK-NEXT:    br label [[TMP6]]
+; CHECK:       6:
+; CHECK-NEXT:    fence syncscope("singlethread") acq_rel
+; CHECK-NEXT:    [[V:%.*]] = load <2 x ptr>, ptr [[A]], align 16
+; CHECK-NEXT:    ret <2 x ptr> [[V]]
+;
+entry:
+  %v = load <2 x ptr>, ptr %a, align 16
+  ret <2 x ptr> %v
+}
+
+define <vscale x 4 x i32> @load_nxv4i32(ptr %a) sanitize_concurrency {
+; CHECK-LABEL: @load_nxv4i32(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    [[TMP0:%.*]] = call i64 @llvm.vscale.i64()
+; CHECK-NEXT:    [[TMP1:%.*]] = mul nuw i64 [[TMP0]], 16
+; CHECK-NEXT:    [[CSAN_OLD:%.*]] = load volatile <vscale x 4 x i32>, ptr 
[[A:%.*]], align 16, !nosanitize [[META0]]
+; CHECK-NEXT:    [[TMP2:%.*]] = call i32 @usleep(i32 80)
+; CHECK-NEXT:    [[CSAN_NEW:%.*]] = load volatile <vscale x 4 x i32>, ptr 
[[A]], align 16, !nosanitize [[META0]]
+; CHECK-NEXT:    [[CSAN_CHANGED:%.*]] = icmp ne <vscale x 4 x i32> 
[[CSAN_OLD]], [[CSAN_NEW]]
+; CHECK-NEXT:    [[TMP3:%.*]] = call i1 @llvm.vector.reduce.or.nxv4i1(<vscale 
x 4 x i1> [[CSAN_CHANGED]])
+; CHECK-NEXT:    br i1 [[TMP3]], label [[TMP4:%.*]], label [[TMP5:%.*]]
+; CHECK:       4:
+; CHECK-NEXT:    call void @__csan_report_race(ptr [[A]], i64 [[TMP1]], i32 0)
+; CHECK-NEXT:    br label [[TMP5]]
+; CHECK:       5:
+; CHECK-NEXT:    fence syncscope("singlethread") acq_rel
+; CHECK-NEXT:    [[V:%.*]] = load <vscale x 4 x i32>, ptr [[A]], align 16
+; CHECK-NEXT:    ret <vscale x 4 x i32> [[V]]
+;
+entry:
+  %v = load <vscale x 4 x i32>, ptr %a, align 16
+  ret <vscale x 4 x i32> %v
+}
+
+define { i32, i32 } @load_aggregate(ptr %a) sanitize_concurrency {
+; CHECK-LABEL: @load_aggregate(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    [[CSAN_OLD:%.*]] = load volatile i64, ptr [[A:%.*]], align 4, 
!nosanitize [[META0]]
+; CHECK-NEXT:    [[TMP0:%.*]] = call i32 @usleep(i32 80)
+; CHECK-NEXT:    [[CSAN_NEW:%.*]] = load volatile i64, ptr [[A]], align 4, 
!nosanitize [[META0]]
+; CHECK-NEXT:    [[CSAN_CHANGED:%.*]] = icmp ne i64 [[CSAN_OLD]], [[CSAN_NEW]]
+; CHECK-NEXT:    br i1 [[CSAN_CHANGED]], label [[TMP1:%.*]], label [[TMP2:%.*]]
+; CHECK:       1:
+; CHECK-NEXT:    call void @__csan_report_race(ptr [[A]], i64 8, i32 0)
+; CHECK-NEXT:    br label [[TMP2]]
+; CHECK:       2:
+; CHECK-NEXT:    fence syncscope("singlethread") acq_rel
+; CHECK-NEXT:    [[V:%.*]] = load { i32, i32 }, ptr [[A]], align 4
+; CHECK-NEXT:    ret { i32, i32 } [[V]]
+;
+entry:
+  %v = load { i32, i32 }, ptr %a, align 4
+  ret { i32, i32 } %v
+}
+
+define i32 @load_unaligned(ptr %a) sanitize_concurrency {
+; CHECK-LABEL: @load_unaligned(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    [[CSAN_OLD:%.*]] = load volatile i32, ptr [[A:%.*]], align 1, 
!nosanitize [[META0]]
+; CHECK-NEXT:    [[TMP0:%.*]] = call i32 @usleep(i32 80)
+; CHECK-NEXT:    [[CSAN_NEW:%.*]] = load volatile i32, ptr [[A]], align 1, 
!nosanitize [[META0]]
+; CHECK-NEXT:    [[CSAN_CHANGED:%.*]] = icmp ne i32 [[CSAN_OLD]], [[CSAN_NEW]]
+; CHECK-NEXT:    br i1 [[CSAN_CHANGED]], label [[TMP1:%.*]], label [[TMP2:%.*]]
+; CHECK:       1:
+; CHECK-NEXT:    call void @__csan_report_race(ptr [[A]], i64 4, i32 0)
+; CHECK-NEXT:    br label [[TMP2]]
+; CHECK:       2:
+; CHECK-NEXT:    fence syncscope("singlethread") acq_rel
+; CHECK-NEXT:    [[V:%.*]] = load i32, ptr [[A]], align 1
+; CHECK-NEXT:    ret i32 [[V]]
+;
+entry:
+  %v = load i32, ptr %a, align 1
+  ret i32 %v
+}
+
+define void @memcpy_i32(ptr %dst, ptr %src) sanitize_concurrency {
+; CHECK-LABEL: @memcpy_i32(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    [[CSAN_OLD:%.*]] = load volatile i32, ptr [[SRC:%.*]], align 
1, !nosanitize [[META0]]
+; CHECK-NEXT:    [[TMP0:%.*]] = call i32 @usleep(i32 80)
+; CHECK-NEXT:    [[CSAN_NEW:%.*]] = load volatile i32, ptr [[SRC]], align 1, 
!nosanitize [[META0]]
+; CHECK-NEXT:    [[CSAN_CHANGED:%.*]] = icmp ne i32 [[CSAN_OLD]], [[CSAN_NEW]]
+; CHECK-NEXT:    br i1 [[CSAN_CHANGED]], label [[TMP1:%.*]], label [[TMP2:%.*]]
+; CHECK:       1:
+; CHECK-NEXT:    call void @__csan_report_race(ptr [[SRC]], i64 4, i32 0)
+; CHECK-NEXT:    br label [[TMP2]]
+; CHECK:       2:
+; CHECK-NEXT:    fence syncscope("singlethread") acq_rel
+; CHECK-NEXT:    [[CSAN_OLD1:%.*]] = load volatile i32, ptr [[DST:%.*]], align 
1, !nosanitize [[META0]]
+; CHECK-NEXT:    [[TMP3:%.*]] = call i32 @usleep(i32 80)
+; CHECK-NEXT:    [[CSAN_NEW2:%.*]] = load volatile i32, ptr [[DST]], align 1, 
!nosanitize [[META0]]
+; CHECK-NEXT:    [[CSAN_CHANGED3:%.*]] = icmp ne i32 [[CSAN_OLD1]], 
[[CSAN_NEW2]]
+; CHECK-NEXT:    br i1 [[CSAN_CHANGED3]], label [[TMP4:%.*]], label 
[[TMP5:%.*]]
+; CHECK:       4:
+; CHECK-NEXT:    call void @__csan_report_race(ptr [[DST]], i64 4, i32 4)
+; CHECK-NEXT:    br label [[TMP5]]
+; CHECK:       5:
+; CHECK-NEXT:    fence syncscope("singlethread") acq_rel
+; CHECK-NEXT:    call void @llvm.memcpy.p0.p0.i64(ptr [[DST]], ptr [[SRC]], 
i64 4, i1 false)
+; CHECK-NEXT:    ret void
+;
+entry:
+  call void @llvm.memcpy.p0.p0.i64(ptr %dst, ptr %src, i64 4, i1 false)
+  ret void
+}
+
+define void @memcpy_i24(ptr %dst, ptr %src) sanitize_concurrency {
+; CHECK-LABEL: @memcpy_i24(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    [[CSAN_OLD:%.*]] = load volatile i24, ptr [[SRC:%.*]], align 
1, !nosanitize [[META0]]
+; CHECK-NEXT:    [[TMP0:%.*]] = call i32 @usleep(i32 80)
+; CHECK-NEXT:    [[CSAN_NEW:%.*]] = load volatile i24, ptr [[SRC]], align 1, 
!nosanitize [[META0]]
+; CHECK-NEXT:    [[CSAN_CHANGED:%.*]] = icmp ne i24 [[CSAN_OLD]], [[CSAN_NEW]]
+; CHECK-NEXT:    br i1 [[CSAN_CHANGED]], label [[TMP1:%.*]], label [[TMP2:%.*]]
+; CHECK:       1:
+; CHECK-NEXT:    call void @__csan_report_race(ptr [[SRC]], i64 3, i32 0)
+; CHECK-NEXT:    br label [[TMP2]]
+; CHECK:       2:
+; CHECK-NEXT:    fence syncscope("singlethread") acq_rel
+; CHECK-NEXT:    [[CSAN_OLD1:%.*]] = load volatile i24, ptr [[DST:%.*]], align 
1, !nosanitize [[META0]]
+; CHECK-NEXT:    [[TMP3:%.*]] = call i32 @usleep(i32 80)
+; CHECK-NEXT:    [[CSAN_NEW2:%.*]] = load volatile i24, ptr [[DST]], align 1, 
!nosanitize [[META0]]
+; CHECK-NEXT:    [[CSAN_CHANGED3:%.*]] = icmp ne i24 [[CSAN_OLD1]], 
[[CSAN_NEW2]]
+; CHECK-NEXT:    br i1 [[CSAN_CHANGED3]], label [[TMP4:%.*]], label 
[[TMP5:%.*]]
+; CHECK:       4:
+; CHECK-NEXT:    call void @__csan_report_race(ptr [[DST]], i64 3, i32 4)
+; CHECK-NEXT:    br label [[TMP5]]
+; CHECK:       5:
+; CHECK-NEXT:    fence syncscope("singlethread") acq_rel
+; CHECK-NEXT:    call void @llvm.memcpy.p0.p0.i64(ptr [[DST]], ptr [[SRC]], 
i64 3, i1 false)
+; CHECK-NEXT:    ret void
+;
+entry:
+  call void @llvm.memcpy.p0.p0.i64(ptr %dst, ptr %src, i64 3, i1 false)
+  ret void
+}
+
+define void @memcpy_capped(ptr %dst, ptr %src) sanitize_concurrency {
+; CHECK-LABEL: @memcpy_capped(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    [[CSAN_OLD:%.*]] = load volatile i64, ptr [[SRC:%.*]], align 
1, !nosanitize [[META0]]
+; CHECK-NEXT:    [[TMP0:%.*]] = call i32 @usleep(i32 80)
+; CHECK-NEXT:    [[CSAN_NEW:%.*]] = load volatile i64, ptr [[SRC]], align 1, 
!nosanitize [[META0]]
+; CHECK-NEXT:    [[CSAN_CHANGED:%.*]] = icmp ne i64 [[CSAN_OLD]], [[CSAN_NEW]]
+; CHECK-NEXT:    br i1 [[CSAN_CHANGED]], label [[TMP1:%.*]], label [[TMP2:%.*]]
+; CHECK:       1:
+; CHECK-NEXT:    call void @__csan_report_race(ptr [[SRC]], i64 32, i32 0)
+; CHECK-NEXT:    br label [[TMP2]]
+; CHECK:       2:
+; CHECK-NEXT:    fence syncscope("singlethread") acq_rel
+; CHECK-NEXT:    [[CSAN_OLD1:%.*]] = load volatile i64, ptr [[DST:%.*]], align 
1, !nosanitize [[META0]]
+; CHECK-NEXT:    [[TMP3:%.*]] = call i32 @usleep(i32 80)
+; CHECK-NEXT:    [[CSAN_NEW2:%.*]] = load volatile i64, ptr [[DST]], align 1, 
!nosanitize [[META0]]
+; CHECK-NEXT:    [[CSAN_CHANGED3:%.*]] = icmp ne i64 [[CSAN_OLD1]], 
[[CSAN_NEW2]]
+; CHECK-NEXT:    br i1 [[CSAN_CHANGED3]], label [[TMP4:%.*]], label 
[[TMP5:%.*]]
+; CHECK:       4:
+; CHECK-NEXT:    call void @__csan_report_race(ptr [[DST]], i64 32, i32 4)
+; CHECK-NEXT:    br label [[TMP5]]
+; CHECK:       5:
+; CHECK-NEXT:    fence syncscope("singlethread") acq_rel
+; CHECK-NEXT:    call void @llvm.memcpy.p0.p0.i64(ptr [[DST]], ptr [[SRC]], 
i64 32, i1 false)
+; CHECK-NEXT:    ret void
+;
+entry:
+  call void @llvm.memcpy.p0.p0.i64(ptr %dst, ptr %src, i64 32, i1 false)
+  ret void
+}
+
+define void @memcpy_dynamic(ptr %dst, ptr %src, i64 %n) sanitize_concurrency {
+; CHECK-LABEL: @memcpy_dynamic(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    [[TMP0:%.*]] = icmp ne i64 [[N:%.*]], 0
+; CHECK-NEXT:    br i1 [[TMP0]], label [[TMP1:%.*]], label [[TMP5:%.*]]
+; CHECK:       1:
+; CHECK-NEXT:    [[CSAN_OLD:%.*]] = load volatile i8, ptr [[SRC:%.*]], align 
1, !nosanitize [[META0]]
+; CHECK-NEXT:    [[TMP2:%.*]] = call i32 @usleep(i32 80)
+; CHECK-NEXT:    [[CSAN_NEW:%.*]] = load volatile i8, ptr [[SRC]], align 1, 
!nosanitize [[META0]]
+; CHECK-NEXT:    [[CSAN_CHANGED:%.*]] = icmp ne i8 [[CSAN_OLD]], [[CSAN_NEW]]
+; CHECK-NEXT:    br i1 [[CSAN_CHANGED]], label [[TMP3:%.*]], label [[TMP4:%.*]]
+; CHECK:       3:
+; CHECK-NEXT:    call void @__csan_report_race(ptr [[SRC]], i64 [[N]], i32 0)
+; CHECK-NEXT:    br label [[TMP4]]
+; CHECK:       4:
+; CHECK-NEXT:    fence syncscope("singlethread") acq_rel
+; CHECK-NEXT:    br label [[TMP5]]
+; CHECK:       5:
+; CHECK-NEXT:    [[TMP6:%.*]] = icmp ne i64 [[N]], 0
+; CHECK-NEXT:    br i1 [[TMP6]], label [[TMP7:%.*]], label [[TMP11:%.*]]
+; CHECK:       7:
+; CHECK-NEXT:    [[CSAN_OLD1:%.*]] = load volatile i8, ptr [[DST:%.*]], align 
1, !nosanitize [[META0]]
+; CHECK-NEXT:    [[TMP8:%.*]] = call i32 @usleep(i32 80)
+; CHECK-NEXT:    [[CSAN_NEW2:%.*]] = load volatile i8, ptr [[DST]], align 1, 
!nosanitize [[META0]]
+; CHECK-NEXT:    [[CSAN_CHANGED3:%.*]] = icmp ne i8 [[CSAN_OLD1]], 
[[CSAN_NEW2]]
+; CHECK-NEXT:    br i1 [[CSAN_CHANGED3]], label [[TMP9:%.*]], label 
[[TMP10:%.*]]
+; CHECK:       9:
+; CHECK-NEXT:    call void @__csan_report_race(ptr [[DST]], i64 [[N]], i32 4)
+; CHECK-NEXT:    br label [[TMP10]]
+; CHECK:       10:
+; CHECK-NEXT:    fence syncscope("singlethread") acq_rel
+; CHECK-NEXT:    br label [[TMP11]]
+; CHECK:       11:
+; CHECK-NEXT:    call void @llvm.memcpy.p0.p0.i64(ptr [[DST]], ptr [[SRC]], 
i64 [[N]], i1 false)
+; CHECK-NEXT:    ret void
+;
+entry:
+  call void @llvm.memcpy.p0.p0.i64(ptr %dst, ptr %src, i64 %n, i1 false)
+  ret void
+}
+
+define void @memcpy_zero(ptr %dst, ptr %src) sanitize_concurrency {
+; CHECK-LABEL: @memcpy_zero(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    call void @llvm.memcpy.p0.p0.i64(ptr [[DST:%.*]], ptr 
[[SRC:%.*]], i64 0, i1 false)
+; CHECK-NEXT:    ret void
+;
+entry:
+  call void @llvm.memcpy.p0.p0.i64(ptr %dst, ptr %src, i64 0, i1 false)
+  ret void
+}
+
+define i32 @atomic_load(ptr %a) sanitize_concurrency {
+; CHECK-LABEL: @atomic_load(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    [[V:%.*]] = load atomic i32, ptr [[A:%.*]] seq_cst, align 4
+; CHECK-NEXT:    ret i32 [[V]]
+;
+entry:
+  %v = load atomic i32, ptr %a seq_cst, align 4
+  ret i32 %v
+}
+
+define i32 @unsanitized(ptr %a) {
+; CHECK-LABEL: @unsanitized(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    [[V:%.*]] = load i32, ptr [[A:%.*]], align 4
+; CHECK-NEXT:    ret i32 [[V]]
+;
+entry:
+  %v = load i32, ptr %a, align 4
+  ret i32 %v
+}
+
+declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr 
noalias nocapture readonly, i64, i1 immarg)
diff --git a/llvm/test/Instrumentation/ConcurrencySanitizer/minimal_target.ll 
b/llvm/test/Instrumentation/ConcurrencySanitizer/minimal_target.ll
new file mode 100644
index 00000000000000..17af5d69c405be
--- /dev/null
+++ b/llvm/test/Instrumentation/ConcurrencySanitizer/minimal_target.ll
@@ -0,0 +1,82 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt < %s -passes='function(csan)' -csan-minimal -S 
-mtriple=x86_64-unknown-linux-gnu | FileCheck %s --check-prefixes=X64
+; RUN: opt < %s -passes='function(csan)' -csan-minimal -S 
-mtriple=aarch64-unknown-linux-gnu | FileCheck %s --check-prefixes=AARCH64
+; RUN: opt < %s -passes='function(csan)' -csan-minimal -S 
-mtriple=amdgpu-amd-amdhsa | FileCheck %s --check-prefixes=AMDGPU
+; RUN: opt < %s -passes='function(csan)' -csan-minimal -S 
-mtriple=nvptx64-nvidia-cuda | FileCheck %s --check-prefixes=NVPTX
+
+define void @load(ptr %a) sanitize_concurrency {
+; X64-LABEL: @load(
+; X64-NEXT:  entry:
+; X64-NEXT:    [[CSAN_OLD:%.*]] = load volatile i32, ptr [[A:%.*]], align 4, 
!nosanitize [[META0:![0-9]+]]
+; X64-NEXT:    [[TMP0:%.*]] = call i32 @usleep(i32 80)
+; X64-NEXT:    [[CSAN_NEW:%.*]] = load volatile i32, ptr [[A]], align 4, 
!nosanitize [[META0]]
+; X64-NEXT:    [[CSAN_CHANGED:%.*]] = icmp ne i32 [[CSAN_OLD]], [[CSAN_NEW]]
+; X64-NEXT:    br i1 [[CSAN_CHANGED]], label [[TMP1:%.*]], label [[TMP2:%.*]]
+; X64:       1:
+; X64-NEXT:    call void @__csan_report_race(ptr [[A]], i64 4, i32 0)
+; X64-NEXT:    br label [[TMP2]]
+; X64:       2:
+; X64-NEXT:    fence syncscope("singlethread") acq_rel
+; X64-NEXT:    [[V:%.*]] = load i32, ptr [[A]], align 4
+; X64-NEXT:    ret void
+;
+; AARCH64-LABEL: @load(
+; AARCH64-NEXT:  entry:
+; AARCH64-NEXT:    [[CSAN_OLD:%.*]] = load volatile i32, ptr [[A:%.*]], align 
4, !nosanitize [[META0:![0-9]+]]
+; AARCH64-NEXT:    [[TMP0:%.*]] = call i32 @usleep(i32 80)
+; AARCH64-NEXT:    [[CSAN_NEW:%.*]] = load volatile i32, ptr [[A]], align 4, 
!nosanitize [[META0]]
+; AARCH64-NEXT:    [[CSAN_CHANGED:%.*]] = icmp ne i32 [[CSAN_OLD]], 
[[CSAN_NEW]]
+; AARCH64-NEXT:    br i1 [[CSAN_CHANGED]], label [[TMP1:%.*]], label 
[[TMP2:%.*]]
+; AARCH64:       1:
+; AARCH64-NEXT:    call void @__csan_report_race(ptr [[A]], i64 4, i32 0)
+; AARCH64-NEXT:    br label [[TMP2]]
+; AARCH64:       2:
+; AARCH64-NEXT:    fence syncscope("singlethread") acq_rel
+; AARCH64-NEXT:    [[V:%.*]] = load i32, ptr [[A]], align 4
+; AARCH64-NEXT:    ret void
+;
+; AMDGPU-LABEL: @load(
+; AMDGPU-NEXT:  entry:
+; AMDGPU-NEXT:    [[CSAN_OLD:%.*]] = load volatile i32, ptr [[A:%.*]], align 
4, !nosanitize [[META0:![0-9]+]]
+; AMDGPU-NEXT:    [[TMP0:%.*]] = call i64 @llvm.readsteadycounter()
+; AMDGPU-NEXT:    [[CSAN_DELAY_END:%.*]] = add i64 [[TMP0]], 1000
+; AMDGPU-NEXT:    call void @llvm.amdgcn.s.sleep(i32 2)
+; AMDGPU-NEXT:    br label [[CSAN_DELAY:%.*]]
+; AMDGPU:       csan.delay:
+; AMDGPU-NEXT:    [[TMP1:%.*]] = call i64 @llvm.readsteadycounter()
+; AMDGPU-NEXT:    [[CSAN_DELAYING:%.*]] = icmp ult i64 [[TMP1]], 
[[CSAN_DELAY_END]]
+; AMDGPU-NEXT:    br i1 [[CSAN_DELAYING]], label [[CSAN_DELAY_BODY:%.*]], 
label [[CSAN_DELAY_DONE:%.*]]
+; AMDGPU:       csan.delay.body:
+; AMDGPU-NEXT:    call void @llvm.amdgcn.s.sleep(i32 15)
+; AMDGPU-NEXT:    br label [[CSAN_DELAY]]
+; AMDGPU:       csan.delay.done:
+; AMDGPU-NEXT:    [[CSAN_NEW:%.*]] = load volatile i32, ptr [[A]], align 4, 
!nosanitize [[META0]]
+; AMDGPU-NEXT:    [[CSAN_CHANGED:%.*]] = icmp ne i32 [[CSAN_OLD]], [[CSAN_NEW]]
+; AMDGPU-NEXT:    br i1 [[CSAN_CHANGED]], label [[TMP2:%.*]], label 
[[TMP3:%.*]]
+; AMDGPU:       2:
+; AMDGPU-NEXT:    call void @__csan_report_race(ptr [[A]], i64 4, i32 0)
+; AMDGPU-NEXT:    br label [[TMP3]]
+; AMDGPU:       3:
+; AMDGPU-NEXT:    fence syncscope("singlethread") acq_rel
+; AMDGPU-NEXT:    [[V:%.*]] = load i32, ptr [[A]], align 4
+; AMDGPU-NEXT:    ret void
+;
+; NVPTX-LABEL: @load(
+; NVPTX-NEXT:  entry:
+; NVPTX-NEXT:    [[CSAN_OLD:%.*]] = load volatile i32, ptr [[A:%.*]], align 4, 
!nosanitize [[META0:![0-9]+]]
+; NVPTX-NEXT:    call void @llvm.nvvm.nanosleep(i32 10000)
+; NVPTX-NEXT:    [[CSAN_NEW:%.*]] = load volatile i32, ptr [[A]], align 4, 
!nosanitize [[META0]]
+; NVPTX-NEXT:    [[CSAN_CHANGED:%.*]] = icmp ne i32 [[CSAN_OLD]], [[CSAN_NEW]]
+; NVPTX-NEXT:    br i1 [[CSAN_CHANGED]], label [[TMP0:%.*]], label [[TMP1:%.*]]
+; NVPTX:       0:
+; NVPTX-NEXT:    call void @__csan_report_race(ptr [[A]], i64 4, i32 0)
+; NVPTX-NEXT:    br label [[TMP1]]
+; NVPTX:       1:
+; NVPTX-NEXT:    fence syncscope("singlethread") acq_rel
+; NVPTX-NEXT:    [[V:%.*]] = load i32, ptr [[A]], align 4
+; NVPTX-NEXT:    ret void
+;
+entry:
+  %v = load i32, ptr %a, align 4
+  ret void
+}
diff --git a/llvm/test/Transforms/InferFunctionAttrs/annotate.ll 
b/llvm/test/Transforms/InferFunctionAttrs/annotate.ll
index 86c1ae3ed67fed..aa61eb4ea7ea77 100644
--- a/llvm/test/Transforms/InferFunctionAttrs/annotate.ll
+++ b/llvm/test/Transforms/InferFunctionAttrs/annotate.ll
@@ -1158,6 +1158,12 @@ declare i32 @unlink(ptr)
 ; CHECK: declare noundef i32 @unsetenv(ptr noundef readonly captures(none)) 
[[NOFREE_NOUNWIND]]
 declare i32 @unsetenv(ptr)
 
+; CHECK-LINUX: declare noundef i32 @usleep(i32 noundef) [[NOFREE_NOUNWIND]]
+; CHECK-DARWIN: declare noundef i32 @usleep(i32 noundef) [[NOFREE_NOUNWIND]]
+; CHECK-UNKNOWN: declare i32 @usleep(i32)
+; CHECK-NVPTX: declare i32 @usleep(i32)
+declare i32 @usleep(i32)
+
 ; CHECK: declare noundef i32 @utime(ptr noundef readonly captures(none), ptr 
noundef readonly captures(none)) [[NOFREE_NOUNWIND]]
 declare i32 @utime(ptr, ptr)
 
diff --git a/llvm/test/Transforms/InferFunctionAttrs/no-proto.ll 
b/llvm/test/Transforms/InferFunctionAttrs/no-proto.ll
index 898d83f3fb8aed..15261fed793537 100644
--- a/llvm/test/Transforms/InferFunctionAttrs/no-proto.ll
+++ b/llvm/test/Transforms/InferFunctionAttrs/no-proto.ll
@@ -945,6 +945,9 @@ declare void @unlink(...)
 ; CHECK: declare void @unsetenv(...)
 declare void @unsetenv(...)
 
+; CHECK: declare void @usleep(...)
+declare void @usleep(...)
+
 ; CHECK: declare void @utime(...)
 declare void @utime(...)
 
diff --git a/llvm/unittests/Analysis/TargetLibraryInfoTest.cpp 
b/llvm/unittests/Analysis/TargetLibraryInfoTest.cpp
index 62c2b52decccac..2e918787d2672d 100644
--- a/llvm/unittests/Analysis/TargetLibraryInfoTest.cpp
+++ b/llvm/unittests/Analysis/TargetLibraryInfoTest.cpp
@@ -465,6 +465,7 @@ TEST_F(TargetLibraryInfoTest, ValidProto) {
       "declare i32 @uname(ptr)\n"
       "declare i32 @ungetc(i32, ptr)\n"
       "declare i32 @unlink(ptr)\n"
+      "declare i32 @usleep(i32)\n"
       "declare i32 @utime(ptr, ptr)\n"
       "declare i32 @utimes(ptr, ptr)\n"
       "declare ptr @valloc(i64)\n"

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to