Skip to content

Commit 9053c7a

Browse files
Add check for the 'memory(argmem: write)' attribute.
1 parent 2a3b1e6 commit 9053c7a

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
@@ -2274,18 +2274,24 @@ bool LoopAccessInfo::canAnalyzeLoop() {
22742274
return true;
22752275
}
22762276

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

2285+
Function *F = Call->getCalledFunction();
2286+
if (!F->hasFnAttribute(Attribute::AttrKind::Memory))
2287+
return false;
2288+
2289+
auto ME = F->getFnAttribute(Attribute::AttrKind::Memory).getMemoryEffects();
22852290
LibFunc Func;
22862291
TLI->getLibFunc(*Call, Func);
2287-
return Func == LibFunc::LibFunc_modf || Func == LibFunc::LibFunc_modff ||
2288-
Func == LibFunc::LibFunc_frexp || Func == LibFunc::LibFunc_frexpf;
2292+
return ME.onlyWritesMemory() && ME.onlyAccessesArgPointees() &&
2293+
(Func == LibFunc::LibFunc_modf || Func == LibFunc::LibFunc_modff ||
2294+
Func == LibFunc::LibFunc_frexp || Func == LibFunc::LibFunc_frexpf);
22892295
}
22902296

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

0 commit comments

Comments
 (0)