[Tarantool-patches] [PATCH luajit] Fix FOLD rule for BUFHDR append.
Maxim Kokryashkin
m.kokryashkin at tarantool.org
Fri Nov 17 14:06:17 MSK 2023
Hi, Sergey!
LGTM, except for a few nits below.
On Tue, Nov 14, 2023 at 06:04:55PM +0300, Sergey Kaplun wrote:
> From: Mike Pall <mike>
>
> Reported by XmiliaH.
>
> (cherry-picked from commit bc1bdbf620f58f0978385828bc51272903601e17)
>
> `bufput_append()` may fold `BUFHDR RESET` + `BUFPUT` IRs to `BUFHDR
> APPEND` even if the right operand (`BUFSTR`) is the PHI. If it's not the
> last IR in the `BUFSTR` chain, this may lead to an incorrect resulting
> value in the buffer, which contains a longer string since `APPEND` is
> used instead of `RESET`.
>
> This patch adds the corresponding check inside the fold rule.
>
> Sergey Kaplun:
> * added the description and the test for the problem
>
> Part of tarantool/tarantool#9145
> ---
>
> Branch: https://github.com/tarantool/luajit/tree/skaplun/lj-791-fold-bufhdr-append
> Tarantool PR: https://github.com/tarantool/tarantool/pull/9369
> Relate issues:
> * https://github.com/LuaJIT/LuaJIT/issues/791
> * https://github.com/tarantool/tarantool/issues/9145
>
> src/lj_opt_fold.c | 3 +-
> .../lj-791-fold-bufhdr-append.test.lua | 54 +++++++++++++++++++
> 2 files changed, 56 insertions(+), 1 deletion(-)
> create mode 100644 test/tarantool-tests/lj-791-fold-bufhdr-append.test.lua
>
> diff --git a/src/lj_opt_fold.c b/src/lj_opt_fold.c
> index 944a9ecc..910cbc14 100644
> --- a/src/lj_opt_fold.c
> +++ b/src/lj_opt_fold.c
<snipped>
> diff --git a/test/tarantool-tests/lj-791-fold-bufhdr-append.test.lua b/test/tarantool-tests/lj-791-fold-bufhdr-append.test.lua
> new file mode 100644
> index 00000000..b2422159
> --- /dev/null
> +++ b/test/tarantool-tests/lj-791-fold-bufhdr-append.test.lua
> @@ -0,0 +1,54 @@
<snipped>
> +-- XXX: Use 5 iterations to run variant part of the loop.
Typo: s/variant/the variant/
> +for _ = 1, 5 do
> + result = prefix .. 'a'
> + -- We need a non-constant string to be appended to prevent more
> + -- aggressive optimizations. Use an empty string for
> + -- convenience. Also, use a constant string in the first operand
> + -- in the concatenation operator for more readable `jit.dump`
> + -- output.
> + prefix = 'Lu' .. EMPTY_STR
> +end
> +
> +test:is(result, 'Lua', 'skipped BUFPUT APPEND optimization for PHIs')
The test description is a bit misleading. At first glance it reads like
the `BUFPUT APPEND` itself is skipped. I suggest paraphrasing it like
this:
"BUFPUT APPEND optimization is not applied for PHIs"
> +
> +test:done(true)
> --
> 2.42.0
>
More information about the Tarantool-patches
mailing list