aboutsummaryrefslogtreecommitdiff
path: root/llvm/test/Analysis/TypeBasedAliasAnalysis/aggregates.ll
blob: 4049c78049e03646289754a624f186aae2fc59c7 (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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
; RUN: opt < %s -aa-pipeline=tbaa,basic-aa -passes=aa-eval -evaluate-aa-metadata \
; RUN:     -print-no-aliases -print-may-aliases -disable-output 2>&1 | \
; RUN:     FileCheck %s
; RUN: opt < %s -aa-pipeline=tbaa,basic-aa -passes=gvn -S | FileCheck %s --check-prefix=OPT
;
; Check that TBAA handles access tags with aggregate final access types
; correctly.

%A = type { i32 }  ; struct A { int i; };
%B = type { %A }   ; struct B { A a; };
%C = type { %B }   ; struct C { B b; };
%D = type { i16 }  ; struct D { short s; };

; int vs. A::i  =>  MayAlias.
define i32 @f1(ptr %i, ptr %a) {
entry:
; CHECK-LABEL: f1
; CHECK: MayAlias: store i32 7, {{.*}} <-> store i32 5,
; OPT-LABEL: f1
; OPT: store i32 5,
; OPT: store i32 7,
; OPT: %[[RET:.*]] = load i32,
; OPT: ret i32 %[[RET]]
  store i32 5, ptr %i, align 4, !tbaa !3  ; TAG_int
  store i32 7, ptr %a, align 4, !tbaa !5  ; TAG_A_i
  %0 = load i32, ptr %i, align 4, !tbaa !3  ; TAG_int
  ret i32 %0
}

; int vs. B::a  =>  MayAlias.
define i32 @f2(ptr %i, ptr %b) {
entry:
; CHECK-LABEL: f2
; CHECK: MayAlias: store i32 7, {{.*}} <-> store i32 5,
; OPT-LABEL: f2
; OPT: store i32 5,
; OPT: store i32 7,
; OPT: %[[RET:.*]] = load i32,
; OPT: ret i32 %[[RET]]
  store i32 5, ptr %i, align 4, !tbaa !3  ; TAG_int
  store i32 7, ptr %b, align 4, !tbaa !7  ; TAG_B_a
  %0 = load i32, ptr %i, align 4, !tbaa !3  ; TAG_int
  ret i32 %0
}

; int vs. C::b  =>  MayAlias.
define i32 @f3(ptr %i, ptr %c) {
entry:
; CHECK-LABEL: f3
; CHECK: MayAlias: store i32 7, {{.*}} <-> store i32 5,
; OPT-LABEL: f3
; OPT: store i32 5,
; OPT: store i32 7,
; OPT: %[[RET:.*]] = load i32,
; OPT: ret i32 %[[RET]]
  store i32 5, ptr %i, align 4, !tbaa !3  ; TAG_int
  store i32 7, ptr %c, align 4, !tbaa !9  ; TAG_C_b
  %0 = load i32, ptr %i, align 4, !tbaa !3  ; TAG_int
  ret i32 %0
}

; A vs. C::b  =>  MayAlias.
define i32 @f4(ptr %a, ptr %c) {
entry:
; CHECK-LABEL: f4
; CHECK: MayAlias: store i32 7, {{.*}} <-> store i32 5,
; OPT-LABEL: f4
; OPT: store i32 5,
; OPT: store i32 7,
; OPT: %[[RET:.*]] = load i32,
; OPT: ret i32 %[[RET]]
  store i32 5, ptr %a, align 4, !tbaa !10   ; TAG_A
  store i32 7, ptr %c, align 4, !tbaa !9   ; TAG_C_b
  %0 = load i32, ptr %a, align 4, !tbaa !10  ; TAG_A
  ret i32 %0
}

; short vs. C::b  =>  NoAlias.
define i32 @f5(ptr %i, ptr %c) {
entry:
; CHECK-LABEL: f5
; CHECK: NoAlias: store i32 7, {{.*}} <-> store i32 5,
; OPT-LABEL: f5
; OPT: store i32 5,
; OPT: store i32 7,
; OPT: ret i32 5
  store i32 5, ptr %i, align 4, !tbaa !12  ; TAG_short
  store i32 7, ptr %c, align 4, !tbaa !9  ; TAG_C_b
  %0 = load i32, ptr %i, align 4, !tbaa !12  ; TAG_short
  ret i32 %0
}

; C vs. D  =>  NoAlias.
define i32 @f6(ptr %c, ptr %d) {
entry:
; CHECK-LABEL: f6
; CHECK: NoAlias: store i16 7, {{.*}} <-> store i32 5,
; OPT-LABEL: f6
; OPT: store i32 5,
; OPT: store i16 7,
; OPT: ret i32 5
  store i32 5, ptr %c, align 4, !tbaa !13  ; TAG_C
  store i16 7, ptr %d, align 4, !tbaa !15  ; TAG_D
  %0 = load i32, ptr %c, align 4, !tbaa !13  ; TAG_C
  ret i32 %0
}

!0 = !{!"root"}
!1 = !{!0, i64 1, !"char"}
!2 = !{!1, i64 4, !"int"}
!3 = !{!2, !2, i64 0, i64 4}  ; TAG_int

!4 = !{!1, i64 4, !"A", !2, i64 0, i64 4}
!5 = !{!4, !2, i64 0, i64 4}  ; TAG_A_i

!6 = !{!1, i64 4, !"B", !4, i64 0, i64 4}
!7 = !{!6, !4, i64 0, i64 4}  ; TAG_B_a

!8 = !{!1, i64 4, !"C", !6, i64 0, i64 4}
!9 = !{!8, !6, i64 0, i64 4}  ; TAG_C_b

!10 = !{!4, !4, i64 0, i64 4}  ; TAG_A

!11 = !{!1, i64 2, !"short"}
!12 = !{!11, !11, i64 0, i64 2}  ; TAG_short

!13 = !{!8, !8, i64 0, i64 4}  ; TAG_C

!14 = !{!4, i64 2, !"D", !11, i64 0, i64 2}
!15 = !{!14, !14, i64 0, i64 2}  ; TAG_D