[PATCH] D15912: [BasicAA/MDA] Sink aliasing rules for malloc and calloc into BasicAA
Philip Reames via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 9 15:24:57 PST 2016
This revision was automatically updated to reflect the committed changes.
Closed by commit rL263075: [BasicAA/MDA] Sink aliasing rules for malloc and calloc into BasicAA (authored by reames).
Changed prior to commit:
http://reviews.llvm.org/D15912?vs=44081&id=50207#toc
Repository:
rL LLVM
http://reviews.llvm.org/D15912
Files:
llvm/trunk/lib/Analysis/BasicAliasAnalysis.cpp
llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp
Index: llvm/trunk/lib/Analysis/BasicAliasAnalysis.cpp
===================================================================
--- llvm/trunk/lib/Analysis/BasicAliasAnalysis.cpp
+++ llvm/trunk/lib/Analysis/BasicAliasAnalysis.cpp
@@ -760,6 +760,20 @@
return MRI_NoModRef;
}
+ // If the CallSite is to malloc or calloc, we can assume that it doesn't
+ // modify any IR visible value. This is only valid because we assume these
+ // routines do not read values visible in the IR. TODO: Consider special
+ // casing realloc and strdup routines which access only their arguments as
+ // well. Or alternatively, replace all of this with inaccessiblememonly once
+ // that's implemented fully.
+ auto *Inst = CS.getInstruction();
+ if (isMallocLikeFn(Inst, &TLI) || isCallocLikeFn(Inst, &TLI)) {
+ // Be conservative if the accessed pointer may alias the allocation -
+ // fallback to the generic handling below.
+ if (getBestAAResults().alias(MemoryLocation(Inst), Loc) == NoAlias)
+ return MRI_NoModRef;
+ }
+
// While the assume intrinsic is marked as arbitrarily writing so that
// proper control dependencies will be maintained, it never aliases any
// particular memory location.
Index: llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp
===================================================================
--- llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp
+++ llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp
@@ -669,26 +669,13 @@
// If this is an allocation, and if we know that the accessed pointer is to
// the allocation, return Def. This means that there is no dependence and
// the access can be optimized based on that. For example, a load could
- // turn into undef.
- // Note: Only determine this to be a malloc if Inst is the malloc call, not
- // a subsequent bitcast of the malloc call result. There can be stores to
- // the malloced memory between the malloc call and its bitcast uses, and we
- // need to continue scanning until the malloc call.
+ // turn into undef. Note that we can bypass the allocation itself when
+ // looking for a clobber in many cases; that's an alias property and is
+ // handled by BasicAA.
if (isa<AllocaInst>(Inst) || isNoAliasFn(Inst, TLI)) {
const Value *AccessPtr = GetUnderlyingObject(MemLoc.Ptr, DL);
-
if (AccessPtr == Inst || AA->isMustAlias(Inst, AccessPtr))
return MemDepResult::getDef(Inst);
- if (isInvariantLoad)
- continue;
- // Be conservative if the accessed pointer may alias the allocation -
- // fallback to the generic handling below.
- if ((AA->alias(Inst, AccessPtr) == NoAlias) &&
- // If the allocation is not aliased and does not read memory (like
- // strdup), it is safe to ignore.
- (isa<AllocaInst>(Inst) || isMallocLikeFn(Inst, TLI) ||
- isCallocLikeFn(Inst, TLI)))
- continue;
}
if (isInvariantLoad)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D15912.50207.patch
Type: text/x-patch
Size: 2983 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160309/8529daa7/attachment.bin>
More information about the llvm-commits
mailing list