Skip to content

Commit 4c59a94

Browse files
Add check for the 'memory(argmem: write)' attribute.
1 parent 97ebe12 commit 4c59a94

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

llvm/lib/Analysis/LoopAccessAnalysis.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2277,18 +2277,24 @@ bool LoopAccessInfo::canAnalyzeLoop() {
22772277
return true;
22782278
}
22792279

2280-
/// Returns whether \p I is a known math library call that has memory write-only
2281-
/// attribute set.
2280+
/// Returns whether \p I is a known math library call that has attribute
2281+
/// 'memory(argmem: write)' set.
22822282
static bool isMathLibCallMemWriteOnly(const TargetLibraryInfo *TLI,
22832283
const Instruction &I) {
22842284
auto *Call = dyn_cast<CallInst>(&I);
22852285
if (!Call)
22862286
return false;
22872287

2288+
Function *F = Call->getCalledFunction();
2289+
if (!F->hasFnAttribute(Attribute::AttrKind::Memory))
2290+
return false;
2291+
2292+
auto ME = F->getFnAttribute(Attribute::AttrKind::Memory).getMemoryEffects();
22882293
LibFunc Func;
22892294
TLI->getLibFunc(*Call, Func);
2290-
return Func == LibFunc::LibFunc_modf || Func == LibFunc::LibFunc_modff ||
2291-
Func == LibFunc::LibFunc_frexp || Func == LibFunc::LibFunc_frexpf;
2295+
return ME.onlyWritesMemory() && ME.onlyAccessesArgPointees() &&
2296+
(Func == LibFunc::LibFunc_modf || Func == LibFunc::LibFunc_modff ||
2297+
Func == LibFunc::LibFunc_frexp || Func == LibFunc::LibFunc_frexpf);
22922298
}
22932299

22942300
void LoopAccessInfo::analyzeLoop(AAResults *AA, LoopInfo *LI,

0 commit comments

Comments
 (0)