diff mbox

[v6,10/50] tcg: Avoid loops against variable bounds

Message ID 20171016172609.23422-11-richard.henderson@linaro.org (mailing list archive)
State New, archived
Headers show

Commit Message

Richard Henderson Oct. 16, 2017, 5:25 p.m. UTC
From: Richard Henderson <rth@twiddle.net>

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 <alex.bennee@linaro.org>
Signed-off-by: Richard Henderson <rth@twiddle.net>
---
 tcg/tcg.c | 27 ++++++++++-----------------
 1 file changed, 10 insertions(+), 17 deletions(-)

Comments

Emilio Cota Oct. 17, 2017, 10:03 p.m. UTC | #1
On Mon, Oct 16, 2017 at 10:25:29 -0700, Richard Henderson wrote:
> From: Richard Henderson <rth@twiddle.net>
> 
> 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 <alex.bennee@linaro.org>
> Signed-off-by: Richard Henderson <rth@twiddle.net>

Reviewed-by: Emilio G. Cota <cota@braap.org>

FWIW on a Skylake host I couldn't measure a difference. However, the
generated code is indeed slightly different.

		E.
Richard Henderson Oct. 18, 2017, 4:30 a.m. UTC | #2
On 10/17/2017 03:03 PM, Emilio G. Cota wrote:
> On Mon, Oct 16, 2017 at 10:25:29 -0700, Richard Henderson wrote:
>> From: Richard Henderson <rth@twiddle.net>
>>
>> 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 <alex.bennee@linaro.org>
>> Signed-off-by: Richard Henderson <rth@twiddle.net>
> 
> Reviewed-by: Emilio G. Cota <cota@braap.org>
> 
> FWIW on a Skylake host I couldn't measure a difference. However, the
> generated code is indeed slightly different.

I wouldn't expect so.  Low-overhead loops are more of a ppc thing.


r~
diff mbox

Patch

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