@@ -122,6 +122,25 @@ static SPIRVMemoryModelKind getMemoryModel(Module &M) {
122
122
return SPIRVMemoryModelKind::MemoryModelMax;
123
123
}
124
124
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
+
125
144
LLVMToSPIRVBase::LLVMToSPIRVBase (SPIRVModule *SMod)
126
145
: M(nullptr ), Ctx(nullptr ), BM(SMod), SrcLang(0 ), SrcLangVer(0 ) {
127
146
DbgTran = std::make_unique<LLVMToSPIRVDbgTran>(nullptr , SMod, this );
@@ -1956,7 +1975,9 @@ bool LLVMToSPIRVBase::transDecoration(Value *V, SPIRVValue *BV) {
1956
1975
BV->setFPFastMathMode (M);
1957
1976
}
1958
1977
}
1959
- transMemAliasingINTELDecorations (V, BV);
1978
+ if (Instruction *Inst = dyn_cast<Instruction>(V))
1979
+ if (shouldTryToAddMemAliasingDecoration (Inst))
1980
+ transMemAliasingINTELDecorations (Inst, BV);
1960
1981
1961
1982
if (auto *CI = dyn_cast<CallInst>(V)) {
1962
1983
auto OC = BV->getOpCode ();
@@ -1984,19 +2005,11 @@ bool LLVMToSPIRVBase::transAlign(Value *V, SPIRVValue *BV) {
1984
2005
1985
2006
// Apply aliasing decorations to instructions annotated with aliasing metadata.
1986
2007
// Do it for any instruction but loads and stores.
1987
- void LLVMToSPIRVBase::transMemAliasingINTELDecorations (Value *V ,
2008
+ void LLVMToSPIRVBase::transMemAliasingINTELDecorations (Instruction *Inst ,
1988
2009
SPIRVValue *BV) {
1989
2010
if (!BM->isAllowedToUseExtension (
1990
2011
ExtensionID::SPV_INTEL_memory_access_aliasing))
1991
2012
return ;
1992
- // Loads and Stores are handled during memory access mask addition
1993
- if (isa<StoreInst>(V) || isa<LoadInst>(V))
1994
- return ;
1995
-
1996
- Instruction *Inst = dyn_cast<Instruction>(V);
1997
- if (!Inst)
1998
- return ;
1999
-
2000
2013
if (MDNode *AliasingListMD =
2001
2014
Inst->getMetadata (LLVMContext::MD_alias_scope)) {
2002
2015
auto *MemAliasList =
0 commit comments