1; This testcase consists of alias relations which should be completely
2; resolvable by cfl-steens-aa, but require analysis of getelementptr constant exprs.
3; Derived from BasicAA/2003-12-11-ConstExprGEP.ll
4
5; RUN: opt < %s -aa-pipeline=cfl-steens-aa -passes=aa-eval -print-may-aliases -disable-output 2>&1 | FileCheck %s
6
7%T = type { i32, [10 x i8] }
8
9@G = external global %T
10@G2 = external global %T
11
12; TODO: Quite a few of these are MayAlias because we don't yet consider
13; constant offsets in CFLSteensAA. If we start doing so, then we'll need to
14; change these test cases
15
16; CHECK:     Function: test
17; CHECK:     MayAlias: i32* %D, i32* %F
18; CHECK:     MayAlias: i32* %D, i8* %X
19; CHECK:     MayAlias: i32* %F, i8* %X
20define void @test() {
21  %D = getelementptr %T, %T* @G, i64 0, i32 0
22  %F = getelementptr i32, i32* getelementptr (%T, %T* @G, i64 0, i32 0), i64 0
23  %X = getelementptr [10 x i8], [10 x i8]* getelementptr (%T, %T* @G, i64 0, i32 1), i64 0, i64 5
24  load i32, i32* %D
25  load i32, i32* %F
26  load i8, i8* %X
27
28  ret void
29}
30
31; CHECK:     Function: simplecheck
32; CHECK:     MayAlias: i32* %F, i32* %arg0
33; CHECK:     MayAlias: i32* %H, i32* %arg0
34; CHECK:     MayAlias: i32* %F, i32* %H
35define void @simplecheck(i32* %arg0) {
36  %F = getelementptr i32, i32* getelementptr (%T, %T* @G, i64 0, i32 0), i64 0
37  %H = getelementptr %T, %T* @G2, i64 0, i32 0
38  load i32, i32* %arg0
39  load i32, i32* %F
40  load i32, i32* %H
41
42  ret void
43}
44
45; Ensure that CFLSteensAA properly identifies and handles escaping variables (i.e.
46; globals) in nested ConstantExprs
47
48; CHECK:      Function: checkNesting
49; CHECK:      MayAlias: i32* %A, i32* %arg0
50
51%NestedT = type { [1 x [1 x i32]] }
52@NT = external global %NestedT
53
54define void @checkNesting(i32* %arg0) {
55  %A = getelementptr [1 x i32],
56         [1 x i32]* getelementptr
57           ([1 x [1 x i32]], [1 x [1 x i32]]* getelementptr (%NestedT, %NestedT* @NT, i64 0, i32 0),
58           i64 0,
59           i32 0),
60         i64 0,
61         i32 0
62  load i32, i32* %arg0
63  load i32, i32* %A
64  ret void
65}
66