From patchwork Mon Oct 16 17:25:29 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 115949 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp3946964qgn; Mon, 16 Oct 2017 10:41:39 -0700 (PDT) X-Received: by 10.55.10.18 with SMTP id 18mr13625407qkk.184.1508175699489; Mon, 16 Oct 2017 10:41:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508175699; cv=none; d=google.com; s=arc-20160816; b=gB0ZAzvBBC66Q6aq3+u2h1cstHyOY46KIgcvqpkaHb2w2+Pvm7iSASvLVGonmgntUG A+s35il5/niaJspxvP+duSOWkFdq3rCQ5ce2OM7ZZ53bxlmxmrb/ceALE2hNLcDqJT9j CYVkIzq/9gXE1gIIQrsmCJ3WsWcYDQDNcJVxyUQLJ9RGGAm4mDv1JphR4TcGxtqo79AC 6ZQ1abSmdnvaOWRfzELsK73UmkD10/au26nKpGHPP2+Mv5e3TzblF4W5C8QrGKNBujSG v1W84xI2N9zUbZGWgN8I8OCXPEXo5BK6Ap1fbELNfZquYNUXzNfZDGQDN0p0/+bAkMo+ DjLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=14UnMYMoZqmrJ9oz6osYwF58UTet1QjRnDjyBDt55ag=; b=xT/sXdTHueKoG7VFCLg1UCk8Fr8R0l5/uYlNkzXEpx3M9MZkg+JOpld37XXfIm+HM+ pwRy7NAqEKsqDzEvCkQXv280ejnmbmrCu5EjP3TXsvX/hddS0nKqKxUid089VJ5jRw2/ XCVqZVeB4YK3W1g51uOWXf5ybflyvo1iexnN037iivjFndHP9KZOpgQHZQ8wWm//5Mb9 smLG3YY0uHR4RG3Jc7uRSkS+ftycFRCTVaWHAJCy7xLGAuBgJNJSWiKc4jxux/lId6+y W7rdNRSlGqAoMDiY3Kts6+aIIMuhwtVkgiZy05mzv8P0Fsc/PjTWuyHoFTAj7gdQIB6g h4zA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=As0pz483; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id 30si3554604qtb.110.2017.10.16.10.41.39 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 16 Oct 2017 10:41:39 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=As0pz483; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:34356 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e49OT-0006MO-EA for patch@linaro.org; Mon, 16 Oct 2017 13:41:37 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52283) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e499p-00020a-GA for qemu-devel@nongnu.org; Mon, 16 Oct 2017 13:26:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e499o-0003Op-Gp for qemu-devel@nongnu.org; Mon, 16 Oct 2017 13:26:29 -0400 Received: from mail-pg0-x234.google.com ([2607:f8b0:400e:c05::234]:51119) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1e499o-0003OF-BR for qemu-devel@nongnu.org; Mon, 16 Oct 2017 13:26:28 -0400 Received: by mail-pg0-x234.google.com with SMTP id y7so7342099pgb.7 for ; Mon, 16 Oct 2017 10:26:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=14UnMYMoZqmrJ9oz6osYwF58UTet1QjRnDjyBDt55ag=; b=As0pz48359ajQ6Ug9EXlJEMwQrr+/sBS2QWjxNai+8p5WVwOfF/3fhxDhd/KPcwzyt cWCxYnHDyAMA1I1wR8su2o/xtzhG4R8Czl3zkg0nSRbBH8v/Jj1AgL0kBSjehiIdz6us y8Imv7uxHkCYAxQuD+ZTCX1xHefxk52O13iMk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=14UnMYMoZqmrJ9oz6osYwF58UTet1QjRnDjyBDt55ag=; b=C+ufwKSvNESbtYGEZuDZ1xO1r5P2w0Ih2hgT19R+GMgkvKJNyJzEzcf9bl34RzhNBN lIA36VjVSI18BA7n5woZCky5cRpwyUu3E1UMBbABND/hBcrSlDcQE2U5DFzp2JTLONmX 6pkklOCCa+6rL5qesImLY+rbpp80nuOW+DvqKDOuiokitlYo8FYktjzn97YrRbY62Leo TTBiORMN+ag5kivSexfWOwKo6v8QefmGGsyKYNnRDWXijmD7tNu+yiy+ylc4dL1Voh76 HvebcZ7EHC4BPbeGTuB4SJ2GS+YnrD2JhI4vtDwSeRlfKF/iUAhsIWQekIyop2tjh0U7 7qbw== X-Gm-Message-State: AMCzsaXMfjtUMc5FQCHT5CpcbaIG6mOhpqb4sXVYQz05IVhR7UoQarZa klk+O1zmZ8ixVAgi+Dmjjpf5cMISRpU= X-Google-Smtp-Source: AOwi7QCNegFNvChZ1UiFH9u0w7h60vCqBUCeCCRnDWwYOAsV4p3oDLl8Phm4hNZNwg+khhZZQk0W5g== X-Received: by 10.84.135.101 with SMTP id 92mr9657204pli.180.1508174787215; Mon, 16 Oct 2017 10:26:27 -0700 (PDT) Received: from cloudburst.twiddle.net (97-126-104-76.tukw.qwest.net. [97.126.104.76]) by smtp.gmail.com with ESMTPSA id i187sm5594249pfc.96.2017.10.16.10.26.25 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 16 Oct 2017 10:26:26 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Mon, 16 Oct 2017 10:25:29 -0700 Message-Id: <20171016172609.23422-11-richard.henderson@linaro.org> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20171016172609.23422-1-richard.henderson@linaro.org> References: <20171016172609.23422-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c05::234 Subject: [Qemu-devel] [PATCH v6 10/50] tcg: Avoid loops against variable bounds X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: cota@braap.org, Richard Henderson Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Richard Henderson Copy s->nb_globals or s->nb_temps to a local variable for the purposes of iteration. This should allow the compiler to use low-overhead looping constructs on some hosts. Reviewed-by: Alex Bennée Signed-off-by: Richard Henderson --- tcg/tcg.c | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) -- 2.13.6 Reviewed-by: Emilio G. Cota diff --git a/tcg/tcg.c b/tcg/tcg.c index 719db9f2b6..bb342e06dd 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -1166,23 +1166,16 @@ void tcg_gen_callN(TCGContext *s, void *func, TCGArg ret, static void tcg_reg_alloc_start(TCGContext *s) { - int i; + int i, n; TCGTemp *ts; - for(i = 0; i < s->nb_globals; i++) { + + for (i = 0, n = s->nb_globals; i < n; i++) { ts = &s->temps[i]; - if (ts->fixed_reg) { - ts->val_type = TEMP_VAL_REG; - } else { - ts->val_type = TEMP_VAL_MEM; - } + ts->val_type = (ts->fixed_reg ? TEMP_VAL_REG : TEMP_VAL_MEM); } - for(i = s->nb_globals; i < s->nb_temps; i++) { + for (n = s->nb_temps; i < n; i++) { ts = &s->temps[i]; - if (ts->temp_local) { - ts->val_type = TEMP_VAL_MEM; - } else { - ts->val_type = TEMP_VAL_DEAD; - } + ts->val_type = (ts->temp_local ? TEMP_VAL_MEM : TEMP_VAL_DEAD); ts->mem_allocated = 0; ts->fixed_reg = 0; } @@ -2284,9 +2277,9 @@ static void temp_save(TCGContext *s, TCGTemp *ts, TCGRegSet allocated_regs) temporary registers needs to be allocated to store a constant. */ static void save_globals(TCGContext *s, TCGRegSet allocated_regs) { - int i; + int i, n; - for (i = 0; i < s->nb_globals; i++) { + for (i = 0, n = s->nb_globals; i < n; i++) { temp_save(s, &s->temps[i], allocated_regs); } } @@ -2296,9 +2289,9 @@ static void save_globals(TCGContext *s, TCGRegSet allocated_regs) temporary registers needs to be allocated to store a constant. */ static void sync_globals(TCGContext *s, TCGRegSet allocated_regs) { - int i; + int i, n; - for (i = 0; i < s->nb_globals; i++) { + for (i = 0, n = s->nb_globals; i < n; i++) { TCGTemp *ts = &s->temps[i]; tcg_debug_assert(ts->val_type != TEMP_VAL_REG || ts->fixed_reg