From 1ece474c69cfcf6f8ef14d54e469eb387a7a6983 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Mattias=20Engdeg=C3=A5rd?= Date: Tue, 21 Nov 2023 11:23:57 +0100 Subject: [PATCH] Slight funcall_subr optimisation * src/eval.c (funcall_subr): Help the compiler by reducing aliasing problems, and compensate for a missed-optimisation bug in LLVM where switches sometimes forget to use variable range information (reported in https://github.com/llvm/llvm-project/issues/76085). --- src/eval.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/eval.c b/src/eval.c index 5c9052cb9ab..b3d3fc3132b 100644 --- a/src/eval.c +++ b/src/eval.c @@ -3033,21 +3033,21 @@ funcall_subr (struct Lisp_Subr *subr, ptrdiff_t numargs, Lisp_Object *args) if (numargs >= subr->min_args) { /* Conforming call to finite-arity subr. */ - if (numargs <= subr->max_args - && subr->max_args <= 8) + ptrdiff_t maxargs = subr->max_args; + if (numargs <= maxargs && maxargs <= 8) { Lisp_Object argbuf[8]; Lisp_Object *a; - if (numargs < subr->max_args) + if (numargs < maxargs) { - eassume (subr->max_args <= ARRAYELTS (argbuf)); + eassume (maxargs <= ARRAYELTS (argbuf)); a = argbuf; memcpy (a, args, numargs * word_size); - memclear (a + numargs, (subr->max_args - numargs) * word_size); + memclear (a + numargs, (maxargs - numargs) * word_size); } else a = args; - switch (subr->max_args) + switch (maxargs) { case 0: return subr->function.a0 (); @@ -3069,14 +3069,12 @@ funcall_subr (struct Lisp_Subr *subr, ptrdiff_t numargs, Lisp_Object *args) case 8: return subr->function.a8 (a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7]); - default: - emacs_abort (); /* Can't happen. */ } + eassume (false); /* In case the compiler is too stupid. */ } /* Call to n-adic subr. */ - if (subr->max_args == MANY - || subr->max_args > 8) + if (maxargs == MANY || maxargs > 8) return subr->function.aMANY (numargs, args); } -- 2.39.2