Skip to content

Commit 39a294c

Browse files
committed
Update lit
1 parent 7cde3f5 commit 39a294c

File tree

5 files changed

+102
-82
lines changed

5 files changed

+102
-82
lines changed

llvm/include/llvm/Transforms/Instrumentation/SanitizerCommonUtils.h

-4
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@ constexpr unsigned kSpirOffloadGenericAS = 4;
2929

3030
TargetExtType *getTargetExtType(Type *Ty);
3131
bool isJointMatrixAccess(Value *V);
32-
bool isUnsupportedSPIRAccess(const Value *Addr, Instruction *I,
33-
bool InstrumentLocalPtr,
34-
bool InstrumentPrivatePtr);
35-
3632
} // namespace SanitizerCommonUtils
3733
} // namespace llvm
3834

llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp

+48-2
Original file line numberDiff line numberDiff line change
@@ -1619,6 +1619,53 @@ static bool isUnsupportedDeviceGlobal(GlobalVariable *G) {
16191619
return (!Attr.isStringAttribute() || Attr.getValueAsString() == "false");
16201620
}
16211621

1622+
static bool isUnsupportedSPIRAccess(Value *Addr, Instruction *Inst) {
1623+
// Skip SPIR-V built-in varibles
1624+
auto *OrigValue = Addr->stripInBoundsOffsets();
1625+
if (OrigValue->getName().starts_with("__spirv_BuiltIn"))
1626+
return true;
1627+
1628+
GlobalVariable *GV = dyn_cast<GlobalVariable>(OrigValue);
1629+
if (GV && isUnsupportedDeviceGlobal(GV))
1630+
return true;
1631+
1632+
// Ignore load/store for target ext type since we can't know exactly what size
1633+
// it is.
1634+
if (auto *SI = dyn_cast<StoreInst>(Inst))
1635+
if (SanitizerCommonUtils::getTargetExtType(
1636+
SI->getValueOperand()->getType()) ||
1637+
SanitizerCommonUtils::isJointMatrixAccess(SI->getPointerOperand()))
1638+
return true;
1639+
1640+
if (auto *LI = dyn_cast<LoadInst>(Inst))
1641+
if (SanitizerCommonUtils::getTargetExtType(Inst->getType()) ||
1642+
SanitizerCommonUtils::isJointMatrixAccess(LI->getPointerOperand()))
1643+
return true;
1644+
1645+
Type *PtrTy = cast<PointerType>(Addr->getType()->getScalarType());
1646+
switch (PtrTy->getPointerAddressSpace()) {
1647+
case SanitizerCommonUtils::kSpirOffloadPrivateAS: {
1648+
if (!ClSpirOffloadPrivates)
1649+
return true;
1650+
// Skip kernel arguments
1651+
return Inst->getFunction()->getCallingConv() == CallingConv::SPIR_KERNEL &&
1652+
isa<Argument>(Addr);
1653+
}
1654+
case SanitizerCommonUtils::kSpirOffloadGlobalAS: {
1655+
return !ClSpirOffloadGlobals;
1656+
}
1657+
case SanitizerCommonUtils::kSpirOffloadLocalAS: {
1658+
if (!ClSpirOffloadLocals)
1659+
return true;
1660+
return Addr->getName().starts_with("__Asan");
1661+
}
1662+
case SanitizerCommonUtils::kSpirOffloadGenericAS: {
1663+
return !ClSpirOffloadGenerics;
1664+
}
1665+
}
1666+
return true;
1667+
}
1668+
16221669
void AddressSanitizer::AppendDebugInfoToArgs(Instruction *InsertBefore,
16231670
Value *Addr,
16241671
SmallVectorImpl<Value *> &Args) {
@@ -1847,8 +1894,7 @@ bool AddressSanitizer::isInterestingAlloca(const AllocaInst &AI) {
18471894
bool AddressSanitizer::ignoreAccess(Instruction *Inst, Value *Ptr) {
18481895
// SPIR has its own rules to filter the instrument accesses
18491896
if (TargetTriple.isSPIROrSPIRV()) {
1850-
if (SanitizerCommonUtils::isUnsupportedSPIRAccess(
1851-
Ptr, Inst, ClSpirOffloadLocals, ClSpirOffloadPrivates))
1897+
if (isUnsupportedSPIRAccess(Ptr, Inst))
18521898
return true;
18531899
} else {
18541900
// Instrument accesses from different address spaces only for AMDGPU.

llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp

+39-2
Original file line numberDiff line numberDiff line change
@@ -1729,6 +1729,44 @@ static unsigned TypeSizeToSizeIndex(TypeSize TS) {
17291729
return Log2_32_Ceil((TypeSizeFixed + 7) / 8);
17301730
}
17311731

1732+
static bool isUnsupportedSPIRAccess(const Value *Addr, Instruction *I) {
1733+
if (isa<Instruction>(Addr) &&
1734+
cast<Instruction>(Addr)->getMetadata(LLVMContext::MD_nosanitize)) {
1735+
return true;
1736+
}
1737+
1738+
// Skip SPIR-V built-in varibles
1739+
auto *OrigValue = Addr->stripInBoundsOffsets();
1740+
assert(OrigValue != nullptr);
1741+
if (OrigValue->getName().starts_with("__spirv_BuiltIn"))
1742+
return true;
1743+
1744+
// Ignore load/store for target ext type since we can't know exactly what size
1745+
// it is.
1746+
if (auto *SI = dyn_cast<StoreInst>(I))
1747+
if (SanitizerCommonUtils::getTargetExtType(
1748+
SI->getValueOperand()->getType()) ||
1749+
SanitizerCommonUtils::isJointMatrixAccess(SI->getPointerOperand()))
1750+
return true;
1751+
1752+
if (auto *LI = dyn_cast<LoadInst>(I))
1753+
if (SanitizerCommonUtils::getTargetExtType(I->getType()) ||
1754+
SanitizerCommonUtils::isJointMatrixAccess(LI->getPointerOperand()))
1755+
return true;
1756+
1757+
Type *PtrTy = cast<PointerType>(Addr->getType()->getScalarType());
1758+
switch (PtrTy->getPointerAddressSpace()) {
1759+
case kSpirOffloadPrivateAS:
1760+
return !ClSpirOffloadPrivates;
1761+
case kSpirOffloadLocalAS:
1762+
return !ClSpirOffloadLocals;
1763+
case kSpirOffloadGenericAS:
1764+
return false;
1765+
}
1766+
1767+
return false;
1768+
}
1769+
17321770
static void setNoSanitizedMetadataSPIR(Instruction &I) {
17331771
const Value *Addr = nullptr;
17341772
if (const auto *LI = dyn_cast<LoadInst>(&I))
@@ -1780,8 +1818,7 @@ static void setNoSanitizedMetadataSPIR(Instruction &I) {
17801818
}
17811819
}
17821820

1783-
if (Addr && SanitizerCommonUtils::isUnsupportedSPIRAccess(
1784-
Addr, &I, ClSpirOffloadLocals, ClSpirOffloadPrivates))
1821+
if (Addr && isUnsupportedSPIRAccess(Addr, &I))
17851822
I.setNoSanitizeMetadata();
17861823
}
17871824

llvm/lib/Transforms/Instrumentation/SanitizerCommonUtils.cpp

-40
Original file line numberDiff line numberDiff line change
@@ -59,45 +59,5 @@ bool isJointMatrixAccess(Value *V) {
5959
}
6060
return false;
6161
}
62-
63-
bool isUnsupportedSPIRAccess(const Value *Addr, Instruction *I,
64-
bool InstrumentLocalPtr,
65-
bool InstrumentPrivatePtr) {
66-
if (isa<Instruction>(Addr) &&
67-
cast<Instruction>(Addr)->getMetadata(LLVMContext::MD_nosanitize)) {
68-
return true;
69-
}
70-
71-
// Skip SPIR-V built-in varibles
72-
auto *OrigValue = Addr->stripInBoundsOffsets();
73-
assert(OrigValue != nullptr);
74-
if (OrigValue->getName().starts_with("__spirv_BuiltIn"))
75-
return true;
76-
77-
// Ignore load/store for target ext type since we can't know exactly what size
78-
// it is.
79-
if (auto *SI = dyn_cast<StoreInst>(I))
80-
if (getTargetExtType(SI->getValueOperand()->getType()) ||
81-
isJointMatrixAccess(SI->getPointerOperand()))
82-
return true;
83-
84-
if (auto *LI = dyn_cast<LoadInst>(I))
85-
if (getTargetExtType(I->getType()) ||
86-
isJointMatrixAccess(LI->getPointerOperand()))
87-
return true;
88-
89-
Type *PtrTy = cast<PointerType>(Addr->getType()->getScalarType());
90-
switch (PtrTy->getPointerAddressSpace()) {
91-
case kSpirOffloadPrivateAS:
92-
return !InstrumentPrivatePtr;
93-
case kSpirOffloadLocalAS:
94-
return !InstrumentLocalPtr;
95-
case kSpirOffloadGenericAS:
96-
return false;
97-
}
98-
99-
return false;
100-
}
101-
10262
} // namespace SanitizerCommonUtils
10363
} // namespace llvm

llvm/test/Instrumentation/MemorySanitizer/SPIRV/ignore_target_ext_type.ll

+15-34
Original file line numberDiff line numberDiff line change
@@ -3,42 +3,23 @@
33
target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-n8:16:32:64-G1"
44
target triple = "spir64-unknown-unknown"
55

6-
%"struct.sycl::_V1::ext::oneapi::experimental::matrix::joint_matrix" = type { target("spirv.JointMatrixINTEL", i16, 16, 32, 0, 3, 0, 1) }
6+
%"class.sycl::_V1::ext::oneapi::bfloat16" = type { i16 }
7+
%"struct.sycl::_V1::ext::oneapi::experimental::matrix::joint_matrix" = type { target("spirv.CooperativeMatrixKHR", i16, 3, 16, 32, 0) }
78

8-
; Function Attrs: sanitize_address
9-
define spir_kernel void @_ZTS4multIN4sycl3_V13ext6oneapi8bfloat16ELm16ELm16ELm32EE() #0 {
10-
entry:
11-
; CHECK-LABEL-DAG: @_ZTS4multIN4sycl3_V13ext6oneapi8bfloat16ELm16ELm16ELm32EE
12-
; CHECK-NOT: MyAlloc
13-
%a = alloca [2 x %"struct.sycl::_V1::ext::oneapi::experimental::matrix::joint_matrix"], i32 0, align 8
14-
br label %for.cond10.i
15-
16-
for.cond10.i: ; preds = %for.cond10.i, %entry
17-
%0 = load target("spirv.JointMatrixINTEL", i16, 16, 32, 0, 3, 0, 1), ptr null, align 8
18-
store target("spirv.JointMatrixINTEL", float, 16, 16, 3, 3, 2) zeroinitializer, ptr null, align 8
19-
; CHECK-NOT: call void @asan_load
20-
; CHECK-NOT: call void @asan_store
21-
br label %for.cond10.i
22-
}
9+
; CHECK-LABEL: @test
10+
; CHECK-NOT: call i64 @__msan_get_shadow
11+
declare dso_local spir_func noundef ptr addrspace(4) @_Z19__spirv_AccessChainIN4sycl3_V13ext6oneapi8bfloat16ES4_Lm16ELm32ELN5__spv9MatrixUseE0ELNS5_5Scope4FlagE3EEPT_PPNS5_28__spirv_CooperativeMatrixKHRIT0_XT4_EXT1_EXT2_EXT3_EEEm(ptr addrspace(4) noundef, i64 noundef)
2312

24-
; Function Attrs: sanitize_address
25-
define spir_kernel void @AccessChain() #0 {
13+
define weak_odr dso_local spir_kernel void @test() {
2614
entry:
27-
; CHECK-LABEL-DAG: @AccessChain
28-
%a = alloca %"struct.sycl::_V1::ext::oneapi::experimental::matrix::joint_matrix", align 8
29-
%0 = getelementptr inbounds %"struct.sycl::_V1::ext::oneapi::experimental::matrix::joint_matrix", ptr %a, i64 0, i32 0
30-
%call.i35 = call spir_func ptr @_Z19__spirv_AccessChainIfN4sycl3_V13ext6oneapi12experimental6matrix9precision4tf32ELm8ELm8ELN5__spv9MatrixUseE0ELNS8_5Scope4FlagE3EEPT_PPNS8_28__spirv_CooperativeMatrixKHRIT0_XT4_EXT1_EXT2_EXT3_EEEm(ptr %0, i64 0)
31-
%1 = getelementptr inbounds { i16 }, ptr %call.i35, i64 0, i32 0
32-
; CHECK-NOT: call void @__asan_load
33-
; CHECK-NOT: call void @__asan_store
34-
%2 = load i16, ptr %1, align 4
35-
%call.i42 = call spir_func ptr @_Z19__spirv_AccessChainIfN4sycl3_V13ext6oneapi12experimental6matrix9precision4tf32ELm8ELm8ELN5__spv9MatrixUseE0ELNS8_5Scope4FlagE3EEPT_PPNS8_28__spirv_CooperativeMatrixKHRIT0_XT4_EXT1_EXT2_EXT3_EEEm(ptr %0, i64 0)
36-
%3 = getelementptr inbounds { i16 }, ptr %call.i42, i64 0, i32 0
37-
store i16 %2, ptr %3, align 4
15+
%sub_a.i = alloca %"struct.sycl::_V1::ext::oneapi::experimental::matrix::joint_matrix", align 8
16+
%element.i = alloca %"class.sycl::_V1::ext::oneapi::bfloat16", align 2
17+
%0 = getelementptr inbounds { i16 }, ptr %element.i, i64 0, i32 0
18+
%spvm.i = getelementptr inbounds %"struct.sycl::_V1::ext::oneapi::experimental::matrix::joint_matrix", ptr %sub_a.i, i64 0, i32 0
19+
%addrcast = addrspacecast ptr %spvm.i to ptr addrspace(4)
20+
%call.i67 = call spir_func noundef ptr addrspace(4) @_Z19__spirv_AccessChainIN4sycl3_V13ext6oneapi8bfloat16ES4_Lm16ELm32ELN5__spv9MatrixUseE0ELNS5_5Scope4FlagE3EEPT_PPNS5_28__spirv_CooperativeMatrixKHRIT0_XT4_EXT1_EXT2_EXT3_EEEm(ptr addrspace(4) noundef %addrcast, i64 1)
21+
%gep = getelementptr inbounds nuw { i16 }, ptr addrspace(4) %call.i67, i64 0, i32 0
22+
%val = load i16, ptr %0, align 2
23+
store i16 %val, ptr addrspace(4) %gep, align 2
3824
ret void
3925
}
40-
41-
declare spir_func ptr @_Z19__spirv_AccessChainIfN4sycl3_V13ext6oneapi12experimental6matrix9precision4tf32ELm8ELm8ELN5__spv9MatrixUseE0ELNS8_5Scope4FlagE3EEPT_PPNS8_28__spirv_CooperativeMatrixKHRIT0_XT4_EXT1_EXT2_EXT3_EEEm(ptr, i64)
42-
43-
attributes #0 = { sanitize_address }
44-

0 commit comments

Comments
 (0)