Skip to content

Commit e18c2f1

Browse files
Add check for the 'memory(argmem: write)' attribute.
1 parent 88d325c commit e18c2f1

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

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

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

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

0 commit comments

Comments
 (0)