aboutsummaryrefslogtreecommitdiff
path: root/test/Analysis/DSGraph/gcsetest.ll
blob: 37600a890035197ec20381157d71a1fb04129406 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
; Test that GCSE uses ds-aa to do alias analysis, which is capable of 
; disambiguating some cases.

; RUN: llvm-as < %s | opt -no-aa -ds-aa -load-vn -gcse -instcombine -dce | llvm-dis | not grep ELIM

%intpair = type {int*, int*}
implementation

%intpair *%alloc_pair() {
	%Ap = malloc int
	%Bp = malloc int
 	%C  = malloc {int*, int*}
	%C1p = getelementptr {int*, int*}* %C, long 0, ubyte 0
	store int* %Ap, int** %C1p
	%C2p = getelementptr {int*, int*}* %C, long 0, ubyte 1
	store int* %Bp, int** %C2p
	ret %intpair* %C
}

int* %getp(%intpair* %P) {
	%pp = getelementptr %intpair* %P, long 0, ubyte 0
	%V = load int** %pp
	ret int *%V
}

int* %getq(%intpair* %P) {
	%pp = getelementptr %intpair* %P, long 0, ubyte 1
	%V = load int** %pp
	ret int *%V
}

int %test() {
	%C = call %intpair* %alloc_pair()
	%A = call int* %getp(%intpair* %C)
	%B = call int* %getp(%intpair* %C)
	%A1 = load int* %A

	store int 123, int* %B  ; Store does alias %A

	%A2 = load int* %A
	%x = sub int %A1, %A2
	ret int %x
}

int %test2() {   ; Test context sensitivity
	%C1 = call %intpair* %alloc_pair()
	%C2 = call %intpair* %alloc_pair()
	%P1 = call int* %getp(%intpair* %C1)
	%P2 = call int* %getp(%intpair* %C2)
	%X = load int* %P1
	store int 7, int* %P2
	%Y = load int* %P1
	%ELIM_x = sub int %X, %Y
	ret int %ELIM_x
}

int %test3() {
	%C = call %intpair* %alloc_pair()
	%P1 = call int* %getp(%intpair* %C)
	%P2 = call int* %getq(%intpair* %C)
	%X = load int* %P1
	store int 7, int* %P2
	%Y = load int* %P1
	%ELIM_x = sub int %X, %Y   ; Check field sensitivity
	ret int %ELIM_x
}