Skip to content

Commit 4c4ffd3

Browse files
[ProfCheck] Refactor Select Instrumentation to use Early Exits (#168086)
I think this is quite a bit more readable than the nested conditionals. From review feedback that was not addressed precommitn in #167973.
1 parent e8cc0d2 commit 4c4ffd3

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

llvm/lib/Transforms/Utils/ProfileVerify.cpp

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,14 @@ bool ProfileInjector::inject() {
102102
for (auto &BB : F) {
103103
if (AnnotateSelect) {
104104
for (auto &I : BB) {
105-
if (auto *SI = dyn_cast<SelectInst>(&I))
106-
if (!SI->getCondition()->getType()->isVectorTy() &&
107-
!I.getMetadata(LLVMContext::MD_prof))
108-
setBranchWeights(I, {SelectTrueWeight, SelectFalseWeight},
109-
/*IsExpected=*/false);
105+
if (auto *SI = dyn_cast<SelectInst>(&I)) {
106+
if (SI->getCondition()->getType()->isVectorTy())
107+
continue;
108+
if (I.getMetadata(LLVMContext::MD_prof))
109+
continue;
110+
setBranchWeights(I, {SelectTrueWeight, SelectFalseWeight},
111+
/*IsExpected=*/false);
112+
}
110113
}
111114
}
112115
auto *Term = getTerminatorBenefitingFromMDProf(BB);
@@ -187,11 +190,14 @@ PreservedAnalyses ProfileVerifierPass::run(Function &F,
187190
for (const auto &BB : F) {
188191
if (AnnotateSelect) {
189192
for (const auto &I : BB)
190-
if (auto *SI = dyn_cast<SelectInst>(&I))
191-
if (!SI->getCondition()->getType()->isVectorTy() &&
192-
!I.getMetadata(LLVMContext::MD_prof))
193-
F.getContext().emitError(
194-
"Profile verification failed: select annotation missing");
193+
if (auto *SI = dyn_cast<SelectInst>(&I)) {
194+
if (SI->getCondition()->getType()->isVectorTy())
195+
continue;
196+
if (I.getMetadata(LLVMContext::MD_prof))
197+
continue;
198+
F.getContext().emitError(
199+
"Profile verification failed: select annotation missing");
200+
}
195201
}
196202
if (const auto *Term =
197203
ProfileInjector::getTerminatorBenefitingFromMDProf(BB))

0 commit comments

Comments
 (0)