Received: from eggs.gnu.org ([2001:4830:134:3::10]:52631) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bPYd1-00039H-Rb for qemu-devel@nongnu.org; Tue, 19 Jul 2016 13:16:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bPYcx-0008KE-Kn for qemu-devel@nongnu.org; Tue, 19 Jul 2016 13:16:18 -0400 Received: from mail-lf0-x234.google.com ([2a00:1450:4010:c07::234]:36425) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bPYcx-0008Jz-BV for qemu-devel@nongnu.org; Tue, 19 Jul 2016 13:16:15 -0400 Received: by mail-lf0-x234.google.com with SMTP id g62so19977382lfe.3 for ; Tue, 19 Jul 2016 10:16:15 -0700 (PDT) Sender: Paolo Bonzini References: <20160714202940.18399-1-bobby.prani@gmail.com> From: Paolo Bonzini Message-ID: <558fdb52-fe3e-2841-cc67-3ec2744c0224@redhat.com> Date: Tue, 19 Jul 2016 19:16:07 +0200 MIME-Version: 1.0 In-Reply-To: <20160714202940.18399-1-bobby.prani@gmail.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 8bit Subject: Re: [Qemu-devel] [RFC PATCH] tcg: Optimize fence instructions List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Pranith Kumar , Richard Henderson , "open list:All patches CC here" Cc: serge.fdrv@gmail.com, alex.bennee@linaro.org On 14/07/2016 22:29, Pranith Kumar wrote: > + } else if (curr_mb_type == TCG_BAR_STRL && > + prev_mb_type == TCG_BAR_LDAQ) { > + /* Consecutive load-acquire and store-release barriers > + * can be merged into one stronger SC barrier > + * ldaq; strl => ld; mb; st > + */ > + args[0] = (args[0] & 0x0F) | TCG_BAR_SC; > + tcg_op_remove(s, prev_op); Is this really an optimization? For example the processor could reorder "st1; ldaq1; strl2; ld2" to "ldaq1; ld2; st1; strl2". It cannot do this if you change ldaq1/strl2 to ld1/mb/st2. On x86 for example a memory fence costs ~50 clock cycles, while normal loads and stores are of course faster. Of course this is useful if your target doesn't have ldaq/strl instructions. In this case, however, you probably want to lower ldaq to "ld;mb" and strl to "mb;st"; the other optimizations then will remove the unnecessary barrier. Paolo