11; Test MD_prof validation
22
33; RUN: split-file %s %t
4+
45; RUN: opt -passes=verify %t/valid.ll --disable-output
5- ; RUN: not opt -passes=verify %t/invalid1.ll --disable-output 2>&1 | FileCheck %s
6- ; RUN: not opt -passes=verify %t/invalid2.ll --disable-output 2>&1 | FileCheck %s
6+
7+ ; RUN: not opt -passes=verify %t/wrong-count.ll --disable-output 2>&1 | FileCheck %s --check-prefix=WRONG-COUNT
8+ ; RUN: not opt -passes=verify %t/invalid-name1.ll --disable-output 2>&1 | FileCheck %s
9+ ; RUN: not opt -passes=verify %t/invalid-name2.ll --disable-output 2>&1 | FileCheck %s
10+
11+ ; RUN: opt -passes=verify %t/unknown-correct.ll --disable-output
12+
13+ ; RUN: not opt -passes=verify %t/unknown-invalid.ll --disable-output 2>&1 | FileCheck %s
14+ ; RUN: not opt -passes=verify %t/unknown-on-function1.ll --disable-output 2>&1 | FileCheck %s --check-prefix=ON-FUNCTION1
15+ ; RUN: not opt -passes=verify %t/unknown-on-function2.ll --disable-output 2>&1 | FileCheck %s --check-prefix=ON-FUNCTION2
16+ ; RUN: not opt -passes=verify %t/invalid-unknown-placement.ll --disable-output 2>&1 | FileCheck %s --check-prefix=INVALID-UNKNOWN-PLACEMENT
717
818;--- valid.ll
9- define void @test (i1 %0 ) {
10- br i1 %0 , label %2 , label %3 , !prof !0
11- 2 :
19+ declare void @to_invoke ()
20+ declare i32 @__gxx_personality_v0 (...)
21+
22+ define void @invoker () personality ptr @__gxx_personality_v0 {
23+ invoke void @to_invoke () to label %exit unwind label %lpad , !prof !0
24+ lpad:
25+ %ll = landingpad {ptr , i32 }
26+ cleanup
1227 ret void
13- 3 :
28+ exit :
1429 ret void
1530}
31+
32+ define i32 @test (i32 %a ) {
33+ %c = icmp eq i32 %a , 0
34+ br i1 %c , label %yes , label %exit , !prof !0
35+ yes:
36+ switch i32 %a , label %exit [ i32 1 , label %case_b
37+ i32 2 , label %case_c ], !prof !1
38+ case_b:
39+ br label %exit
40+ case_c:
41+ br label %exit
42+ exit:
43+ %r = select i1 %c , i32 1 , i32 2 , !prof !0
44+ ret i32 %r
45+ }
1646!0 = !{!"branch_weights" , i32 1 , i32 2 }
47+ !1 = !{!"branch_weights" , i32 1 , i32 2 , i32 3 }
48+
49+ ;--- wrong-count.ll
50+ define void @test (i32 %a ) {
51+ %c = icmp eq i32 %a , 0
52+ br i1 %c , label %yes , label %no , !prof !0
53+ yes:
54+ ret void
55+ no:
56+ ret void
57+ }
58+ !0 = !{!"branch_weights" , i32 1 , i32 2 , i32 3 }
1759
18- ;--- invalid1.ll
60+ ; WRONG-COUNT: Wrong number of operands
61+
62+ ;--- invalid-name1.ll
1963define void @test (i1 %0 ) {
2064 br i1 %0 , label %2 , label %3 , !prof !0
21652 :
@@ -25,7 +69,7 @@ define void @test(i1 %0) {
2569}
2670!0 = !{!"invalid" , i32 1 , i32 2 }
2771
28- ;--- invalid2 .ll
72+ ;--- invalid-name2 .ll
2973define void @test (i1 %0 ) {
3074 br i1 %0 , label %2 , label %3 , !prof !0
31752 :
@@ -36,4 +80,72 @@ define void @test(i1 %0) {
3680
3781!0 = !{!"function_entry_count" , i32 1 }
3882
39- ; CHECK: expected either branch_weights or VP profile name
83+ ; CHECK: expected either branch_weights or VP profile name
84+
85+ ;--- unknown-correct.ll
86+ declare void @to_invoke ()
87+ declare i32 @__gxx_personality_v0 (...)
88+
89+ define void @invoker () personality ptr @__gxx_personality_v0 {
90+ invoke void @to_invoke () to label %exit unwind label %lpad , !prof !0
91+ lpad:
92+ %ll = landingpad {ptr , i32 }
93+ cleanup
94+ ret void
95+ exit:
96+ ret void
97+ }
98+
99+ define i32 @test (i32 %a ) {
100+ %c = icmp eq i32 %a , 0
101+ br i1 %c , label %yes , label %exit , !prof !0
102+ yes:
103+ switch i32 %a , label %exit [ i32 1 , label %case_b
104+ i32 2 , label %case_c ], !prof !0
105+ case_b:
106+ br label %exit
107+ case_c:
108+ br label %exit
109+ exit:
110+ %r = select i1 %c , i32 1 , i32 2 , !prof !0
111+ ret i32 %r
112+ }
113+
114+ !0 = !{!"unknown" }
115+
116+ ;--- unknown-invalid.ll
117+ define void @test (i32 %a ) {
118+ %c = icmp eq i32 %a , 0
119+ br i1 %c , label %yes , label %no , !prof !0
120+ yes:
121+ ret void
122+ no:
123+ ret void
124+ }
125+
126+ !0 = !{!"unknown" , i32 12 , i32 67 }
127+
128+ ;--- unknown-on-function1.ll
129+ define void @test () !prof !0 {
130+ ret void
131+ }
132+
133+ !0 = !{!"unknown" }
134+ ; ON-FUNCTION1: 'unknown' !prof metadata should appear only on instructions supporting the 'branch_weights' metadata
135+
136+ ;--- unknown-on-function2.ll
137+ define void @test () !prof !0 {
138+ ret void
139+ }
140+
141+ !0 = !{!"unknown" , i64 123 }
142+ ; ON-FUNCTION2: first operand should be 'function_entry_count' or 'synthetic_function_entry_count'
143+
144+ ;--- invalid-unknown-placement.ll
145+ define i32 @test () {
146+ %r = add i32 1 , 2 , !prof !0
147+ ret i32 %r
148+ }
149+ !0 = !{!"unknown" }
150+
151+ ; INVALID-UNKNOWN-PLACEMENT: 'unknown' !prof should only appear on instructions on which 'branch_weigths' would
0 commit comments