Page MenuHomePhabricator

[Sema] Avoid isNullPointerConstant invocation
ClosedPublic

Authored by justinstitt on Aug 9 2022, 5:00 PM.

Details

Summary

DiagnoseNullConversion is needlessly calling isNullPointerConstant which
is an expensive routine due to its calls to a constant evaluator --
which we don't need.

Building the Linux Kernel (x86_64) with this fix has improved build
times by ~2.1%. This is mainly due to the following methods no longer
needing to be called anywhere near as often:

  1. ExprConstant::CheckICE (reduced CPU cycles by ~90%)
  2. IntExprEvaluator::VisitBinaryOperator (reduced CPU cycles by ~50%)

Diff Detail

Event Timeline

justinstitt created this revision.Aug 9 2022, 5:00 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 9 2022, 5:00 PM
Herald added a subscriber: pengfei. · View Herald Transcript
justinstitt requested review of this revision.Aug 9 2022, 5:00 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 9 2022, 5:00 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
justinstitt retitled this revision from [Sema] Only invoke DiagnoseNullConversions for CPlusPlus (-Wnull-conversion) to [Sema] Avoid isNullPointerConstant invocation.
justinstitt edited the summary of this revision. (Show Details)

use @rtrieu 's suggestion regarding not invoking isNullPointerConstant as opposed to checking for C++ lang opt.

rtrieu accepted this revision.Aug 10 2022, 9:00 PM

I think this is a reasonable step for improving compile times. I put some suggestions for more descriptive names below (he said, after suggesting those names in the first place).

The description of this change should mention that expensive part is because isNullPointerConstant makes calls to a constant evaluator which we don't need.

clang/lib/Sema/SemaChecking.cpp
13343

Let's call this IsGNUNullExpr

13344

And let's call this HasNullPtrType

This revision is now accepted and ready to land.Aug 10 2022, 9:00 PM
justinstitt edited the summary of this revision. (Show Details)

add more descriptive names, add more detail to revision summary.

justinstitt marked 2 inline comments as done.Aug 11 2022, 12:47 PM

move return to new line, as per clang-format.

nickdesaulniers accepted this revision.Aug 14 2022, 1:27 PM

Awesome! This makes a measurable improvement in my Linux kernel build times!

Thanks for the patch, and thanks @rtrieu for suggestions that will improve C++ code compilation times as well.

I'll commit this for you since you don't yet have commit access.

Let's keep an eye on https://llvm-compile-time-tracker.com/compare.php to see how this does.

This revision was automatically updated to reflect the committed changes.