Commit 821290a1 authored by Julian Seward's avatar Julian Seward
Browse files

Bug 1823857 - part 1: Code::lookupTrap: lift an invariant expression out of a hot loop. r=rhunt.

Code::lookupTrap has

  uint32_t target = ((uint8_t*)pc) - segment(t).base();

in a loop in which it is invariant.  This patch lifts it out of the loop since
the clang++ 15.0.7 does not appear to do so, even at -O2.  Reduces (host)
instruction count by around 10% on some artificial small wasm-gc tests.

Differential Revision: https://phabricator.services.mozilla.com/D173275
parent 471df3ea
Loading
Loading
Loading
Loading
+3 −5
Original line number Diff line number Diff line
@@ -1049,17 +1049,15 @@ struct TrapSitePCOffset {

bool Code::lookupTrap(void* pc, Trap* trapOut, BytecodeOffset* bytecode) const {
  for (Tier t : tiers()) {
    uint32_t target = ((uint8_t*)pc) - segment(t).base();
    const TrapSiteVectorArray& trapSitesArray = metadata(t).trapSites;
    for (Trap trap : MakeEnumeratedRange(Trap::Limit)) {
      const TrapSiteVector& trapSites = trapSitesArray[trap];

      uint32_t target = ((uint8_t*)pc) - segment(t).base();
      size_t lowerBound = 0;
      size_t upperBound = trapSites.length();

      size_t match;
      if (BinarySearch(TrapSitePCOffset(trapSites), lowerBound, upperBound,
                       target, &match)) {
      if (BinarySearch(TrapSitePCOffset(trapSites), 0, upperBound, target,
                       &match)) {
        MOZ_ASSERT(segment(t).containsCodePC(pc));
        *trapOut = trap;
        *bytecode = trapSites[match].bytecode;