[PATCH] D20652: [BasicAA] Extend negative offset logic from Allocas to GlobalVariables
Michael Kuperstein via llvm-commits
llvm-commits at lists.llvm.org
Wed May 25 16:46:12 PDT 2016
mkuper created this revision.
mkuper added reviewers: nlewycky, qcolombet, davidxl.
mkuper added subscribers: llvm-commits, dberlin, wmi.
This extends the logic of http://reviews.llvm.org/rL270777 to also apply to GlobalVariables in addition to Allocas.
I don't think there's any other kind of base object this can cover - it doesn't seem safe for arguments, noalias calls, or global aliases.
http://reviews.llvm.org/D20652
Files:
include/llvm/Analysis/BasicAliasAnalysis.h
lib/Analysis/BasicAliasAnalysis.cpp
test/Analysis/BasicAA/negoffset.ll
Index: test/Analysis/BasicAA/negoffset.ll
===================================================================
--- test/Analysis/BasicAA/negoffset.ll
+++ test/Analysis/BasicAA/negoffset.ll
@@ -26,6 +26,17 @@
ret void
}
+ at gv = global i32 1
+; CHECK-LABEL: Function: global:
+; CHECK-DAG: MayAlias: i32* %p0, i32* @gv
+; CHECK-DAG: NoAlias: i32* %p1, i32* @gv
+define void @global() {
+ %random = call i32* @random.i32(i32* @gv)
+ %p0 = getelementptr inbounds i32, i32* %random, i32 0
+ %p1 = getelementptr inbounds i32, i32* %random, i32 1
+ ret void
+}
+
; CHECK-LABEL: Function: struct:
; CHECK-DAG: MayAlias: i32* %f0, i32* %p0
; CHECK-DAG: MayAlias: i32* %f1, i32* %p0
Index: lib/Analysis/BasicAliasAnalysis.cpp
===================================================================
--- lib/Analysis/BasicAliasAnalysis.cpp
+++ lib/Analysis/BasicAliasAnalysis.cpp
@@ -964,6 +964,11 @@
// repsect to the alloca, that means the GEP can not alias pointer (b).
// Note that the pointer based on the alloca may not be a GEP. For
// example, it may be the alloca itself.
+// The same applies if (b) is based on a GlobalVariable. Note that just being
+// based on isIdentifiedObject() is not enough - we need an identified object
+// that does not permit access to negative offsets. For example, a negative
+// offset from a noalias argument or call can be inbounds w.r.t the actual
+// underlying object.
//
// For example, consider:
//
@@ -986,19 +991,22 @@
// the highest %f1 can be is (%alloca + 3). This means %random can not be higher
// than (%alloca - 1), and so is not inbounds, a contradiction.
bool BasicAAResult::isGEPBaseAtNegativeOffset(const GEPOperator *GEPOp,
- const DecomposedGEP &DecompGEP, const DecomposedGEP &DecompAlloca,
- uint64_t AllocaAccessSize) {
- // If the alloca access size is unknown, or the GEP isn't inbounds, bail.
- if (AllocaAccessSize == MemoryLocation::UnknownSize || !GEPOp->isInBounds())
+ const DecomposedGEP &DecompGEP, const DecomposedGEP &DecompObject,
+ uint64_t ObjectAccessSize) {
+ // If the object access size is unknown, or the GEP isn't inbounds, bail.
+ if (ObjectAccessSize == MemoryLocation::UnknownSize || !GEPOp->isInBounds())
return false;
- // We need an alloca, and want to know the offset of the pointer
- // from the alloca precisely, so no variable indices are allowed.
- if (!isa<AllocaInst>(DecompAlloca.Base) || !DecompAlloca.VarIndices.empty())
+ // We need the object to be an alloca or a globalvariable, and want to know
+ // the offset of the pointer from the object precisely, so no variable
+ // indices are allowed.
+ if (!(isa<AllocaInst>(DecompObject.Base) ||
+ isa<GlobalVariable>(DecompObject.Base)) ||
+ !DecompObject.VarIndices.empty())
return false;
- int64_t AllocaBaseOffset = DecompAlloca.StructOffset +
- DecompAlloca.OtherOffset;
+ int64_t ObjectBaseOffset = DecompObject.StructOffset +
+ DecompObject.OtherOffset;
// If the GEP has no variable indices, we know the precise offset
// from the base, then use it. If the GEP has variable indices, we're in
@@ -1009,7 +1017,7 @@
if (DecompGEP.VarIndices.empty())
GEPBaseOffset += DecompGEP.OtherOffset;
- return (GEPBaseOffset >= AllocaBaseOffset + (int64_t)AllocaAccessSize);
+ return (GEPBaseOffset >= ObjectBaseOffset + (int64_t)ObjectAccessSize);
}
/// Provides a bunch of ad-hoc rules to disambiguate a GEP instruction against
Index: include/llvm/Analysis/BasicAliasAnalysis.h
===================================================================
--- include/llvm/Analysis/BasicAliasAnalysis.h
+++ include/llvm/Analysis/BasicAliasAnalysis.h
@@ -157,8 +157,8 @@
const DataLayout &DL, AssumptionCache *AC, DominatorTree *DT);
static bool isGEPBaseAtNegativeOffset(const GEPOperator *GEPOp,
- const DecomposedGEP &DecompGEP, const DecomposedGEP &DecompAlloca,
- uint64_t AllocaAccessSize);
+ const DecomposedGEP &DecompGEP, const DecomposedGEP &DecompObject,
+ uint64_t ObjectAccessSize);
/// \brief A Heuristic for aliasGEP that searches for a constant offset
/// between the variables.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D20652.58539.patch
Type: text/x-patch
Size: 4220 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160525/4a6ec68a/attachment.bin>
More information about the llvm-commits
mailing list