Skip to content

Commit 403a943

Browse files
authored
Don't try to apply aliasing decoration to SPIR-V instruction without return id (#1196)
Signed-off-by: Dmitry Sidorov <[email protected]>
1 parent 6eb3848 commit 403a943

File tree

3 files changed

+49
-19
lines changed

3 files changed

+49
-19
lines changed

lib/SPIRV/SPIRVWriter.cpp

+25-19
Original file line numberDiff line numberDiff line change
@@ -122,25 +122,6 @@ static SPIRVMemoryModelKind getMemoryModel(Module &M) {
122122
return SPIRVMemoryModelKind::MemoryModelMax;
123123
}
124124

125-
static bool shouldTryToAddMemAliasingDecoration(Instruction *Inst) {
126-
// Limit translation of aliasing metadata with only this set of instructions
127-
// gracefully considering others as compilation mistakes and ignoring them
128-
if (!Inst->mayReadOrWriteMemory())
129-
return false;
130-
// Loads and Stores are handled during memory access mask addition
131-
if (isa<StoreInst>(Inst) || isa<LoadInst>(Inst))
132-
return false;
133-
CallInst *CI = dyn_cast<CallInst>(Inst);
134-
if (!CI)
135-
return true;
136-
// Calls to intrinsics are skipped. At some point lifetime start/end will be
137-
// handled separately, but specification isn't ready.
138-
if (Function *Fun = CI->getCalledFunction())
139-
if (Fun->isIntrinsic())
140-
return false;
141-
return true;
142-
}
143-
144125
LLVMToSPIRVBase::LLVMToSPIRVBase(SPIRVModule *SMod)
145126
: M(nullptr), Ctx(nullptr), BM(SMod), SrcLang(0), SrcLangVer(0) {
146127
DbgTran = std::make_unique<LLVMToSPIRVDbgTran>(nullptr, SMod, this);
@@ -1963,6 +1944,31 @@ SPIRVValue *LLVMToSPIRVBase::mapValue(Value *V, SPIRVValue *BV) {
19631944
return BV;
19641945
}
19651946

1947+
bool LLVMToSPIRVBase::shouldTryToAddMemAliasingDecoration(Instruction *Inst) {
1948+
// Limit translation of aliasing metadata with only this set of instructions
1949+
// gracefully considering others as compilation mistakes and ignoring them
1950+
if (!Inst->mayReadOrWriteMemory())
1951+
return false;
1952+
// Loads and Stores are handled during memory access mask addition
1953+
if (isa<StoreInst>(Inst) || isa<LoadInst>(Inst))
1954+
return false;
1955+
CallInst *CI = dyn_cast<CallInst>(Inst);
1956+
if (!CI)
1957+
return true;
1958+
if (Function *Fun = CI->getCalledFunction()) {
1959+
// Calls to intrinsics are skipped. At some point lifetime start/end will be
1960+
// handled separately, but specification isn't ready.
1961+
if (Fun->isIntrinsic())
1962+
return false;
1963+
// Also skip SPIR-V instructions that don't have result id to attach the
1964+
// decorations
1965+
if (isBuiltinTransToInst(Fun))
1966+
if (Fun->getReturnType()->isVoidTy())
1967+
return false;
1968+
}
1969+
return true;
1970+
}
1971+
19661972
bool LLVMToSPIRVBase::transDecoration(Value *V, SPIRVValue *BV) {
19671973
if (!transAlign(V, BV))
19681974
return false;

lib/SPIRV/SPIRVWriter.h

+1
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ class LLVMToSPIRVBase {
103103
SPIRVValue *transAsmINTEL(InlineAsm *Asm);
104104
SPIRVValue *transAsmCallINTEL(CallInst *Call, SPIRVBasicBlock *BB);
105105
bool transDecoration(Value *V, SPIRVValue *BV);
106+
bool shouldTryToAddMemAliasingDecoration(Instruction *V);
106107
void transMemAliasingINTELDecorations(Instruction *V, SPIRVValue *BV);
107108
SPIRVWord transFunctionControlMask(Function *);
108109
SPIRVFunction *transFunctionDecl(Function *F);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
; The test checks if the translator won't crash
2+
3+
; RUN: llvm-as %s -o %t.bc
4+
; RUN: llvm-spirv %t.bc --spirv-ext=+SPV_INTEL_memory_access_aliasing -o %t.spv
5+
6+
; ModuleID = 'main'
7+
target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024"
8+
target triple = "spir64-unknown-unknown"
9+
10+
%class.anon = type { i8 }
11+
12+
; Function Attrs: nounwind
13+
define spir_kernel void @barrier_simple()
14+
{
15+
tail call spir_func void @_Z22__spirv_ControlBarrierjjj(i32 2, i32 2, i32 272), !noalias !1
16+
ret void
17+
}
18+
19+
declare dso_local spir_func void @_Z22__spirv_ControlBarrierjjj(i32, i32, i32)
20+
21+
!1 = !{!2}
22+
!2 = distinct !{!2, !3}
23+
!3 = distinct !{!3}

0 commit comments

Comments
 (0)