[llvm] b05f5b9 - [FunctionAttrs] Make location classification more precise
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 13 02:31:36 PDT 2022
Author: Nikita Popov
Date: 2022-10-13T11:24:23+02:00
New Revision: b05f5b90a12098660a4fc16da0b4d421ddfe14e2
URL: https://github.com/llvm/llvm-project/commit/b05f5b90a12098660a4fc16da0b4d421ddfe14e2
DIFF: https://github.com/llvm/llvm-project/commit/b05f5b90a12098660a4fc16da0b4d421ddfe14e2.diff
LOG: [FunctionAttrs] Make location classification more precise
Don't add argmem if the pointer is clearly not an argument (e.g.
a global). I don't think this makes a difference right now, but
gives more obvious results with D135780.
Added:
Modified:
llvm/lib/Transforms/IPO/FunctionAttrs.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/IPO/FunctionAttrs.cpp b/llvm/lib/Transforms/IPO/FunctionAttrs.cpp
index 007d84a702fa..a5bf7543472c 100644
--- a/llvm/lib/Transforms/IPO/FunctionAttrs.cpp
+++ b/llvm/lib/Transforms/IPO/FunctionAttrs.cpp
@@ -139,10 +139,19 @@ checkFunctionMemoryAccess(Function &F, bool ThisBody, AAResults &AAR,
F.getAttributes().hasAttrSomewhere(Attribute::Preallocated))
MRB |= FunctionModRefBehavior::argMemOnly(ModRefInfo::ModRef);
- // Returns true if Ptr is not based on a function argument.
- auto IsArgumentOrAlloca = [](const Value *Ptr) {
+ auto AddPtrAccess = [&](const Value *Ptr, ModRefInfo MR) {
const Value *UO = getUnderlyingObject(Ptr);
- return isa<Argument>(UO) || isa<AllocaInst>(UO);
+ if (isa<AllocaInst>(UO))
+ return;
+ if (isa<Argument>(UO)) {
+ MRB |= FunctionModRefBehavior::argMemOnly(MR);
+ return;
+ }
+ // If it's not an identified object, it might be an argument.
+ if (!isIdentifiedObject(UO))
+ MRB |= FunctionModRefBehavior::argMemOnly(MR);
+ MRB |= FunctionModRefBehavior(FunctionModRefBehavior::Other, MR);
+ return;
};
// Scan the function body for instructions that may read or write memory.
for (Instruction &I : instructions(F)) {
@@ -193,9 +202,7 @@ checkFunctionMemoryAccess(Function &F, bool ThisBody, AAResults &AAR,
if (AAR.pointsToConstantMemory(Loc, /*OrLocal=*/true))
continue;
- MRB |= FunctionModRefBehavior::argMemOnly(ArgMR);
- if (!IsArgumentOrAlloca(Loc.Ptr))
- MRB |= FunctionModRefBehavior(FunctionModRefBehavior::Other, ArgMR);
+ AddPtrAccess(Loc.Ptr, ArgMR);
}
}
continue;
@@ -221,11 +228,7 @@ checkFunctionMemoryAccess(Function &F, bool ThisBody, AAResults &AAR,
if (!I.isVolatile() && AAR.pointsToConstantMemory(*Loc, /*OrLocal=*/true))
continue;
- // The accessed location can be either only argument memory, or
- // argument & other memory, but never inaccessible memory.
- MRB |= FunctionModRefBehavior::argMemOnly(MR);
- if (!IsArgumentOrAlloca(Loc->Ptr))
- MRB |= FunctionModRefBehavior(FunctionModRefBehavior::Other, MR);
+ AddPtrAccess(Loc->Ptr, MR);
}
return OrigMRB & MRB;
More information about the llvm-commits
mailing list