-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[IR][PGO] Verify invalid MD_prof
metadata on instructions
#145576
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[IR][PGO] Verify invalid MD_prof
metadata on instructions
#145576
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
5be0d4b
to
abf3112
Compare
@llvm/pr-subscribers-llvm-ir Author: Mircea Trofin (mtrofin) ChangesThis PR moves the validation of Full diff: https://github.com/llvm/llvm-project/pull/145576.diff 4 Files Affected:
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 71261343b3482..ae95e3e2bff8d 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -5008,6 +5008,9 @@ void Verifier::visitProfMetadata(Instruction &I, MDNode *MD) {
Check(mdconst::dyn_extract<ConstantInt>(MDO),
"!prof brunch_weights operand is not a const int");
}
+ } else {
+ Check(ProfName == "VP", "expected either branch_weights or VP profile name",
+ MD);
}
}
diff --git a/llvm/test/Bitcode/branch-weight-invalid.ll b/llvm/test/Bitcode/branch-weight-invalid.ll
new file mode 100644
index 0000000000000..9247d69fe2521
--- /dev/null
+++ b/llvm/test/Bitcode/branch-weight-invalid.ll
@@ -0,0 +1,28 @@
+; Test MD_prof validation
+
+; RUN: split-file %s %t
+; not opt -passes=verify %t/invalid1 --disable-output 2>&1 | FileCheck %s
+; not opt -passes=verify %t/invalid2 --disable-output 2>&1 | FileCheck %s
+
+;--- invalid1.ll
+define void @test(i1 %0) {
+ br i1 %0, label %2, label %3, !prof !0
+2:
+ ret void
+3:
+ ret void
+}
+!0 = !{!"invalid", i32 1, i32 2}
+
+;--- invalid2.ll
+define void @test(i1 %0) {
+ br i1 %0, label %2, label %3, !prof !0
+2:
+ ret void
+3:
+ ret void
+}
+
+!0 = !{!"function_entry_count", i32 1}
+
+; CHECK: expected either branch_weights or VP profile name
\ No newline at end of file
diff --git a/llvm/test/Transforms/SimplifyCFG/preserve-branchweights.ll b/llvm/test/Transforms/SimplifyCFG/preserve-branchweights.ll
index fb607c72a0e35..5bc0aa07a9e10 100644
--- a/llvm/test/Transforms/SimplifyCFG/preserve-branchweights.ll
+++ b/llvm/test/Transforms/SimplifyCFG/preserve-branchweights.ll
@@ -38,45 +38,12 @@ Z:
ret void
}
-; Make sure the metadata name string is "branch_weights" before propagating it.
-
-define void @fake_weights(i1 %a, i1 %b) {
-; CHECK-LABEL: @fake_weights(
-; CHECK-NEXT: entry:
-; CHECK-NEXT: [[A_NOT:%.*]] = xor i1 [[A:%.*]], true
-; CHECK-NEXT: [[C:%.*]] = or i1 [[B:%.*]], false
-; CHECK-NEXT: [[OR_COND:%.*]] = select i1 [[A_NOT]], i1 [[C]], i1 false
-; CHECK-NEXT: br i1 [[OR_COND]], label [[Z:%.*]], label [[Y:%.*]], !prof [[PROF1:![0-9]+]]
-; CHECK: common.ret:
-; CHECK-NEXT: ret void
-; CHECK: Y:
-; CHECK-NEXT: call void @helper(i32 0)
-; CHECK-NEXT: br label [[COMMON_RET:%.*]]
-; CHECK: Z:
-; CHECK-NEXT: call void @helper(i32 1)
-; CHECK-NEXT: br label [[COMMON_RET]]
-;
-entry:
- br i1 %a, label %Y, label %X, !prof !12
-X:
- %c = or i1 %b, false
- br i1 %c, label %Z, label %Y, !prof !1
-
-Y:
- call void @helper(i32 0)
- ret void
-
-Z:
- call void @helper(i32 1)
- ret void
-}
-
define void @test2(i1 %a, i1 %b) {
; CHECK-LABEL: @test2(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[C:%.*]] = or i1 [[B:%.*]], false
; CHECK-NEXT: [[OR_COND:%.*]] = select i1 [[A:%.*]], i1 [[C]], i1 false
-; CHECK-NEXT: br i1 [[OR_COND]], label [[Z:%.*]], label [[Y:%.*]], !prof [[PROF2:![0-9]+]]
+; CHECK-NEXT: br i1 [[OR_COND]], label [[Z:%.*]], label [[Y:%.*]], !prof [[PROF1:![0-9]+]]
; CHECK: common.ret:
; CHECK-NEXT: ret void
; CHECK: Y:
@@ -107,7 +74,7 @@ define void @test3(i1 %a, i1 %b) {
; CHECK-NEXT: entry:
; CHECK-NEXT: [[C:%.*]] = or i1 [[B:%.*]], false
; CHECK-NEXT: [[OR_COND:%.*]] = select i1 [[A:%.*]], i1 [[C]], i1 false
-; CHECK-NEXT: br i1 [[OR_COND]], label [[Z:%.*]], label [[Y:%.*]], !prof [[PROF1]]
+; CHECK-NEXT: br i1 [[OR_COND]], label [[Z:%.*]], label [[Y:%.*]], !prof [[PROF2:![0-9]+]]
; CHECK: common.ret:
; CHECK-NEXT: ret void
; CHECK: Y:
@@ -138,7 +105,7 @@ define void @test4(i1 %a, i1 %b) {
; CHECK-NEXT: entry:
; CHECK-NEXT: [[C:%.*]] = or i1 [[B:%.*]], false
; CHECK-NEXT: [[OR_COND:%.*]] = select i1 [[A:%.*]], i1 [[C]], i1 false
-; CHECK-NEXT: br i1 [[OR_COND]], label [[Z:%.*]], label [[Y:%.*]], !prof [[PROF1]]
+; CHECK-NEXT: br i1 [[OR_COND]], label [[Z:%.*]], label [[Y:%.*]], !prof [[PROF2]]
; CHECK: common.ret:
; CHECK-NEXT: ret void
; CHECK: Y:
@@ -1136,8 +1103,8 @@ exit:
; CHECK: attributes #[[ATTR2:[0-9]+]] = { noredzone nounwind ssp memory(none) }
;.
; CHECK: [[PROF0]] = !{!"branch_weights", i32 5, i32 11}
-; CHECK: [[PROF1]] = !{!"branch_weights", i32 1, i32 3}
-; CHECK: [[PROF2]] = !{!"branch_weights", i32 1, i32 5}
+; CHECK: [[PROF1]] = !{!"branch_weights", i32 1, i32 5}
+; CHECK: [[PROF2]] = !{!"branch_weights", i32 1, i32 3}
; CHECK: [[PROF3]] = !{!"branch_weights", i32 7, i32 1, i32 2}
; CHECK: [[PROF4]] = !{!"branch_weights", i32 49, i32 12, i32 24, i32 35}
; CHECK: [[PROF5]] = !{!"branch_weights", i32 11, i32 5}
diff --git a/mlir/test/Target/LLVMIR/Import/import-failure.ll b/mlir/test/Target/LLVMIR/Import/import-failure.ll
index a05a2b4bd4507..d48be66f2063e 100644
--- a/mlir/test/Target/LLVMIR/Import/import-failure.ll
+++ b/mlir/test/Target/LLVMIR/Import/import-failure.ll
@@ -258,22 +258,6 @@ end:
; // -----
-; CHECK: <unknown>
-; CHECK-SAME: warning: expected function_entry_count to be attached to a function
-; CHECK: warning: unhandled metadata: !0 = !{!"function_entry_count", i64 42}
-define void @cond_br(i1 %arg) {
-entry:
- br i1 %arg, label %bb1, label %bb2, !prof !0
-bb1:
- ret void
-bb2:
- ret void
-}
-
-!0 = !{!"function_entry_count", i64 42}
-
-; // -----
-
; CHECK: <unknown>
; CHECK-SAME: warning: dropped instruction: call void @llvm.experimental.noalias.scope.decl(metadata !0)
define void @unused_scope() {
|
@llvm/pr-subscribers-mlir-llvm Author: Mircea Trofin (mtrofin) ChangesThis PR moves the validation of Full diff: https://github.com/llvm/llvm-project/pull/145576.diff 4 Files Affected:
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 71261343b3482..ae95e3e2bff8d 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -5008,6 +5008,9 @@ void Verifier::visitProfMetadata(Instruction &I, MDNode *MD) {
Check(mdconst::dyn_extract<ConstantInt>(MDO),
"!prof brunch_weights operand is not a const int");
}
+ } else {
+ Check(ProfName == "VP", "expected either branch_weights or VP profile name",
+ MD);
}
}
diff --git a/llvm/test/Bitcode/branch-weight-invalid.ll b/llvm/test/Bitcode/branch-weight-invalid.ll
new file mode 100644
index 0000000000000..9247d69fe2521
--- /dev/null
+++ b/llvm/test/Bitcode/branch-weight-invalid.ll
@@ -0,0 +1,28 @@
+; Test MD_prof validation
+
+; RUN: split-file %s %t
+; not opt -passes=verify %t/invalid1 --disable-output 2>&1 | FileCheck %s
+; not opt -passes=verify %t/invalid2 --disable-output 2>&1 | FileCheck %s
+
+;--- invalid1.ll
+define void @test(i1 %0) {
+ br i1 %0, label %2, label %3, !prof !0
+2:
+ ret void
+3:
+ ret void
+}
+!0 = !{!"invalid", i32 1, i32 2}
+
+;--- invalid2.ll
+define void @test(i1 %0) {
+ br i1 %0, label %2, label %3, !prof !0
+2:
+ ret void
+3:
+ ret void
+}
+
+!0 = !{!"function_entry_count", i32 1}
+
+; CHECK: expected either branch_weights or VP profile name
\ No newline at end of file
diff --git a/llvm/test/Transforms/SimplifyCFG/preserve-branchweights.ll b/llvm/test/Transforms/SimplifyCFG/preserve-branchweights.ll
index fb607c72a0e35..5bc0aa07a9e10 100644
--- a/llvm/test/Transforms/SimplifyCFG/preserve-branchweights.ll
+++ b/llvm/test/Transforms/SimplifyCFG/preserve-branchweights.ll
@@ -38,45 +38,12 @@ Z:
ret void
}
-; Make sure the metadata name string is "branch_weights" before propagating it.
-
-define void @fake_weights(i1 %a, i1 %b) {
-; CHECK-LABEL: @fake_weights(
-; CHECK-NEXT: entry:
-; CHECK-NEXT: [[A_NOT:%.*]] = xor i1 [[A:%.*]], true
-; CHECK-NEXT: [[C:%.*]] = or i1 [[B:%.*]], false
-; CHECK-NEXT: [[OR_COND:%.*]] = select i1 [[A_NOT]], i1 [[C]], i1 false
-; CHECK-NEXT: br i1 [[OR_COND]], label [[Z:%.*]], label [[Y:%.*]], !prof [[PROF1:![0-9]+]]
-; CHECK: common.ret:
-; CHECK-NEXT: ret void
-; CHECK: Y:
-; CHECK-NEXT: call void @helper(i32 0)
-; CHECK-NEXT: br label [[COMMON_RET:%.*]]
-; CHECK: Z:
-; CHECK-NEXT: call void @helper(i32 1)
-; CHECK-NEXT: br label [[COMMON_RET]]
-;
-entry:
- br i1 %a, label %Y, label %X, !prof !12
-X:
- %c = or i1 %b, false
- br i1 %c, label %Z, label %Y, !prof !1
-
-Y:
- call void @helper(i32 0)
- ret void
-
-Z:
- call void @helper(i32 1)
- ret void
-}
-
define void @test2(i1 %a, i1 %b) {
; CHECK-LABEL: @test2(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[C:%.*]] = or i1 [[B:%.*]], false
; CHECK-NEXT: [[OR_COND:%.*]] = select i1 [[A:%.*]], i1 [[C]], i1 false
-; CHECK-NEXT: br i1 [[OR_COND]], label [[Z:%.*]], label [[Y:%.*]], !prof [[PROF2:![0-9]+]]
+; CHECK-NEXT: br i1 [[OR_COND]], label [[Z:%.*]], label [[Y:%.*]], !prof [[PROF1:![0-9]+]]
; CHECK: common.ret:
; CHECK-NEXT: ret void
; CHECK: Y:
@@ -107,7 +74,7 @@ define void @test3(i1 %a, i1 %b) {
; CHECK-NEXT: entry:
; CHECK-NEXT: [[C:%.*]] = or i1 [[B:%.*]], false
; CHECK-NEXT: [[OR_COND:%.*]] = select i1 [[A:%.*]], i1 [[C]], i1 false
-; CHECK-NEXT: br i1 [[OR_COND]], label [[Z:%.*]], label [[Y:%.*]], !prof [[PROF1]]
+; CHECK-NEXT: br i1 [[OR_COND]], label [[Z:%.*]], label [[Y:%.*]], !prof [[PROF2:![0-9]+]]
; CHECK: common.ret:
; CHECK-NEXT: ret void
; CHECK: Y:
@@ -138,7 +105,7 @@ define void @test4(i1 %a, i1 %b) {
; CHECK-NEXT: entry:
; CHECK-NEXT: [[C:%.*]] = or i1 [[B:%.*]], false
; CHECK-NEXT: [[OR_COND:%.*]] = select i1 [[A:%.*]], i1 [[C]], i1 false
-; CHECK-NEXT: br i1 [[OR_COND]], label [[Z:%.*]], label [[Y:%.*]], !prof [[PROF1]]
+; CHECK-NEXT: br i1 [[OR_COND]], label [[Z:%.*]], label [[Y:%.*]], !prof [[PROF2]]
; CHECK: common.ret:
; CHECK-NEXT: ret void
; CHECK: Y:
@@ -1136,8 +1103,8 @@ exit:
; CHECK: attributes #[[ATTR2:[0-9]+]] = { noredzone nounwind ssp memory(none) }
;.
; CHECK: [[PROF0]] = !{!"branch_weights", i32 5, i32 11}
-; CHECK: [[PROF1]] = !{!"branch_weights", i32 1, i32 3}
-; CHECK: [[PROF2]] = !{!"branch_weights", i32 1, i32 5}
+; CHECK: [[PROF1]] = !{!"branch_weights", i32 1, i32 5}
+; CHECK: [[PROF2]] = !{!"branch_weights", i32 1, i32 3}
; CHECK: [[PROF3]] = !{!"branch_weights", i32 7, i32 1, i32 2}
; CHECK: [[PROF4]] = !{!"branch_weights", i32 49, i32 12, i32 24, i32 35}
; CHECK: [[PROF5]] = !{!"branch_weights", i32 11, i32 5}
diff --git a/mlir/test/Target/LLVMIR/Import/import-failure.ll b/mlir/test/Target/LLVMIR/Import/import-failure.ll
index a05a2b4bd4507..d48be66f2063e 100644
--- a/mlir/test/Target/LLVMIR/Import/import-failure.ll
+++ b/mlir/test/Target/LLVMIR/Import/import-failure.ll
@@ -258,22 +258,6 @@ end:
; // -----
-; CHECK: <unknown>
-; CHECK-SAME: warning: expected function_entry_count to be attached to a function
-; CHECK: warning: unhandled metadata: !0 = !{!"function_entry_count", i64 42}
-define void @cond_br(i1 %arg) {
-entry:
- br i1 %arg, label %bb1, label %bb2, !prof !0
-bb1:
- ret void
-bb2:
- ret void
-}
-
-!0 = !{!"function_entry_count", i64 42}
-
-; // -----
-
; CHECK: <unknown>
; CHECK-SAME: warning: dropped instruction: call void @llvm.experimental.noalias.scope.decl(metadata !0)
define void @unused_scope() {
|
@llvm/pr-subscribers-llvm-transforms Author: Mircea Trofin (mtrofin) ChangesThis PR moves the validation of Full diff: https://github.com/llvm/llvm-project/pull/145576.diff 4 Files Affected:
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 71261343b3482..ae95e3e2bff8d 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -5008,6 +5008,9 @@ void Verifier::visitProfMetadata(Instruction &I, MDNode *MD) {
Check(mdconst::dyn_extract<ConstantInt>(MDO),
"!prof brunch_weights operand is not a const int");
}
+ } else {
+ Check(ProfName == "VP", "expected either branch_weights or VP profile name",
+ MD);
}
}
diff --git a/llvm/test/Bitcode/branch-weight-invalid.ll b/llvm/test/Bitcode/branch-weight-invalid.ll
new file mode 100644
index 0000000000000..9247d69fe2521
--- /dev/null
+++ b/llvm/test/Bitcode/branch-weight-invalid.ll
@@ -0,0 +1,28 @@
+; Test MD_prof validation
+
+; RUN: split-file %s %t
+; not opt -passes=verify %t/invalid1 --disable-output 2>&1 | FileCheck %s
+; not opt -passes=verify %t/invalid2 --disable-output 2>&1 | FileCheck %s
+
+;--- invalid1.ll
+define void @test(i1 %0) {
+ br i1 %0, label %2, label %3, !prof !0
+2:
+ ret void
+3:
+ ret void
+}
+!0 = !{!"invalid", i32 1, i32 2}
+
+;--- invalid2.ll
+define void @test(i1 %0) {
+ br i1 %0, label %2, label %3, !prof !0
+2:
+ ret void
+3:
+ ret void
+}
+
+!0 = !{!"function_entry_count", i32 1}
+
+; CHECK: expected either branch_weights or VP profile name
\ No newline at end of file
diff --git a/llvm/test/Transforms/SimplifyCFG/preserve-branchweights.ll b/llvm/test/Transforms/SimplifyCFG/preserve-branchweights.ll
index fb607c72a0e35..5bc0aa07a9e10 100644
--- a/llvm/test/Transforms/SimplifyCFG/preserve-branchweights.ll
+++ b/llvm/test/Transforms/SimplifyCFG/preserve-branchweights.ll
@@ -38,45 +38,12 @@ Z:
ret void
}
-; Make sure the metadata name string is "branch_weights" before propagating it.
-
-define void @fake_weights(i1 %a, i1 %b) {
-; CHECK-LABEL: @fake_weights(
-; CHECK-NEXT: entry:
-; CHECK-NEXT: [[A_NOT:%.*]] = xor i1 [[A:%.*]], true
-; CHECK-NEXT: [[C:%.*]] = or i1 [[B:%.*]], false
-; CHECK-NEXT: [[OR_COND:%.*]] = select i1 [[A_NOT]], i1 [[C]], i1 false
-; CHECK-NEXT: br i1 [[OR_COND]], label [[Z:%.*]], label [[Y:%.*]], !prof [[PROF1:![0-9]+]]
-; CHECK: common.ret:
-; CHECK-NEXT: ret void
-; CHECK: Y:
-; CHECK-NEXT: call void @helper(i32 0)
-; CHECK-NEXT: br label [[COMMON_RET:%.*]]
-; CHECK: Z:
-; CHECK-NEXT: call void @helper(i32 1)
-; CHECK-NEXT: br label [[COMMON_RET]]
-;
-entry:
- br i1 %a, label %Y, label %X, !prof !12
-X:
- %c = or i1 %b, false
- br i1 %c, label %Z, label %Y, !prof !1
-
-Y:
- call void @helper(i32 0)
- ret void
-
-Z:
- call void @helper(i32 1)
- ret void
-}
-
define void @test2(i1 %a, i1 %b) {
; CHECK-LABEL: @test2(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[C:%.*]] = or i1 [[B:%.*]], false
; CHECK-NEXT: [[OR_COND:%.*]] = select i1 [[A:%.*]], i1 [[C]], i1 false
-; CHECK-NEXT: br i1 [[OR_COND]], label [[Z:%.*]], label [[Y:%.*]], !prof [[PROF2:![0-9]+]]
+; CHECK-NEXT: br i1 [[OR_COND]], label [[Z:%.*]], label [[Y:%.*]], !prof [[PROF1:![0-9]+]]
; CHECK: common.ret:
; CHECK-NEXT: ret void
; CHECK: Y:
@@ -107,7 +74,7 @@ define void @test3(i1 %a, i1 %b) {
; CHECK-NEXT: entry:
; CHECK-NEXT: [[C:%.*]] = or i1 [[B:%.*]], false
; CHECK-NEXT: [[OR_COND:%.*]] = select i1 [[A:%.*]], i1 [[C]], i1 false
-; CHECK-NEXT: br i1 [[OR_COND]], label [[Z:%.*]], label [[Y:%.*]], !prof [[PROF1]]
+; CHECK-NEXT: br i1 [[OR_COND]], label [[Z:%.*]], label [[Y:%.*]], !prof [[PROF2:![0-9]+]]
; CHECK: common.ret:
; CHECK-NEXT: ret void
; CHECK: Y:
@@ -138,7 +105,7 @@ define void @test4(i1 %a, i1 %b) {
; CHECK-NEXT: entry:
; CHECK-NEXT: [[C:%.*]] = or i1 [[B:%.*]], false
; CHECK-NEXT: [[OR_COND:%.*]] = select i1 [[A:%.*]], i1 [[C]], i1 false
-; CHECK-NEXT: br i1 [[OR_COND]], label [[Z:%.*]], label [[Y:%.*]], !prof [[PROF1]]
+; CHECK-NEXT: br i1 [[OR_COND]], label [[Z:%.*]], label [[Y:%.*]], !prof [[PROF2]]
; CHECK: common.ret:
; CHECK-NEXT: ret void
; CHECK: Y:
@@ -1136,8 +1103,8 @@ exit:
; CHECK: attributes #[[ATTR2:[0-9]+]] = { noredzone nounwind ssp memory(none) }
;.
; CHECK: [[PROF0]] = !{!"branch_weights", i32 5, i32 11}
-; CHECK: [[PROF1]] = !{!"branch_weights", i32 1, i32 3}
-; CHECK: [[PROF2]] = !{!"branch_weights", i32 1, i32 5}
+; CHECK: [[PROF1]] = !{!"branch_weights", i32 1, i32 5}
+; CHECK: [[PROF2]] = !{!"branch_weights", i32 1, i32 3}
; CHECK: [[PROF3]] = !{!"branch_weights", i32 7, i32 1, i32 2}
; CHECK: [[PROF4]] = !{!"branch_weights", i32 49, i32 12, i32 24, i32 35}
; CHECK: [[PROF5]] = !{!"branch_weights", i32 11, i32 5}
diff --git a/mlir/test/Target/LLVMIR/Import/import-failure.ll b/mlir/test/Target/LLVMIR/Import/import-failure.ll
index a05a2b4bd4507..d48be66f2063e 100644
--- a/mlir/test/Target/LLVMIR/Import/import-failure.ll
+++ b/mlir/test/Target/LLVMIR/Import/import-failure.ll
@@ -258,22 +258,6 @@ end:
; // -----
-; CHECK: <unknown>
-; CHECK-SAME: warning: expected function_entry_count to be attached to a function
-; CHECK: warning: unhandled metadata: !0 = !{!"function_entry_count", i64 42}
-define void @cond_br(i1 %arg) {
-entry:
- br i1 %arg, label %bb1, label %bb2, !prof !0
-bb1:
- ret void
-bb2:
- ret void
-}
-
-!0 = !{!"function_entry_count", i64 42}
-
-; // -----
-
; CHECK: <unknown>
; CHECK-SAME: warning: dropped instruction: call void @llvm.experimental.noalias.scope.decl(metadata !0)
define void @unused_scope() {
|
@llvm/pr-subscribers-mlir Author: Mircea Trofin (mtrofin) ChangesThis PR moves the validation of Full diff: https://github.com/llvm/llvm-project/pull/145576.diff 4 Files Affected:
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 71261343b3482..ae95e3e2bff8d 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -5008,6 +5008,9 @@ void Verifier::visitProfMetadata(Instruction &I, MDNode *MD) {
Check(mdconst::dyn_extract<ConstantInt>(MDO),
"!prof brunch_weights operand is not a const int");
}
+ } else {
+ Check(ProfName == "VP", "expected either branch_weights or VP profile name",
+ MD);
}
}
diff --git a/llvm/test/Bitcode/branch-weight-invalid.ll b/llvm/test/Bitcode/branch-weight-invalid.ll
new file mode 100644
index 0000000000000..9247d69fe2521
--- /dev/null
+++ b/llvm/test/Bitcode/branch-weight-invalid.ll
@@ -0,0 +1,28 @@
+; Test MD_prof validation
+
+; RUN: split-file %s %t
+; not opt -passes=verify %t/invalid1 --disable-output 2>&1 | FileCheck %s
+; not opt -passes=verify %t/invalid2 --disable-output 2>&1 | FileCheck %s
+
+;--- invalid1.ll
+define void @test(i1 %0) {
+ br i1 %0, label %2, label %3, !prof !0
+2:
+ ret void
+3:
+ ret void
+}
+!0 = !{!"invalid", i32 1, i32 2}
+
+;--- invalid2.ll
+define void @test(i1 %0) {
+ br i1 %0, label %2, label %3, !prof !0
+2:
+ ret void
+3:
+ ret void
+}
+
+!0 = !{!"function_entry_count", i32 1}
+
+; CHECK: expected either branch_weights or VP profile name
\ No newline at end of file
diff --git a/llvm/test/Transforms/SimplifyCFG/preserve-branchweights.ll b/llvm/test/Transforms/SimplifyCFG/preserve-branchweights.ll
index fb607c72a0e35..5bc0aa07a9e10 100644
--- a/llvm/test/Transforms/SimplifyCFG/preserve-branchweights.ll
+++ b/llvm/test/Transforms/SimplifyCFG/preserve-branchweights.ll
@@ -38,45 +38,12 @@ Z:
ret void
}
-; Make sure the metadata name string is "branch_weights" before propagating it.
-
-define void @fake_weights(i1 %a, i1 %b) {
-; CHECK-LABEL: @fake_weights(
-; CHECK-NEXT: entry:
-; CHECK-NEXT: [[A_NOT:%.*]] = xor i1 [[A:%.*]], true
-; CHECK-NEXT: [[C:%.*]] = or i1 [[B:%.*]], false
-; CHECK-NEXT: [[OR_COND:%.*]] = select i1 [[A_NOT]], i1 [[C]], i1 false
-; CHECK-NEXT: br i1 [[OR_COND]], label [[Z:%.*]], label [[Y:%.*]], !prof [[PROF1:![0-9]+]]
-; CHECK: common.ret:
-; CHECK-NEXT: ret void
-; CHECK: Y:
-; CHECK-NEXT: call void @helper(i32 0)
-; CHECK-NEXT: br label [[COMMON_RET:%.*]]
-; CHECK: Z:
-; CHECK-NEXT: call void @helper(i32 1)
-; CHECK-NEXT: br label [[COMMON_RET]]
-;
-entry:
- br i1 %a, label %Y, label %X, !prof !12
-X:
- %c = or i1 %b, false
- br i1 %c, label %Z, label %Y, !prof !1
-
-Y:
- call void @helper(i32 0)
- ret void
-
-Z:
- call void @helper(i32 1)
- ret void
-}
-
define void @test2(i1 %a, i1 %b) {
; CHECK-LABEL: @test2(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[C:%.*]] = or i1 [[B:%.*]], false
; CHECK-NEXT: [[OR_COND:%.*]] = select i1 [[A:%.*]], i1 [[C]], i1 false
-; CHECK-NEXT: br i1 [[OR_COND]], label [[Z:%.*]], label [[Y:%.*]], !prof [[PROF2:![0-9]+]]
+; CHECK-NEXT: br i1 [[OR_COND]], label [[Z:%.*]], label [[Y:%.*]], !prof [[PROF1:![0-9]+]]
; CHECK: common.ret:
; CHECK-NEXT: ret void
; CHECK: Y:
@@ -107,7 +74,7 @@ define void @test3(i1 %a, i1 %b) {
; CHECK-NEXT: entry:
; CHECK-NEXT: [[C:%.*]] = or i1 [[B:%.*]], false
; CHECK-NEXT: [[OR_COND:%.*]] = select i1 [[A:%.*]], i1 [[C]], i1 false
-; CHECK-NEXT: br i1 [[OR_COND]], label [[Z:%.*]], label [[Y:%.*]], !prof [[PROF1]]
+; CHECK-NEXT: br i1 [[OR_COND]], label [[Z:%.*]], label [[Y:%.*]], !prof [[PROF2:![0-9]+]]
; CHECK: common.ret:
; CHECK-NEXT: ret void
; CHECK: Y:
@@ -138,7 +105,7 @@ define void @test4(i1 %a, i1 %b) {
; CHECK-NEXT: entry:
; CHECK-NEXT: [[C:%.*]] = or i1 [[B:%.*]], false
; CHECK-NEXT: [[OR_COND:%.*]] = select i1 [[A:%.*]], i1 [[C]], i1 false
-; CHECK-NEXT: br i1 [[OR_COND]], label [[Z:%.*]], label [[Y:%.*]], !prof [[PROF1]]
+; CHECK-NEXT: br i1 [[OR_COND]], label [[Z:%.*]], label [[Y:%.*]], !prof [[PROF2]]
; CHECK: common.ret:
; CHECK-NEXT: ret void
; CHECK: Y:
@@ -1136,8 +1103,8 @@ exit:
; CHECK: attributes #[[ATTR2:[0-9]+]] = { noredzone nounwind ssp memory(none) }
;.
; CHECK: [[PROF0]] = !{!"branch_weights", i32 5, i32 11}
-; CHECK: [[PROF1]] = !{!"branch_weights", i32 1, i32 3}
-; CHECK: [[PROF2]] = !{!"branch_weights", i32 1, i32 5}
+; CHECK: [[PROF1]] = !{!"branch_weights", i32 1, i32 5}
+; CHECK: [[PROF2]] = !{!"branch_weights", i32 1, i32 3}
; CHECK: [[PROF3]] = !{!"branch_weights", i32 7, i32 1, i32 2}
; CHECK: [[PROF4]] = !{!"branch_weights", i32 49, i32 12, i32 24, i32 35}
; CHECK: [[PROF5]] = !{!"branch_weights", i32 11, i32 5}
diff --git a/mlir/test/Target/LLVMIR/Import/import-failure.ll b/mlir/test/Target/LLVMIR/Import/import-failure.ll
index a05a2b4bd4507..d48be66f2063e 100644
--- a/mlir/test/Target/LLVMIR/Import/import-failure.ll
+++ b/mlir/test/Target/LLVMIR/Import/import-failure.ll
@@ -258,22 +258,6 @@ end:
; // -----
-; CHECK: <unknown>
-; CHECK-SAME: warning: expected function_entry_count to be attached to a function
-; CHECK: warning: unhandled metadata: !0 = !{!"function_entry_count", i64 42}
-define void @cond_br(i1 %arg) {
-entry:
- br i1 %arg, label %bb1, label %bb2, !prof !0
-bb1:
- ret void
-bb2:
- ret void
-}
-
-!0 = !{!"function_entry_count", i64 42}
-
-; // -----
-
; CHECK: <unknown>
; CHECK-SAME: warning: dropped instruction: call void @llvm.experimental.noalias.scope.decl(metadata !0)
define void @unused_scope() {
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
abf3112
to
1464876
Compare
1464876
to
3cda0f3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couple comments but otherwise lgtm
3cda0f3
to
8a91105
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM % minor nits.
; RUN: not opt -passes=verify %t/invalid1.ll --disable-output 2>&1 | FileCheck %s | ||
; RUN: not opt -passes=verify %t/invalid2.ll --disable-output 2>&1 | FileCheck %s |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems a bit ad-hoc to share the rely on the check annotation of the source file. I'm unsure how this is done normally, so maybe this is fine(?).
I would probably pass %t/invalid1.ll
and %t/invalid2.ll
to FileCheck
instead of %s
in both cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The usual way to do this is passing %s
to FileCheck but using a different --check-prefix
for each file. But given that the error message is the same here, this should be fine as-is...
8a91105
to
3c77cbc
Compare
This PR places the validation of
MD_prof
instruction metadata in the Verifier.