Skip to content

Commit c3b4002

Browse files
Add check for the 'memory(argmem: write)' attribute.
1 parent 32d2b45 commit c3b4002

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

llvm/lib/Analysis/LoopAccessAnalysis.cpp

+10-4
Original file line numberDiff line numberDiff line change
@@ -2309,18 +2309,24 @@ bool LoopAccessInfo::canAnalyzeLoop() {
23092309
return true;
23102310
}
23112311

2312-
/// Returns whether \p I is a known math library call that has memory write-only
2313-
/// attribute set.
2312+
/// Returns whether \p I is a known math library call that has attribute
2313+
/// 'memory(argmem: write)' set.
23142314
static bool isMathLibCallMemWriteOnly(const TargetLibraryInfo *TLI,
23152315
const Instruction &I) {
23162316
auto *Call = dyn_cast<CallInst>(&I);
23172317
if (!Call)
23182318
return false;
23192319

2320+
Function *F = Call->getCalledFunction();
2321+
if (!F->hasFnAttribute(Attribute::AttrKind::Memory))
2322+
return false;
2323+
2324+
auto ME = F->getFnAttribute(Attribute::AttrKind::Memory).getMemoryEffects();
23202325
LibFunc Func;
23212326
TLI->getLibFunc(*Call, Func);
2322-
return Func == LibFunc::LibFunc_modf || Func == LibFunc::LibFunc_modff ||
2323-
Func == LibFunc::LibFunc_frexp || Func == LibFunc::LibFunc_frexpf;
2327+
return ME.onlyWritesMemory() && ME.onlyAccessesArgPointees() &&
2328+
(Func == LibFunc::LibFunc_modf || Func == LibFunc::LibFunc_modff ||
2329+
Func == LibFunc::LibFunc_frexp || Func == LibFunc::LibFunc_frexpf);
23242330
}
23252331

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

0 commit comments

Comments
 (0)