@@ -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 );
@@ -1973,7 +1992,9 @@ bool LLVMToSPIRVBase::transDecoration(Value *V, SPIRVValue *BV) {
1973
1992
BV->setFPFastMathMode (M);
1974
1993
}
1975
1994
}
1976
- transMemAliasingINTELDecorations (V, BV);
1995
+ if (Instruction *Inst = dyn_cast<Instruction>(V))
1996
+ if (shouldTryToAddMemAliasingDecoration (Inst))
1997
+ transMemAliasingINTELDecorations (Inst, BV);
1977
1998
1978
1999
if (auto *CI = dyn_cast<CallInst>(V)) {
1979
2000
auto OC = BV->getOpCode ();
@@ -2001,18 +2022,11 @@ bool LLVMToSPIRVBase::transAlign(Value *V, SPIRVValue *BV) {
2001
2022
2002
2023
// Apply aliasing decorations to instructions annotated with aliasing metadata.
2003
2024
// Do it for any instruction but loads and stores.
2004
- void LLVMToSPIRVBase::transMemAliasingINTELDecorations (Value *V, SPIRVValue *BV) {
2025
+ void LLVMToSPIRVBase::transMemAliasingINTELDecorations (Instruction *Inst,
2026
+ SPIRVValue *BV) {
2005
2027
if (!BM->isAllowedToUseExtension (
2006
2028
ExtensionID::SPV_INTEL_memory_access_aliasing))
2007
2029
return ;
2008
- // Loads and Stores are handled during memory access mask addition
2009
- if (isa<StoreInst>(V) || isa<LoadInst>(V))
2010
- return ;
2011
-
2012
- Instruction *Inst = dyn_cast<Instruction>(V);
2013
- if (!Inst)
2014
- return ;
2015
-
2016
2030
if (MDNode *AliasingListMD =
2017
2031
Inst->getMetadata (LLVMContext::MD_alias_scope)) {
2018
2032
auto *MemAliasList =
0 commit comments