From acb3a99a65a0fbfd1bb157f6ec98f7f39020718b Mon Sep 17 00:00:00 2001 From: Guilherme Ottoni Date: Thu, 23 Oct 2014 13:13:16 -0700 Subject: [PATCH] Tweak to enable more refcount optimizations Summary: When a value is known to exist in many places, observeValue() will not insert any IncRef before a DecRef. That's bad because it ends up preventing some IncRef/DecRef pairs from being eliminated because the IncRef is pushed down past the DecRef. This diff makes sure that we always drop an IncRef before a DecRef, which then enables more IncRef/DecRef pairs to be eliminated. Reviewed By: @swtaarrs Differential Revision: D1631498 --- hphp/runtime/vm/jit/refcount-opts.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/hphp/runtime/vm/jit/refcount-opts.cpp b/hphp/runtime/vm/jit/refcount-opts.cpp index 9f02e5d6044..e5325947e81 100644 --- a/hphp/runtime/vm/jit/refcount-opts.cpp +++ b/hphp/runtime/vm/jit/refcount-opts.cpp @@ -1236,6 +1236,12 @@ struct SinkPointAnalyzer : private LocalStateHook { assertCanConsume(value); + // Drop one IncRef right before a DecRef, so that we don't end up + // missing opportunities because we sunk IncRefs too late. + if (m_inst->is(DecRef, DecRefNZ) && valState.optDelta() > 0) { + placeSinkPoint(value, valState, sinkPoint); + } + // Note that we're treating consumers and observers the same here, which is // necessary until we have better alias analysis. observeValue(value, valState, sinkPoint); -- 2.11.4.GIT