-
Notifications
You must be signed in to change notification settings - Fork 14.7k
[LowerAllowCheckPass] allow to specify runtime.check hotness #145998
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
Merged
fmayer
merged 2 commits into
main
from
users/fmayer/spr/lowerallowcheckpass-allow-to-specify-runtimecheck-hotness
Jun 27, 2025
Merged
[LowerAllowCheckPass] allow to specify runtime.check hotness #145998
fmayer
merged 2 commits into
main
from
users/fmayer/spr/lowerallowcheckpass-allow-to-specify-runtimecheck-hotness
Jun 27, 2025
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Created using spr 1.3.4
@llvm/pr-subscribers-llvm-transforms Author: Florian Mayer (fmayer) ChangesFull diff: https://github.com/llvm/llvm-project/pull/145998.diff 4 Files Affected:
diff --git a/llvm/include/llvm/Transforms/Instrumentation/LowerAllowCheckPass.h b/llvm/include/llvm/Transforms/Instrumentation/LowerAllowCheckPass.h
index 7b095ea24b4b0..05dd827c2d2e7 100644
--- a/llvm/include/llvm/Transforms/Instrumentation/LowerAllowCheckPass.h
+++ b/llvm/include/llvm/Transforms/Instrumentation/LowerAllowCheckPass.h
@@ -27,6 +27,7 @@ class LowerAllowCheckPass : public PassInfoMixin<LowerAllowCheckPass> {
public:
struct Options {
std::vector<unsigned int> cutoffs;
+ uint64_t runtime_check;
};
explicit LowerAllowCheckPass(LowerAllowCheckPass::Options Opts)
diff --git a/llvm/lib/Passes/PassBuilder.cpp b/llvm/lib/Passes/PassBuilder.cpp
index 4603eaff8ade9..6475cae0551c6 100644
--- a/llvm/lib/Passes/PassBuilder.cpp
+++ b/llvm/lib/Passes/PassBuilder.cpp
@@ -932,6 +932,19 @@ parseLowerAllowCheckPassOptions(StringRef Params) {
Result.cutoffs[index] = cutoff;
}
+ } else if (ParamName.starts_with("runtime_check")) {
+ StringRef ValueString;
+ std::tie(std::ignore, ValueString) = ParamName.split("=");
+ int runtime_check;
+ if (ValueString.getAsInteger(0, runtime_check)) {
+ return make_error<StringError>(
+ formatv("invalid LowerAllowCheck pass runtime_check parameter '{}' "
+ "({})",
+ ValueString, Params)
+ .str(),
+ inconvertibleErrorCode());
+ }
+ Result.runtime_check = runtime_check;
} else {
return make_error<StringError>(
formatv("invalid LowerAllowCheck pass parameter '{}'", ParamName)
diff --git a/llvm/lib/Transforms/Instrumentation/LowerAllowCheckPass.cpp b/llvm/lib/Transforms/Instrumentation/LowerAllowCheckPass.cpp
index f6a273262e535..2538ef9e89f24 100644
--- a/llvm/lib/Transforms/Instrumentation/LowerAllowCheckPass.cpp
+++ b/llvm/lib/Transforms/Instrumentation/LowerAllowCheckPass.cpp
@@ -74,7 +74,7 @@ static void emitRemark(IntrinsicInst *II, OptimizationRemarkEmitter &ORE,
static bool removeUbsanTraps(Function &F, const BlockFrequencyInfo &BFI,
const ProfileSummaryInfo *PSI,
OptimizationRemarkEmitter &ORE,
- const std::vector<unsigned int> &cutoffs) {
+ const LowerAllowCheckPass::Options &Opts) {
SmallVector<std::pair<IntrinsicInst *, bool>, 16> ReplaceWithValue;
std::unique_ptr<RandomNumberGenerator> Rng;
@@ -89,8 +89,10 @@ static bool removeUbsanTraps(Function &F, const BlockFrequencyInfo &BFI,
return HotPercentileCutoff;
else if (II->getIntrinsicID() == Intrinsic::allow_ubsan_check) {
auto *Kind = cast<ConstantInt>(II->getArgOperand(0));
- if (Kind->getZExtValue() < cutoffs.size())
- return cutoffs[Kind->getZExtValue()];
+ if (Kind->getZExtValue() < Opts.cutoffs.size())
+ return Opts.cutoffs[Kind->getZExtValue()];
+ } else if (II->getIntrinsicID() == Intrinsic::allow_runtime_check) {
+ return Opts.runtime_check;
}
return 0;
@@ -157,7 +159,7 @@ PreservedAnalyses LowerAllowCheckPass::run(Function &F,
OptimizationRemarkEmitter &ORE =
AM.getResult<OptimizationRemarkEmitterAnalysis>(F);
- return removeUbsanTraps(F, BFI, PSI, ORE, Opts.cutoffs)
+ return removeUbsanTraps(F, BFI, PSI, ORE, Opts)
// We do not change the CFG, we only replace the intrinsics with
// true or false.
? PreservedAnalyses::none().preserveSet<CFGAnalyses>()
@@ -182,14 +184,22 @@ void LowerAllowCheckPass::printPipeline(
// correctness.
// TODO: print shorter output by combining adjacent runs, etc.
int i = 0;
+ bool printed = false;
for (unsigned int cutoff : Opts.cutoffs) {
if (cutoff > 0) {
if (i > 0)
OS << ";";
OS << "cutoffs[" << i << "]=" << cutoff;
+ printed = true;
}
i++;
}
+ if (Opts.runtime_check) {
+ if (printed)
+ OS << ";";
+ OS << "runtime_check=" << Opts.runtime_check;
+ }
+
OS << '>';
}
diff --git a/llvm/test/Transforms/lower-builtin-allow-check-remarks.ll b/llvm/test/Transforms/lower-builtin-allow-check-remarks.ll
index 190f4b240537e..3030cc02f8689 100644
--- a/llvm/test/Transforms/lower-builtin-allow-check-remarks.ll
+++ b/llvm/test/Transforms/lower-builtin-allow-check-remarks.ll
@@ -4,12 +4,21 @@
; RUN: opt < %s -passes='require<profile-summary>,function(lower-allow-check)' -lower-allow-check-percentile-cutoff-hot=0 -pass-remarks=lower-allow-check -pass-remarks-missed=lower-allow-check -S 2>&1 | FileCheck %s
; RUN: opt < %s -passes='require<profile-summary>,function(lower-allow-check)' -lower-allow-check-percentile-cutoff-hot=1000000 -pass-remarks=lower-allow-check -pass-remarks-missed=lower-allow-check -S 2>&1 | FileCheck %s --check-prefixes=REMOVE
+; RUN: opt < %s -passes='require<profile-summary>,function(lower-allow-check<cutoffs[7]=0;runtime_check=1000000>)' -pass-remarks=lower-allow-check -pass-remarks-missed=lower-allow-check -S 2>&1 | FileCheck %s --check-prefixes=MIXED
+; RUN: opt < %s -passes='require<profile-summary>,function(lower-allow-check<cutoffs[7]=1000000;runtime_check=0>)' -pass-remarks=lower-allow-check -pass-remarks-missed=lower-allow-check -S 2>&1 | FileCheck %s --check-prefixes=MIXED2
+
; CHECK: remark: <unknown>:0:0: Allowed check: Kind=test_check F=test_runtime BB=entry1
; CHECK: remark: <unknown>:0:0: Allowed check: Kind=7 F=test_ubsan BB=entry2
; REMOVE: remark: <unknown>:0:0: Removed check: Kind=test_check F=test_runtime BB=entry1
; REMOVE: remark: <unknown>:0:0: Removed check: Kind=7 F=test_ubsan BB=entry2
+; MIXED: remark: <unknown>:0:0: Removed check: Kind=test_check F=test_runtime BB=entry1
+; MIXED: remark: <unknown>:0:0: Allowed check: Kind=7 F=test_ubsan BB=entry2
+
+; MIXED2: remark: <unknown>:0:0: Allowed check: Kind=test_check F=test_runtime BB=entry1
+; MIXED2: remark: <unknown>:0:0: Removed check: Kind=7 F=test_ubsan BB=entry2
+
target triple = "x86_64-pc-linux-gnu"
define i1 @test_runtime() local_unnamed_addr {
|
vitalybuka
reviewed
Jun 27, 2025
llvm/include/llvm/Transforms/Instrumentation/LowerAllowCheckPass.h
Outdated
Show resolved
Hide resolved
vitalybuka
reviewed
Jun 27, 2025
vitalybuka
approved these changes
Jun 27, 2025
vitalybuka
approved these changes
Jun 27, 2025
rlavaee
pushed a commit
to rlavaee/llvm-project
that referenced
this pull request
Jul 1, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.