llvm.org GIT mirror llvm / 0692f37
[BasicAA] Return MayAlias for the pointer plus variable offset to structure object member Differential Revision: https://reviews.llvm.org/D45510 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@330106 91177308-0d34-0410-b5e6-96231b3b80d8 Shiva Chen 2 years ago
2 changed file(s) with 32 addition(s) and 11 deletion(s). Raw diff Collapse all Expand all
11751175 DecompObject.OtherOffset;
11761176
11771177 // If the GEP has no variable indices, we know the precise offset
1178 // from the base, then use it. If the GEP has variable indices, we're in
1179 // a bit more trouble: we can't count on the constant offsets that come
1180 // from non-struct sources, since these can be "rewound" by a negative
1181 // variable offset. So use only offsets that came from structs.
1178 // from the base, then use it. If the GEP has variable indices,
1179 // we can't get exact GEP offset to identify pointer alias. So return
1180 // false in that case.
1181 if (!DecompGEP.VarIndices.empty())
1182 return false;
11821183 int64_t GEPBaseOffset = DecompGEP.StructOffset;
1183 if (DecompGEP.VarIndices.empty())
1184 GEPBaseOffset += DecompGEP.OtherOffset;
1184 GEPBaseOffset += DecompGEP.OtherOffset;
11851185
11861186 return (GEPBaseOffset >= ObjectBaseOffset + (int64_t)ObjectAccessSize);
11871187 }
6060 ; CHECK-DAG: MayAlias: i32* %a2.0, i32* %r2.1i
6161 ; CHECK-DAG: NoAlias: i32* %a1, i32* %r2.0
6262 ; CHECK-DAG: NoAlias: i32* %a1, i32* %r2.1
63 ; CHECK-DAG: NoAlias: i32* %a1, i32* %r2.i
64 ; CHECK-DAG: NoAlias: i32* %a1, i32* %r2.1i
63 ; CHECK-DAG: MayAlias: i32* %a1, i32* %r2.i
64 ; CHECK-DAG: MayAlias: i32* %a1, i32* %r2.1i
6565 %complex = type { i32, i32, [4 x i32] }
6666 define void @complex1(i32 %i) {
6767 %alloca = alloca %complex
7878 }
7979
8080 ; CHECK-LABEL: Function: complex2:
81 ; CHECK-DAG: NoAlias: i32* %alloca, i32* %p120
82 ; CHECK-DAG: NoAlias: i32* %alloca, i32* %pi20
83 ; CHECK-DAG: NoAlias: i32* %alloca, i32* %pij1
81 ; CHECK-DAG: NoAlias: i32* %alloca, i32* %p120
82 ; CHECK-DAG: MayAlias: i32* %alloca, i32* %pi20
83 ; CHECK-DAG: MayAlias: i32* %alloca, i32* %pij1
8484 ; CHECK-DAG: MayAlias: i32* %a3, i32* %pij1
8585 %inner = type { i32, i32 }
8686 %outer = type { i32, i32, [10 x %inner] }
9595 ret void
9696 }
9797
98 ; CHECK-LABEL: Function: pointer_offset:
99 ; CHECK-DAG: MayAlias: i32** %add.ptr, i32** %p1
100 ; CHECK-DAG: MayAlias: i32** %add.ptr, i32** %q2
101 %struct.X = type { i32*, i32* }
102 define i32 @pointer_offset(i32 signext %i, i32 signext %j, i32 zeroext %off) {
103 entry:
104 %i.addr = alloca i32
105 %j.addr = alloca i32
106 %x = alloca %struct.X
107 store i32 %i, i32* %i.addr
108 store i32 %j, i32* %j.addr
109 %0 = bitcast %struct.X* %x to i8*
110 %p1 = getelementptr inbounds %struct.X, %struct.X* %x, i32 0, i32 0
111 store i32* %i.addr, i32** %p1
112 %q2 = getelementptr inbounds %struct.X, %struct.X* %x, i32 0, i32 1
113 store i32* %j.addr, i32** %q2
114 %add.ptr = getelementptr inbounds i32*, i32** %q2, i32 %off
115 %1 = load i32*, i32** %add.ptr
116 %2 = load i32, i32* %1
117 ret i32 %2
118 }