Skip to content
  • Sean Silva's avatar
    Add `isRelExprOneOf` helper · 2eed7592
    Sean Silva authored
    In various places in LLD's hot loops, we have expressions of the form
    "E == R_FOO || E == R_BAR || ..." (E is a RelExpr).
    
    Some of these expressions are quite long, and even though they usually go just
    a very small number of ways and so should be well predicted, they can still
    occupy branch predictor resources harming other parts of the code, or they
    won't be predicted well if they overflow branch predictor resources or if the
    branches are too dense and the branch predictor can't track them all (the
    compiler can in theory avoid this, at a cost in text size). And some of these
    expressions are so large and executed so frequently that even when
    well-predicted they probably still have a nontrivial cost.
    
    This speedup should be pretty portable. The cost of these simple bit tests is
    independent of:
    
    - the target we are linking for
    - the distribution of RelExpr's for a given link (which can depend on how the
      input files were compiled)
    - what compiler was used to compile LLD (it is just a simple bit test;
      hopefully the compiler gets it right!)
    - adding new target-dependent relocations (e.g. needsPlt doesn't pay any extra
      cost checking R_PPC_PLT_OPD on x86-64 builds)
    
    I did some rough measurements on clang-fsds and this patch gives over about 4%
    speedup for a regular -O1 link, about 2.5% for -O3 --gc-sections and over 5%
    for -O0. Sorry, I don't have my current machine set up for doing really
    accurate measurements right now.
    
    This also is just a bit cleaner. Thanks for Joerg for suggesting for
    this approach.
    
    Differential Revision: https://reviews.llvm.org/D27156
    
    llvm-svn: 288314
    2eed7592
Loading