llvm.org GIT mirror llvm / 9e81c3b
TBAA: handle scalar TBAA format and struct-path aware TBAA format. Remove the command line argument "struct-path-tbaa" since we should not depend on command line argument to decide which format the IR file is using. Instead, we check the first operand of the tbaa tag node, if it is a MDNode, we treat it as struct-path aware TBAA format, otherwise, we treat it as scalar TBAA format. When clang starts to use struct-path aware TBAA format no matter whether struct-path-tbaa is no, and we can auto-upgrade existing bc files, the support for scalar TBAA format can be dropped. Existing testing cases are updated to use the struct-path aware TBAA format. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@191538 91177308-0d34-0410-b5e6-96231b3b80d8 Manman Ren 6 years ago
28 changed file(s) with 252 addition(s) and 110 deletion(s). Raw diff Collapse all Expand all
1515 // typical C/C++ TBAA, but it can also be used to implement custom alias
1616 // analysis behavior for other languages.
1717 //
18 // The current metadata format is very simple. TBAA MDNodes have up to
18 // We now support two types of metadata format: scalar TBAA and struct-path
19 // aware TBAA. After all testing cases are upgraded to use struct-path aware
20 // TBAA and we can auto-upgrade existing bc files, the support for scalar TBAA
21 // can be dropped.
22 //
23 // The scalar TBAA metadata format is very simple. TBAA MDNodes have up to
1924 // three fields, e.g.:
2025 // !0 = metadata !{ metadata !"an example type tree" }
2126 // !1 = metadata !{ metadata !"int", metadata !0 }
3843 // indicates that the type is "constant" (meaning pointsToConstantMemory
3944 // should return true; see
4045 // http://llvm.org/docs/AliasAnalysis.html#OtherItfs).
46 //
47 // With struct-path aware TBAA, the MDNodes attached to an instruction using
48 // "!tbaa" are called path tag nodes.
49 //
50 // The path tag node has 4 fields with the last field being optional.
51 //
52 // The first field is the base type node, it can be a struct type node
53 // or a scalar type node. The second field is the access type node, it
54 // must be a scalar type node. The third field is the offset into the base type.
55 // The last field has the same meaning as the last field of our scalar TBAA:
56 // it's an integer which if equal to 1 indicates that the access is "constant".
57 //
58 // The struct type node has a name and a list of pairs, one pair for each member
59 // of the struct. The first element of each pair is a type node (a struct type
60 // node or a sclar type node), specifying the type of the member, the second
61 // element of each pair is the offset of the member.
62 //
63 // Given an example
64 // typedef struct {
65 // short s;
66 // } A;
67 // typedef struct {
68 // uint16_t s;
69 // A a;
70 // } B;
71 //
72 // For an acess to B.a.s, we attach !5 (a path tag node) to the load/store
73 // instruction. The base type is !4 (struct B), the access type is !2 (scalar
74 // type short) and the offset is 4.
75 //
76 // !0 = metadata !{metadata !"Simple C/C++ TBAA"}
77 // !1 = metadata !{metadata !"omnipotent char", metadata !0} // Scalar type node
78 // !2 = metadata !{metadata !"short", metadata !1} // Scalar type node
79 // !3 = metadata !{metadata !"A", metadata !2, i64 0} // Struct type node
80 // !4 = metadata !{metadata !"B", metadata !2, i64 0, metadata !3, i64 4}
81 // // Struct type node
82 // !5 = metadata !{metadata !4, metadata !2, i64 4} // Path tag node
83 //
84 // The struct type nodes and the scalar type nodes form a type DAG.
85 // Root (!0)
86 // char (!1) -- edge to Root
87 // short (!2) -- edge to char
88 // A (!3) -- edge with offset 0 to short
89 // B (!4) -- edge with offset 0 to short and edge with offset 4 to A
90 //
91 // To check if two tags (tagX and tagY) can alias, we start from the base type
92 // of tagX, follow the edge with the correct offset in the type DAG and adjust
93 // the offset until we reach the base type of tagY or until we reach the Root
94 // node.
95 // If we reach the base type of tagY, compare the adjusted offset with
96 // offset of tagY, return Alias if the offsets are the same, return NoAlias
97 // otherwise.
98 // If we reach the Root node, perform the above starting from base type of tagY
99 // to see if we reach base type of tagX.
100 //
101 // If they have different roots, they're part of different potentially
102 // unrelated type systems, so we return Alias to be conservative.
103 // If neither node is an ancestor of the other and they have the same root,
104 // then we say NoAlias.
41105 //
42106 // TODO: The current metadata format doesn't support struct
43107 // fields. For example:
70134 // achieved by stripping the !tbaa tags from IR, but this option is sometimes
71135 // more convenient.
72136 static cl::opt EnableTBAA("enable-tbaa", cl::init(true));
73 static cl::opt EnableStructPathTBAA("struct-path-tbaa", cl::init(false));
74137
75138 namespace {
76139 /// TBAANode - This is a simple wrapper around an MDNode which provides a
258321 AliasAnalysis::getAnalysisUsage(AU);
259322 }
260323
324 /// Check the first operand of the tbaa tag node, if it is a MDNode, we treat
325 /// it as struct-path aware TBAA format, otherwise, we treat it as scalar TBAA
326 /// format.
327 static bool isStructPathTBAA(const MDNode *MD) {
328 return isa(MD->getOperand(0));
329 }
330
261331 /// Aliases - Test whether the type represented by A may alias the
262332 /// type represented by B.
263333 bool
264334 TypeBasedAliasAnalysis::Aliases(const MDNode *A,
265335 const MDNode *B) const {
266 if (EnableStructPathTBAA)
336 if (isStructPathTBAA(A))
267337 return PathAliases(A, B);
268338
269339 // Keep track of the root node for A and B.
396466
397467 // If this is an "immutable" type, we can assume the pointer is pointing
398468 // to constant memory.
399 if ((!EnableStructPathTBAA && TBAANode(M).TypeIsImmutable()) ||
400 (EnableStructPathTBAA && TBAAStructTagNode(M).TypeIsImmutable()))
469 if ((!isStructPathTBAA(M) && TBAANode(M).TypeIsImmutable()) ||
470 (isStructPathTBAA(M) && TBAAStructTagNode(M).TypeIsImmutable()))
401471 return true;
402472
403473 return AliasAnalysis::pointsToConstantMemory(Loc, OrLocal);
413483 // If this is an "immutable" type, we can assume the call doesn't write
414484 // to memory.
415485 if (const MDNode *M = CS.getInstruction()->getMetadata(LLVMContext::MD_tbaa))
416 if ((!EnableStructPathTBAA && TBAANode(M).TypeIsImmutable()) ||
417 (EnableStructPathTBAA && TBAAStructTagNode(M).TypeIsImmutable()))
486 if ((!isStructPathTBAA(M) && TBAANode(M).TypeIsImmutable()) ||
487 (isStructPathTBAA(M) && TBAAStructTagNode(M).TypeIsImmutable()))
418488 Min = OnlyReadsMemory;
419489
420490 return ModRefBehavior(AliasAnalysis::getModRefBehavior(CS) & Min);
458528 }
459529
460530 bool MDNode::isTBAAVtableAccess() const {
461 if (!EnableStructPathTBAA) {
531 if (!isStructPathTBAA(this)) {
462532 if (getNumOperands() < 1) return false;
463533 if (MDString *Tag1 = dyn_cast(getOperand(0))) {
464534 if (Tag1->getString() == "vtable pointer") return true;
484554 return A;
485555
486556 // For struct-path aware TBAA, we use the access type of the tag.
487 if (EnableStructPathTBAA) {
557 bool StructPath = isStructPathTBAA(A);
558 if (StructPath) {
488559 A = cast_or_null(A->getOperand(1));
489560 if (!A) return 0;
490561 B = cast_or_null(B->getOperand(1));
517588 --IA;
518589 --IB;
519590 }
520 if (!EnableStructPathTBAA)
591 if (!StructPath)
521592 return Ret;
522593
523594 if (!Ret)
2828 ret i32 %tmp5.lobit
2929 }
3030
31 !0 = metadata !{metadata !"double", metadata !1}
31 !0 = metadata !{metadata !4, metadata !4, i64 0}
3232 !1 = metadata !{metadata !"omnipotent char", metadata !2}
3333 !2 = metadata !{metadata !"Simple C/C++ TBAA", null}
34 !3 = metadata !{metadata !"int", metadata !1}
34 !3 = metadata !{metadata !5, metadata !5, i64 0}
35 !4 = metadata !{metadata !"double", metadata !1}
36 !5 = metadata !{metadata !"int", metadata !1}
4646 ; Root note.
4747 !0 = metadata !{ }
4848 ; Some type.
49 !1 = metadata !{ metadata !"foo", metadata !0 }
49 !1 = metadata !{metadata !7, metadata !7, i64 0}
5050 ; Some other non-aliasing type.
51 !2 = metadata !{ metadata !"bar", metadata !0 }
51 !2 = metadata !{metadata !8, metadata !8, i64 0}
5252
5353 ; Some type.
54 !3 = metadata !{ metadata !"foo", metadata !0 }
54 !3 = metadata !{metadata !9, metadata !9, i64 0}
5555 ; Some type in a different type system.
56 !4 = metadata !{ metadata !"bar", metadata !"different" }
56 !4 = metadata !{metadata !10, metadata !10, i64 0}
5757
5858 ; Invariant memory.
59 !5 = metadata !{ metadata !"qux", metadata !0, i1 1 }
59 !5 = metadata !{metadata !11, metadata !11, i64 0, i1 1}
6060 ; Not invariant memory.
61 !6 = metadata !{ metadata !"qux", metadata !0, i1 0 }
61 !6 = metadata !{metadata !11, metadata !11, i64 0, i1 0}
62 !7 = metadata !{ metadata !"foo", metadata !0 }
63 !8 = metadata !{ metadata !"bar", metadata !0 }
64 !9 = metadata !{ metadata !"foo", metadata !0 }
65 !10 = metadata !{ metadata !"bar", metadata !"different" }
66 !11 = metadata !{ metadata !"qux", metadata !0}
3232 }
3333
3434 !0 = metadata !{metadata !"test"}
35 !1 = metadata !{metadata !"green", metadata !0}
36 !2 = metadata !{metadata !"blue", metadata !0}
35 !1 = metadata !{metadata !3, metadata !3, i64 0}
36 !2 = metadata !{metadata !4, metadata !4, i64 0}
37 !3 = metadata !{metadata !"green", metadata !0}
38 !4 = metadata !{metadata !"blue", metadata !0}
5050 ; Root note.
5151 !0 = metadata !{ }
5252 ; Some type.
53 !1 = metadata !{ metadata !"foo", metadata !0 }
53 !1 = metadata !{metadata !7, metadata !7, i64 0}
5454 ; Some other non-aliasing type.
55 !2 = metadata !{ metadata !"bar", metadata !0 }
55 !2 = metadata !{metadata !8, metadata !8, i64 0}
5656
5757 ; Some type.
58 !3 = metadata !{ metadata !"foo", metadata !0 }
58 !3 = metadata !{metadata !9, metadata !9, i64 0}
5959 ; Some type in a different type system.
60 !4 = metadata !{ metadata !"bar", metadata !"different" }
60 !4 = metadata !{metadata !10, metadata !10, i64 0}
6161
6262 ; Invariant memory.
63 !5 = metadata !{ metadata !"qux", metadata !0, i1 1 }
63 !5 = metadata !{metadata !11, metadata !11, i64 0, i1 1}
6464 ; Not invariant memory.
65 !6 = metadata !{ metadata !"qux", metadata !0, i1 0 }
65 !6 = metadata !{metadata !11, metadata !11, i64 0, i1 0}
66 !7 = metadata !{ metadata !"foo", metadata !0 }
67 !8 = metadata !{ metadata !"bar", metadata !0 }
68 !9 = metadata !{ metadata !"foo", metadata !0 }
69 !10 = metadata !{ metadata !"bar", metadata !"different" }
70 !11 = metadata !{ metadata !"qux", metadata !0}
1212
1313 ; CHECK: for.end:
1414 ; CHECK: %arrayidx31 = getelementptr inbounds %union.vector_t* %t, i64 0, i32 0, i64 1
15 ; CHECK: %tmp32 = load i64* %arrayidx31, align 8, !tbaa !3
15 ; CHECK: %tmp32 = load i64* %arrayidx31, align 8, !tbaa [[TAG:!.*]]
1616
1717 define void @vrlh(%union.vector_t* %va, %union.vector_t* %vb, %union.vector_t* %vd) nounwind {
1818 entry:
122122 ret float %tmp10
123123 }
124124
125 !0 = metadata !{metadata !"short", metadata !1}
125 ; CHECK: [[TAG]] = metadata !{metadata [[TYPE_LL:!.*]], metadata [[TYPE_LL]], i64 0}
126 ; CHECK: [[TYPE_LL]] = metadata !{metadata !"long long", metadata {{!.*}}}
127 !0 = metadata !{metadata !6, metadata !6, i64 0}
126128 !1 = metadata !{metadata !"omnipotent char", metadata !2}
127129 !2 = metadata !{metadata !"Simple C/C++ TBAA", null}
128 !3 = metadata !{metadata !"long long", metadata !1}
129 !4 = metadata !{metadata !"int", metadata !1}
130 !5 = metadata !{metadata !"float", metadata !1}
130 !3 = metadata !{metadata !7, metadata !7, i64 0}
131 !4 = metadata !{metadata !8, metadata !8, i64 0}
132 !5 = metadata !{metadata !9, metadata !9, i64 0}
133 !6 = metadata !{metadata !"short", metadata !1}
134 !7 = metadata !{metadata !"long long", metadata !1}
135 !8 = metadata !{metadata !"int", metadata !1}
136 !9 = metadata !{metadata !"float", metadata !1}
7979 !0 = metadata !{ }
8080
8181 ; Invariant memory.
82 !1 = metadata !{ metadata !"foo", metadata !0, i1 1 }
82 !1 = metadata !{metadata !3, metadata !3, i64 0, i1 1 }
8383 ; Not invariant memory.
84 !2 = metadata !{ metadata !"foo", metadata !0, i1 0 }
84 !2 = metadata !{metadata !3, metadata !3, i64 0, i1 0 }
85 !3 = metadata !{ metadata !"foo", metadata !0 }
8484 }
8585
8686 !0 = metadata !{}
87 !1 = metadata !{metadata !"red", metadata !0}
88 !2 = metadata !{metadata !"blu", metadata !0}
89 !3 = metadata !{metadata !"outer space"}
90 !4 = metadata !{metadata !"brick red", metadata !1}
87 !1 = metadata !{metadata !5, metadata !5, i64 0}
88 !2 = metadata !{metadata !6, metadata !6, i64 0}
89 !3 = metadata !{metadata !7, metadata !7, i64 0}
90 !4 = metadata !{metadata !8, metadata !8, i64 0}
91 !5 = metadata !{metadata !"red", metadata !0}
92 !6 = metadata !{metadata !"blu", metadata !0}
93 !7 = metadata !{metadata !"outer space"}
94 !8 = metadata !{metadata !"brick red", metadata !5}
2525 ; CHECK: attributes [[NUW]] = { nounwind }
2626
2727 !0 = metadata !{metadata !"tbaa root", null}
28 !1 = metadata !{metadata !"A", metadata !0}
29 !2 = metadata !{metadata !"B", metadata !0}
28 !1 = metadata !{metadata !3, metadata !3, i64 0}
29 !2 = metadata !{metadata !4, metadata !4, i64 0}
30 !3 = metadata !{metadata !"A", metadata !0}
31 !4 = metadata !{metadata !"B", metadata !0}
2929 }
3030
3131 !0 = metadata !{metadata !"root", null}
32 !1 = metadata !{metadata !"pointer", metadata !0}
33 !2 = metadata !{metadata !"double", metadata !0}
32 !1 = metadata !{metadata !6, metadata !6, i64 0}
33 !2 = metadata !{metadata !7, metadata !7, i64 0}
3434
3535 ; LICM shouldn't hoist anything here.
3636
5555 br label %loop
5656 }
5757
58 !3 = metadata !{metadata !"pointer", metadata !4}
59 !4 = metadata !{metadata !"char", metadata !5}
60 !5 = metadata !{metadata !"root", null}
58 !3 = metadata !{metadata !"pointer", metadata !8}
59 !4 = metadata !{metadata !8, metadata !8, i64 0}
60 !5 = metadata !{metadata !9, metadata !9, i64 0}
61 !6 = metadata !{metadata !"pointer", metadata !0}
62 !7 = metadata !{metadata !"double", metadata !0}
63 !8 = metadata !{metadata !"char", metadata !9}
64 !9 = metadata !{metadata !"root", null}
66
77 ; CHECK: @foo
88 ; CHECK-NEXT: tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* %p, i8* %q, i64 16, i32 1, i1 false), !tbaa !0
9 ; CHECK-NEXT: store i8 2, i8* %s, align 1, !tbaa !2
9 ; CHECK-NEXT: store i8 2, i8* %s, align 1, !tbaa [[TAGA:!.*]]
1010 ; CHECK-NEXT: ret void
1111 define void @foo(i8* nocapture %p, i8* nocapture %q, i8* nocapture %s) nounwind {
1212 tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* %p, i8* %q, i64 16, i32 1, i1 false), !tbaa !2
1717
1818 declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture, i8* nocapture, i64, i32, i1) nounwind
1919
20 ; CHECK [[TAGA]] = metadata !{metadata [[TYPEA:!.*]], metadata [[TYPEA]], i64 0}
21 ; CHECK [[TYPEA]] = metadata !{metadata !"A", metadata !{{.*}}}
2022 !0 = metadata !{metadata !"tbaa root", null}
21 !1 = metadata !{metadata !"A", metadata !0}
22 !2 = metadata !{metadata !"B", metadata !0}
23 !1 = metadata !{metadata !3, metadata !3, i64 0}
24 !2 = metadata !{metadata !4, metadata !4, i64 0}
25 !3 = metadata !{metadata !"A", metadata !0}
26 !4 = metadata !{metadata !"B", metadata !0}
1717
1818 ; Basic AA says MayAlias, TBAA says NoAlias
1919 ; CHECK: MayAlias: i64* %i5, i8** %p
20 ; CHECK: NoAlias: store i64 %conv, i64* %i5, align 8, !tbaa !4 <-> store i8* null, i8** %p, align 8, !tbaa !3
20 ; CHECK: NoAlias: store i64 %conv, i64* %i5, align 8, !tbaa !6 <-> store i8* null, i8** %p, align 8, !tbaa !9
2121
2222 %struct.Foo = type { i64 }
2323 %struct.Bar = type { i8* }
3131 store i32 %n, i32* %n.addr, align 4, !tbaa !0
3232 %call = call noalias i8* @_Znwm(i64 8)
3333 %0 = bitcast i8* %call to %struct.Foo*
34 store %struct.Foo* %0, %struct.Foo** %f, align 8, !tbaa !3
35 %1 = load %struct.Foo** %f, align 8, !tbaa !3
34 store %struct.Foo* %0, %struct.Foo** %f, align 8, !tbaa !4
35 %1 = load %struct.Foo** %f, align 8, !tbaa !4
3636 %i = getelementptr inbounds %struct.Foo* %1, i32 0, i32 0
37 store i64 1, i64* %i, align 8, !tbaa !4
37 store i64 1, i64* %i, align 8, !tbaa !6
3838 store i32 0, i32* %i1, align 4, !tbaa !0
3939 br label %for.cond
4040
4545 br i1 %cmp, label %for.body, label %for.end
4646
4747 for.body:
48 %4 = load %struct.Foo** %f, align 8, !tbaa !3
48 %4 = load %struct.Foo** %f, align 8, !tbaa !4
4949 %5 = bitcast %struct.Foo* %4 to i8*
5050 %new.isnull = icmp eq i8* %5, null
5151 br i1 %new.isnull, label %new.cont, label %new.notnull
5656
5757 new.cont:
5858 %7 = phi %struct.Bar* [ %6, %new.notnull ], [ null, %for.body ]
59 store %struct.Bar* %7, %struct.Bar** %b, align 8, !tbaa !3
60 %8 = load %struct.Bar** %b, align 8, !tbaa !3
59 store %struct.Bar* %7, %struct.Bar** %b, align 8, !tbaa !4
60 %8 = load %struct.Bar** %b, align 8, !tbaa !4
6161 %p = getelementptr inbounds %struct.Bar* %8, i32 0, i32 0
62 store i8* null, i8** %p, align 8, !tbaa !3
63 %9 = load %struct.Foo** %f, align 8, !tbaa !3
62 store i8* null, i8** %p, align 8, !tbaa !9
63 %9 = load %struct.Foo** %f, align 8, !tbaa !4
6464 %10 = bitcast %struct.Foo* %9 to i8*
6565 %new.isnull2 = icmp eq i8* %10, null
6666 br i1 %new.isnull2, label %new.cont4, label %new.notnull3
7171
7272 new.cont4:
7373 %12 = phi %struct.Foo* [ %11, %new.notnull3 ], [ null, %new.cont ]
74 store %struct.Foo* %12, %struct.Foo** %f, align 8, !tbaa !3
74 store %struct.Foo* %12, %struct.Foo** %f, align 8, !tbaa !4
7575 %13 = load i32* %i1, align 4, !tbaa !0
7676 %conv = sext i32 %13 to i64
77 %14 = load %struct.Foo** %f, align 8, !tbaa !3
77 %14 = load %struct.Foo** %f, align 8, !tbaa !4
7878 %i5 = getelementptr inbounds %struct.Foo* %14, i32 0, i32 0
79 store i64 %conv, i64* %i5, align 8, !tbaa !4
79 store i64 %conv, i64* %i5, align 8, !tbaa !6
8080 br label %for.inc
8181
8282 for.inc:
8686 br label %for.cond
8787
8888 for.end:
89 %16 = load %struct.Foo** %f, align 8, !tbaa !3
89 %16 = load %struct.Foo** %f, align 8, !tbaa !4
9090 %i6 = getelementptr inbounds %struct.Foo* %16, i32 0, i32 0
91 %17 = load i64* %i6, align 8, !tbaa !4
91 %17 = load i64* %i6, align 8, !tbaa !6
9292 ret i64 %17
9393 }
9494
9696
9797 attributes #0 = { nounwind }
9898
99 !0 = metadata !{metadata !"int", metadata !1}
100 !1 = metadata !{metadata !"omnipotent char", metadata !2}
101 !2 = metadata !{metadata !"Simple C/C++ TBAA"}
102 !3 = metadata !{metadata !"any pointer", metadata !1}
103 !4 = metadata !{metadata !"long", metadata !1}
99 !0 = metadata !{metadata !1, metadata !1, i64 0}
100 !1 = metadata !{metadata !"int", metadata !2, i64 0}
101 !2 = metadata !{metadata !"omnipotent char", metadata !3, i64 0}
102 !3 = metadata !{metadata !"Simple C/C++ TBAA"}
103 !4 = metadata !{metadata !5, metadata !5, i64 0}
104 !5 = metadata !{metadata !"any pointer", metadata !2, i64 0}
105 !6 = metadata !{metadata !7, metadata !8, i64 0}
106 !7 = metadata !{metadata !"_ZTS3Foo", metadata !8, i64 0}
107 !8 = metadata !{metadata !"long", metadata !2, i64 0}
108 !9 = metadata !{metadata !10, metadata !5, i64 0}
109 !10 = metadata !{metadata !"_ZTS3Bar", metadata !5, i64 0}
3838 ret i64 %tmp3
3939 }
4040
41 !0 = metadata !{metadata !"int", metadata !1}
41 !0 = metadata !{metadata !2, metadata !2, i64 0}
4242 !1 = metadata !{metadata !"simple"}
43 !3 = metadata !{metadata !"float", metadata !1}
44 !4 = metadata !{metadata !"long", metadata !1}
45 !5 = metadata !{metadata !"small", metadata !1}
43 !2 = metadata !{metadata !"int", metadata !1}
44 !3 = metadata !{metadata !6, metadata !6, i64 0}
45 !4 = metadata !{metadata !7, metadata !7, i64 0}
46 !5 = metadata !{metadata !8, metadata !8, i64 0}
47 !6 = metadata !{metadata !"float", metadata !1}
48 !7 = metadata !{metadata !"long", metadata !1}
49 !8 = metadata !{metadata !"small", metadata !1}
0 ; RUN: opt -tbaa -sink -S < %s | FileCheck %s
11
22 ; CHECK: a:
3 ; CHECK: %f = load float* %p, !tbaa !2
3 ; CHECK: %f = load float* %p, !tbaa [[TAGA:!.*]]
44 ; CHECK: store float %f, float* %q
55
66 define void @foo(float* %p, i1 %c, float* %q, float* %r) {
1414 ret void
1515 }
1616
17 !0 = metadata !{metadata !"A", metadata !2}
18 !1 = metadata !{metadata !"B", metadata !2}
17 ; CHECK: [[TAGA]] = metadata !{metadata [[TYPEA:!.*]], metadata [[TYPEA]], i64 0}
18 ; CHECK: [[TYPEA]] = metadata !{metadata !"A", metadata !{{.*}}}
19 !0 = metadata !{metadata !3, metadata !3, i64 0}
20 !1 = metadata !{metadata !4, metadata !4, i64 0}
1921 !2 = metadata !{metadata !"test"}
22 !3 = metadata !{metadata !"A", metadata !2}
23 !4 = metadata !{metadata !"B", metadata !2}
None ; RUN: opt < %s -tbaa -basicaa -struct-path-tbaa -aa-eval -evaluate-tbaa -print-no-aliases -print-may-aliases -disable-output 2>&1 | FileCheck %s
1 ; RUN: opt < %s -tbaa -basicaa -struct-path-tbaa -gvn -S | FileCheck %s --check-prefix=OPT
0 ; RUN: opt < %s -tbaa -basicaa -aa-eval -evaluate-tbaa -print-no-aliases -print-may-aliases -disable-output 2>&1 | FileCheck %s
1 ; RUN: opt < %s -tbaa -basicaa -gvn -S | FileCheck %s --check-prefix=OPT
22 ; Generated from clang/test/CodeGen/tbaa.cpp with "-O1 -struct-path-tbaa -disable-llvm-optzns".
33
44 %struct.StructA = type { i16, i32, i16, i32 }
385385 }
386386
387387 !0 = metadata !{ metadata !"root" }
388 !1 = metadata !{ metadata !"set1", metadata !0 }
389 !2 = metadata !{ metadata !"set2", metadata !0 }
388 !1 = metadata !{ metadata !3, metadata !3, i64 0 }
389 !2 = metadata !{ metadata !4, metadata !4, i64 0 }
390 !3 = metadata !{ metadata !"set1", metadata !0 }
391 !4 = metadata !{ metadata !"set2", metadata !0 }
6363 ret void
6464 }
6565
66 !0 = metadata !{metadata !"any pointer", metadata !1}
66 !0 = metadata !{metadata !5, metadata !5, i64 0}
6767 !1 = metadata !{metadata !"omnipotent char", metadata !2}
6868 !2 = metadata !{metadata !"Simple C/C++ TBAA", null}
69 !3 = metadata !{metadata !"int", metadata !1}
69 !3 = metadata !{metadata !6, metadata !6, i64 0}
7070 !4 = metadata !{i32 156132, i32 156164, i32 156205, i32 156238, i32 156282, i32 156332, i32 156370, i32 156408, i32 156447, i32 156486, i32 156536, i32 156574, i32 156612, i32 156651, i32 156690, i32 156740, i32 156778, i32 156816, i32 156855, i32 156894, i32 156944, i32 156982, i32 157020, i32 157059, i32 157098, i32 157148, i32 157186, i32 157224, i32 157263, i32 157302, i32 157352, i32 157390, i32 157428, i32 157467, i32 157506, i32 157556, i32 157594, i32 157632, i32 157671, i32 157710, i32 157760, i32 157798, i32 157836, i32 157875, i32 157914, i32 157952, i32 157996, i32 158046, i32 158099, i32 158140, i32 158179, i32 158218, i32 158268, i32 158321, i32 158362, i32 158401, i32 158440, i32 158490, i32 158543, i32 158584, i32 158623, i32 158662, i32 158712, i32 158765, i32 158806, i32 158845, i32 158884, i32 158922, i32 158963, i32 158996, i32 159029, i32 159062, i32 159109, i32 159154, i32 159199, i32 159243, i32 159286, i32 159329, i32 159375, i32 159422, i32 159478, i32 159522, i32 159566}
71 !5 = metadata !{metadata !"any pointer", metadata !1}
72 !6 = metadata !{metadata !"int", metadata !1}
4040 define void @call_virtual_func(%struct.Foo* %f) uwtable {
4141 entry:
4242 %0 = bitcast %struct.Foo* %f to void (%struct.Foo*)***
43 %vtable = load void (%struct.Foo*)*** %0, align 8, !tbaa !3
43 %vtable = load void (%struct.Foo*)*** %0, align 8, !tbaa !2
4444 %1 = load void (%struct.Foo*)** %vtable, align 8
4545 call void %1(%struct.Foo* %f)
4646 ret void
5353 ; CHECK: = load
5454 ; CHECK: ret void
5555
56 !0 = metadata !{metadata !"int", metadata !1}
57 !1 = metadata !{metadata !"omnipotent char", metadata !2}
58 !2 = metadata !{metadata !"Simple C/C++ TBAA", null}
59 !3 = metadata !{metadata !"vtable pointer", metadata !2}
60
56 !0 = metadata !{metadata !"Simple C/C++ TBAA", null}
57 !1 = metadata !{metadata !"vtable pointer", metadata !0}
58 !2 = metadata !{metadata !1, metadata !1, i64 0}
77 %0 = load i8* %a, align 8, !tbaa !0
88 ret i8 %0
99 }
10 !0 = metadata !{metadata !"vtable pointer", metadata !1}
10 !0 = metadata !{metadata !2, metadata !2, i64 0}
1111 !1 = metadata !{metadata !"Simple C/C++ TBAA", null}
12
12 !2 = metadata !{metadata !"vtable pointer", metadata !1}
77 store i8* %b, i8** %a, align 8, !tbaa !0
88 ret void
99 }
10 !0 = metadata !{metadata !"vtable pointer", metadata !1}
10 !0 = metadata !{metadata !2, metadata !2, i64 0}
1111 !1 = metadata !{metadata !"Simple C/C++ TBAA", null}
12
12 !2 = metadata !{metadata !"vtable pointer", metadata !1}
2424 ret void
2525 }
2626
27 !0 = metadata !{metadata !"short", metadata !1}
27 !0 = metadata !{metadata !3, metadata !3, i64 0}
2828 !1 = metadata !{metadata !"omnipotent char", metadata !2}
2929 !2 = metadata !{metadata !"Simple C/C++ TBAA", null}
30 !3 = metadata !{metadata !"short", metadata !1}
1212
1313 define i32 @test2(i8* %p, i8* %q) {
1414 ; CHECK: @test2(i8* %p, i8* %q)
15 ; CHECK: call i32 @foo(i8* %p), !tbaa !0
15 ; CHECK: call i32 @foo(i8* %p), !tbaa [[TAGC:!.*]]
1616 ; CHECK: %c = add i32 %a, %a
1717 %a = call i32 @foo(i8* %p), !tbaa !0
1818 %b = call i32 @foo(i8* %p), !tbaa !0
2222
2323 define i32 @test3(i8* %p, i8* %q) {
2424 ; CHECK: @test3(i8* %p, i8* %q)
25 ; CHECK: call i32 @foo(i8* %p), !tbaa !3
25 ; CHECK: call i32 @foo(i8* %p), !tbaa [[TAGB:!.*]]
2626 ; CHECK: %c = add i32 %a, %a
2727 %a = call i32 @foo(i8* %p), !tbaa !3
2828 %b = call i32 @foo(i8* %p), !tbaa !3
3232
3333 define i32 @test4(i8* %p, i8* %q) {
3434 ; CHECK: @test4(i8* %p, i8* %q)
35 ; CHECK: call i32 @foo(i8* %p), !tbaa !1
35 ; CHECK: call i32 @foo(i8* %p), !tbaa [[TAGA:!.*]]
3636 ; CHECK: %c = add i32 %a, %a
3737 %a = call i32 @foo(i8* %p), !tbaa !1
3838 %b = call i32 @foo(i8* %p), !tbaa !0
4242
4343 define i32 @test5(i8* %p, i8* %q) {
4444 ; CHECK: @test5(i8* %p, i8* %q)
45 ; CHECK: call i32 @foo(i8* %p), !tbaa !1
45 ; CHECK: call i32 @foo(i8* %p), !tbaa [[TAGA:!.*]]
4646 ; CHECK: %c = add i32 %a, %a
4747 %a = call i32 @foo(i8* %p), !tbaa !0
4848 %b = call i32 @foo(i8* %p), !tbaa !1
5252
5353 define i32 @test6(i8* %p, i8* %q) {
5454 ; CHECK: @test6(i8* %p, i8* %q)
55 ; CHECK: call i32 @foo(i8* %p), !tbaa !1
55 ; CHECK: call i32 @foo(i8* %p), !tbaa [[TAGA:!.*]]
5656 ; CHECK: %c = add i32 %a, %a
5757 %a = call i32 @foo(i8* %p), !tbaa !0
5858 %b = call i32 @foo(i8* %p), !tbaa !3
7373
7474 declare i32 @foo(i8*) readonly
7575
76 !0 = metadata !{metadata !"C", metadata !1}
77 !1 = metadata !{metadata !"A", metadata !2}
76 ; CHECK: [[TAGC]] = metadata !{metadata [[TYPEC:!.*]], metadata [[TYPEC]], i64 0}
77 ; CHECK: [[TYPEC]] = metadata !{metadata !"C", metadata [[TYPEA:!.*]]}
78 ; CHECK: [[TYPEA]] = metadata !{metadata !"A", metadata !{{.*}}}
79 ; CHECK: [[TAGB]] = metadata !{metadata [[TYPEB:!.*]], metadata [[TYPEB]], i64 0}
80 ; CHECK: [[TYPEB]] = metadata !{metadata !"B", metadata [[TYPEA]]}
81 ; CHECK: [[TAGA]] = metadata !{metadata [[TYPEA]], metadata [[TYPEA]], i64 0}
82 !0 = metadata !{metadata !5, metadata !5, i64 0}
83 !1 = metadata !{metadata !6, metadata !6, i64 0}
7884 !2 = metadata !{metadata !"tbaa root", null}
79 !3 = metadata !{metadata !"B", metadata !1}
80 !4 = metadata !{metadata !"another root", null}
85 !3 = metadata !{metadata !7, metadata !7, i64 0}
86 !4 = metadata !{metadata !8, metadata !8, i64 0}
87 !5 = metadata !{metadata !"C", metadata !6}
88 !6 = metadata !{metadata !"A", metadata !2}
89 !7 = metadata !{metadata !"B", metadata !6}
90 !8 = metadata !{metadata !"another root", null}
112112 ; CHECK-NEXT: store i32 %storemerge, i32* %gi, align 4, !tbaa !0
113113 }
114114
115 !0 = metadata !{metadata !"int", metadata !1}
115 !0 = metadata !{metadata !4, metadata !4, i64 0}
116116 !1 = metadata !{metadata !"omnipotent char", metadata !2}
117117 !2 = metadata !{metadata !"Simple C/C++ TBAA"}
118118 !3 = metadata !{metadata !"float", metadata !1}
119 !4 = metadata !{metadata !"int", metadata !1}
3434 ret i32 (i8*, i32*, double*)*** %tmp2
3535 }
3636
37 ; CHECK: !0 = metadata !{metadata !"float", metadata !1}
37 ; CHECK: !0 = metadata !{metadata !1, metadata !1, i64 0}
38 ; CHECK: !1 = metadata !{metadata !"float", metadata !2}
3839
3940 !0 = metadata !{metadata !"Simple C/C++ TBAA"}
4041 !1 = metadata !{metadata !"omnipotent char", metadata !0}
41 !2 = metadata !{metadata !"float", metadata !0}
42 !2 = metadata !{metadata !5, metadata !5, i64 0}
4243 !3 = metadata !{i64 0, i64 4, metadata !2}
4344 !4 = metadata !{i64 0, i64 8, null}
45 !5 = metadata !{metadata !"float", metadata !0}
7474 ret i32 %res.0
7575 }
7676
77 !0 = metadata !{metadata !"int", metadata !1}
77 !0 = metadata !{metadata !3, metadata !3, i64 0}
7878 !1 = metadata !{metadata !"omnipotent char", metadata !2}
7979 !2 = metadata !{metadata !"Simple C/C++ TBAA", null}
80
80 !3 = metadata !{metadata !"int", metadata !1}
2929 ret void
3030 }
3131
32 !0 = metadata !{metadata !"any pointer", metadata !1}
32 !0 = metadata !{metadata !5, metadata !5, i64 0}
3333 !1 = metadata !{metadata !"omnipotent char", metadata !2}
3434 !2 = metadata !{metadata !"Simple C/C++ TBAA", null}
3535 !3 = metadata !{metadata !"short", metadata !1}
36 !4 = metadata !{metadata !"int", metadata !1}
36 !4 = metadata !{metadata !6, metadata !6, i64 0}
37 !5 = metadata !{metadata !"any pointer", metadata !1}
38 !6 = metadata !{metadata !"int", metadata !1}
3636 }
3737
3838 !0 = metadata !{metadata !"minimal TBAA"}
39 !1 = metadata !{metadata !"float", metadata !0}
40 !2 = metadata !{metadata !"int", metadata !0}
39 !1 = metadata !{metadata !3, metadata !3, i64 0}
40 !2 = metadata !{metadata !4, metadata !4, i64 0}
41 !3 = metadata !{metadata !"float", metadata !0}
42 !4 = metadata !{metadata !"int", metadata !0}
180180 ; CHECK-NEXT: store i32 %inc, i32* %gi, align 4, !tbaa !0
181181 }
182182
183 !0 = metadata !{metadata !"int", metadata !1}
183 !0 = metadata !{metadata !4, metadata !4, i64 0}
184184 !1 = metadata !{metadata !"omnipotent char", metadata !2}
185185 !2 = metadata !{metadata !"Simple C/C++ TBAA"}
186 !3 = metadata !{metadata !"float", metadata !1}
186 !3 = metadata !{metadata !5, metadata !5, i64 0}
187 !4 = metadata !{metadata !"int", metadata !1}
188 !5 = metadata !{metadata !"float", metadata !1}