This is an archive of the discontinued LLVM Phabricator instance.

[scudo][standalone] Small changes to the fastpath
ClosedPublic

Authored by cryptoad on Dec 4 2020, 2:08 PM.

Details

Summary

There are a few things that I wanted to reorganize for a while:

  • the loop that incrementally goes through classes on failure looked horrible in assembly, mostly because of LIKELY/UNLIKELY within the loop. So remove those, we are already in an unlikely scenario
  • hooks are not used by default on Android/Fuchsia/etc so mark the tests for the existence of the weak functions as unlikely
  • mark of couple of conditions as likely/unlikely
  • in reallocate, the old size was computed again while we already have it in a variable. So just use the one we have.
  • remove the bitwise OR trick and use a logical OR, that has one less test by using a purposeful underflow when Size is 0 (I actually looked at the assembly of the previous code to steal that trick)
  • move the read of the options closer to where they are used, mark them as const

Overall this makes things a tiny bit faster, but cleaner.

Diff Detail

Event Timeline

cryptoad requested review of this revision.Dec 4 2020, 2:08 PM
cryptoad created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptDec 4 2020, 2:08 PM
Herald added a subscriber: Restricted Project. · View Herald Transcript
pcc added inline comments.Dec 4 2020, 2:15 PM
compiler-rt/lib/scudo/standalone/combined.h
1059

Isn't this changing the condition? i.e. it should be Size - 1 > QuarantineMaxChunkSize - 1 now.

Does the assembly still look bad if we just have logical OR here with the original clauses?

cryptoad added inline comments.Dec 4 2020, 2:45 PM
compiler-rt/lib/scudo/standalone/combined.h
1059

Right, thank you! It should be (Size - 1) >= QuarantineMaxChunkSize.
With the logical OR, we get 3 comparisons and conditional jumps, with the bitwise OR we get 2, as the compiler folds the last 2 into the one, via the trick used here.

cryptoad updated this revision to Diff 309664.Dec 4 2020, 2:46 PM

Correct > to >=.

cryptoad edited the summary of this revision. (Show Details)Dec 4 2020, 2:48 PM

Anything I can help address to move forward?

pcc accepted this revision.Dec 9 2020, 2:27 PM

LGTM

This revision is now accepted and ready to land.Dec 9 2020, 2:27 PM
This revision was automatically updated to reflect the committed changes.