From c0d34d35015aeedf6bdb81f71bc3e1fc24e2b693 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jonas=20Walld=C3=A9n?= <jonasw@roxen.com>
Date: Sun, 22 Jul 2012 16:35:17 +0200
Subject: [PATCH] Help compiler remove redundant memory accesses in hot
 locations. (There are many more like these in interpret_functions.h but a lot
 is shadowed by machine-code implementation.) Gives approx. 1-2% improvement
 on my benchmarks.

---
 src/interpret_functions.h | 10 ++++++----
 src/svalue.h              |  7 ++++---
 2 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/src/interpret_functions.h b/src/interpret_functions.h
index f07cc27784..302ded6702 100644
--- a/src/interpret_functions.h
+++ b/src/interpret_functions.h
@@ -497,11 +497,12 @@ OPCODE1(F_CLEAR_2_LOCAL, "clear 2 local", 0, {
 });
 
 OPCODE1(F_CLEAR_4_LOCAL, "clear 4 local", 0, {
+  struct svalue *locals = Pike_fp->locals;
   int e;
-  free_mixed_svalues(Pike_fp->locals + arg1, 4);
+  free_mixed_svalues(locals + arg1, 4);
   for(e = 0; e < 4; e++)
   {
-    SET_SVAL(Pike_fp->locals[arg1+e], PIKE_T_INT, NUMBER_NUMBER, integer, 0);
+    SET_SVAL(locals[arg1+e], PIKE_T_INT, NUMBER_NUMBER, integer, 0);
   }
 });
 
@@ -1920,11 +1921,12 @@ OPCODE2(F_GLOBAL_LOCAL_INDEX, "global[local]", I_UPDATE_SP, {
 });
 
 OPCODE2(F_LOCAL_ARROW, "local->x", I_UPDATE_SP, {
+  struct pike_frame *fp = Pike_fp;
   LOCAL_VAR(struct svalue tmp);
   SET_SVAL(tmp, PIKE_T_STRING, 1, string,
-	   Pike_fp->context->prog->strings[arg1]);
+	   fp->context->prog->strings[arg1]);
   mark_free_svalue (Pike_sp++);
-  index_no_free(Pike_sp-1,Pike_fp->locals+arg2, &tmp);
+  index_no_free(Pike_sp-1,fp->locals+arg2, &tmp);
   print_return_value();
 });
 
diff --git a/src/svalue.h b/src/svalue.h
index 01132a1f94..db5fe7c2e9 100644
--- a/src/svalue.h
+++ b/src/svalue.h
@@ -106,9 +106,10 @@ struct svalue
 #define SET_SVAL(SVAL, TYPE, SUBTYPE, FIELD, EXPR) do {	\
     /* Set the type afterwards to avoid a clobbered	\
      * svalue in case EXPR throws. */			\
-    (SVAL).u.FIELD = (EXPR);				\
-    SET_SVAL_TYPE((SVAL), (TYPE));			\
-    SET_SVAL_SUBTYPE((SVAL), (SUBTYPE));		\
+    struct svalue *__sptr = &(SVAL);			\
+    __sptr->u.FIELD = (EXPR);				\
+    SET_SVAL_TYPE(*__sptr, (TYPE));			\
+    SET_SVAL_SUBTYPE(*__sptr, (SUBTYPE));		\
   } while(0)
 #define INVALIDATE_SVAL(SVAL) SET_SVAL_TYPE(SVAL, 99) /* an invalid type */
 
-- 
GitLab