Skip to content

Commit 29051f1

Browse files
Add check for the 'memory(argmem: write)' attribute.
1 parent 13ce516 commit 29051f1

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
@@ -2326,18 +2326,24 @@ bool LoopAccessInfo::canAnalyzeLoop() {
23262326
return true;
23272327
}
23282328

2329-
/// Returns whether \p I is a known math library call that has memory write-only
2330-
/// attribute set.
2329+
/// Returns whether \p I is a known math library call that has attribute
2330+
/// 'memory(argmem: write)' set.
23312331
static bool isMathLibCallMemWriteOnly(const TargetLibraryInfo *TLI,
23322332
const Instruction &I) {
23332333
auto *Call = dyn_cast<CallInst>(&I);
23342334
if (!Call)
23352335
return false;
23362336

2337+
Function *F = Call->getCalledFunction();
2338+
if (!F->hasFnAttribute(Attribute::AttrKind::Memory))
2339+
return false;
2340+
2341+
auto ME = F->getFnAttribute(Attribute::AttrKind::Memory).getMemoryEffects();
23372342
LibFunc Func;
23382343
TLI->getLibFunc(*Call, Func);
2339-
return Func == LibFunc::LibFunc_modf || Func == LibFunc::LibFunc_modff ||
2340-
Func == LibFunc::LibFunc_frexp || Func == LibFunc::LibFunc_frexpf;
2344+
return ME.onlyWritesMemory() && ME.onlyAccessesArgPointees() &&
2345+
(Func == LibFunc::LibFunc_modf || Func == LibFunc::LibFunc_modff ||
2346+
Func == LibFunc::LibFunc_frexp || Func == LibFunc::LibFunc_frexpf);
23412347
}
23422348

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

0 commit comments

Comments
 (0)