Skip to content

Commit 7787328

Browse files
authored
[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` ```
1 parent 639e1fa commit 7787328

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

clang/lib/CodeGen/BackendUtil.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -789,13 +789,12 @@ static void addSanitizers(const Triple &TargetTriple,
789789
}
790790

791791
if (LowerAllowCheckPass::IsRequested()) {
792-
// We can optimize after inliner, and PGO profile matching. The hook below
793-
// is called at the end `buildFunctionSimplificationPipeline`, which called
794-
// from `buildInlinerPipeline`, which called after profile matching.
795-
PB.registerScalarOptimizerLateEPCallback(
796-
[](FunctionPassManager &FPM, OptimizationLevel Level) {
797-
FPM.addPass(LowerAllowCheckPass());
798-
});
792+
// We want to call it after inline, which is about OptimizerEarlyEPCallback.
793+
PB.registerOptimizerEarlyEPCallback([](ModulePassManager &MPM,
794+
OptimizationLevel Level,
795+
ThinOrFullLTOPhase Phase) {
796+
MPM.addPass(createModuleToFunctionPassAdaptor(LowerAllowCheckPass()));
797+
});
799798
}
800799
}
801800

clang/test/CodeGen/allow-ubsan-check-inline.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ void set(int x);
77
// We will only make decision in the `overflow` function.
88
// NOINL-COUNT-1: remark: Allowed check:
99

10-
// FIXME: We will make decision on every inline.
11-
// INLINE-COUNT-1: remark: Allowed check:
10+
// We will make decision on every inline.
11+
// INLINE-COUNT-5: remark: Allowed check:
1212

1313
static void overflow() {
1414
set(get() + get());

0 commit comments

Comments
 (0)