Skip to content

Commit

Permalink
[BasicAA] Return MayAlias for the pointer plus variable offset to
Browse files Browse the repository at this point in the history
structure object member

Differential Revision: https://reviews.llvm.org/D45510

llvm-svn: 330106
  • Loading branch information
ShivaChen committed Apr 16, 2018
1 parent 4e644b3 commit c84e77a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 11 deletions.
12 changes: 6 additions & 6 deletions llvm/lib/Analysis/BasicAliasAnalysis.cpp
Expand Up @@ -1176,13 +1176,13 @@ bool BasicAAResult::isGEPBaseAtNegativeOffset(const GEPOperator *GEPOp,
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
// a bit more trouble: we can't count on the constant offsets that come
// from non-struct sources, since these can be "rewound" by a negative
// variable offset. So use only offsets that came from structs.
// from the base, then use it. If the GEP has variable indices,
// we can't get exact GEP offset to identify pointer alias. So return
// false in that case.
if (!DecompGEP.VarIndices.empty())
return false;
int64_t GEPBaseOffset = DecompGEP.StructOffset;
if (DecompGEP.VarIndices.empty())
GEPBaseOffset += DecompGEP.OtherOffset;
GEPBaseOffset += DecompGEP.OtherOffset;

return (GEPBaseOffset >= ObjectBaseOffset + (int64_t)ObjectAccessSize);
}
Expand Down
31 changes: 26 additions & 5 deletions llvm/test/Analysis/BasicAA/negoffset.ll
Expand Up @@ -61,8 +61,8 @@ define void @struct() {
; CHECK-DAG: MayAlias: i32* %a2.0, i32* %r2.1i
; CHECK-DAG: NoAlias: i32* %a1, i32* %r2.0
; CHECK-DAG: NoAlias: i32* %a1, i32* %r2.1
; CHECK-DAG: NoAlias: i32* %a1, i32* %r2.i
; CHECK-DAG: NoAlias: i32* %a1, i32* %r2.1i
; CHECK-DAG: MayAlias: i32* %a1, i32* %r2.i
; CHECK-DAG: MayAlias: i32* %a1, i32* %r2.1i
%complex = type { i32, i32, [4 x i32] }
define void @complex1(i32 %i) {
%alloca = alloca %complex
Expand All @@ -79,9 +79,9 @@ define void @complex1(i32 %i) {
}

; CHECK-LABEL: Function: complex2:
; CHECK-DAG: NoAlias: i32* %alloca, i32* %p120
; CHECK-DAG: NoAlias: i32* %alloca, i32* %pi20
; CHECK-DAG: NoAlias: i32* %alloca, i32* %pij1
; CHECK-DAG: NoAlias: i32* %alloca, i32* %p120
; CHECK-DAG: MayAlias: i32* %alloca, i32* %pi20
; CHECK-DAG: MayAlias: i32* %alloca, i32* %pij1
; CHECK-DAG: MayAlias: i32* %a3, i32* %pij1
%inner = type { i32, i32 }
%outer = type { i32, i32, [10 x %inner] }
Expand All @@ -96,3 +96,24 @@ define void @complex2(i32 %i, i32 %j) {
ret void
}

; CHECK-LABEL: Function: pointer_offset:
; CHECK-DAG: MayAlias: i32** %add.ptr, i32** %p1
; CHECK-DAG: MayAlias: i32** %add.ptr, i32** %q2
%struct.X = type { i32*, i32* }
define i32 @pointer_offset(i32 signext %i, i32 signext %j, i32 zeroext %off) {
entry:
%i.addr = alloca i32
%j.addr = alloca i32
%x = alloca %struct.X
store i32 %i, i32* %i.addr
store i32 %j, i32* %j.addr
%0 = bitcast %struct.X* %x to i8*
%p1 = getelementptr inbounds %struct.X, %struct.X* %x, i32 0, i32 0
store i32* %i.addr, i32** %p1
%q2 = getelementptr inbounds %struct.X, %struct.X* %x, i32 0, i32 1
store i32* %j.addr, i32** %q2
%add.ptr = getelementptr inbounds i32*, i32** %q2, i32 %off
%1 = load i32*, i32** %add.ptr
%2 = load i32, i32* %1
ret i32 %2
}

0 comments on commit c84e77a

Please sign in to comment.