[clang] 7787328 - [ubsan] Improve lowering of @llvm.allow.ubsan.check (#119013)
via cfe-commits
cfe-commits at lists.llvm.org
Sat Dec 7 16:13:01 PST 2024
Author: Vitaly Buka
Date: 2024-12-07T16:12:58-08:00
New Revision: 7787328dd64c750c7acf30b86b31f0d7166c8f27
URL: https://github.com/llvm/llvm-project/commit/7787328dd64c750c7acf30b86b31f0d7166c8f27
DIFF: https://github.com/llvm/llvm-project/commit/7787328dd64c750c7acf30b86b31f0d7166c8f27.diff
LOG: [ubsan] Improve lowering of @llvm.allow.ubsan.check (#119013)
This fix the case, when single hot inlined callsite, prevent
checks for all other. This helps to reduce number of removed checks up
to 50% (deppedes on `cutoff-hot` value) .
`ScalarOptimizerLateEPCallback` was happening during
CGSCC walk, after each inlining, but this is effectively
after inlining.
Example, order in comments:
```
static void overflow() {
// 1. Inline get/set if possible
// 2. Simplify
// 3. LowerAllowCheckPass
set(get() + get());
}
void test() {
// 4. Inline
// 5. Nothing for LowerAllowCheckPass
overflow();
}
```
With this patch it will look like:
```
static void overflow() {
// 1. Inline get/set if possible
// 2. Simplify
set(get() + get());
}
void test() {
// 3. Inline
// 4. Simplify
overflow();
}
// Later, after inliner CGSCC walk complete:
// 5. LowerAllowCheckPass for `overflow`
// 6. LowerAllowCheckPass for `test`
```
Added:
Modified:
clang/lib/CodeGen/BackendUtil.cpp
clang/test/CodeGen/allow-ubsan-check-inline.c
Removed:
################################################################################
diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp
index fbb3fb6e5ea423..8cf44592a17475 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -789,13 +789,12 @@ static void addSanitizers(const Triple &TargetTriple,
}
if (LowerAllowCheckPass::IsRequested()) {
- // We can optimize after inliner, and PGO profile matching. The hook below
- // is called at the end `buildFunctionSimplificationPipeline`, which called
- // from `buildInlinerPipeline`, which called after profile matching.
- PB.registerScalarOptimizerLateEPCallback(
- [](FunctionPassManager &FPM, OptimizationLevel Level) {
- FPM.addPass(LowerAllowCheckPass());
- });
+ // We want to call it after inline, which is about OptimizerEarlyEPCallback.
+ PB.registerOptimizerEarlyEPCallback([](ModulePassManager &MPM,
+ OptimizationLevel Level,
+ ThinOrFullLTOPhase Phase) {
+ MPM.addPass(createModuleToFunctionPassAdaptor(LowerAllowCheckPass()));
+ });
}
}
diff --git a/clang/test/CodeGen/allow-ubsan-check-inline.c b/clang/test/CodeGen/allow-ubsan-check-inline.c
index cabe76d8034d77..1de24ab90dac0e 100644
--- a/clang/test/CodeGen/allow-ubsan-check-inline.c
+++ b/clang/test/CodeGen/allow-ubsan-check-inline.c
@@ -7,8 +7,8 @@ void set(int x);
// We will only make decision in the `overflow` function.
// NOINL-COUNT-1: remark: Allowed check:
-// FIXME: We will make decision on every inline.
-// INLINE-COUNT-1: remark: Allowed check:
+// We will make decision on every inline.
+// INLINE-COUNT-5: remark: Allowed check:
static void overflow() {
set(get() + get());
More information about the cfe-commits
mailing list