Skip to content

Commit d7245a2

Browse files
Add check for the 'memory(argmem: write)' attribute.
1 parent 1dc1b5c commit d7245a2

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
@@ -2380,18 +2380,24 @@ bool LoopAccessInfo::canAnalyzeLoop() {
23802380
return true;
23812381
}
23822382

2383-
/// Returns whether \p I is a known math library call that has memory write-only
2384-
/// attribute set.
2383+
/// Returns whether \p I is a known math library call that has attribute
2384+
/// 'memory(argmem: write)' set.
23852385
static bool isMathLibCallMemWriteOnly(const TargetLibraryInfo *TLI,
23862386
const Instruction &I) {
23872387
auto *Call = dyn_cast<CallInst>(&I);
23882388
if (!Call)
23892389
return false;
23902390

2391+
Function *F = Call->getCalledFunction();
2392+
if (!F->hasFnAttribute(Attribute::AttrKind::Memory))
2393+
return false;
2394+
2395+
auto ME = F->getFnAttribute(Attribute::AttrKind::Memory).getMemoryEffects();
23912396
LibFunc Func;
23922397
TLI->getLibFunc(*Call, Func);
2393-
return Func == LibFunc::LibFunc_modf || Func == LibFunc::LibFunc_modff ||
2394-
Func == LibFunc::LibFunc_frexp || Func == LibFunc::LibFunc_frexpf;
2398+
return ME.onlyWritesMemory() && ME.onlyAccessesArgPointees() &&
2399+
(Func == LibFunc::LibFunc_modf || Func == LibFunc::LibFunc_modff ||
2400+
Func == LibFunc::LibFunc_frexp || Func == LibFunc::LibFunc_frexpf);
23952401
}
23962402

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

0 commit comments

Comments
 (0)