Tarantool development patches archive
 help / color / mirror / Atom feed
From: Sergey Bronnikov via Tarantool-patches <tarantool-patches@dev.tarantool.org>
To: Sergey Kaplun <skaplun@tarantool.org>,
	Maxim Kokryashkin <m.kokryashkin@tarantool.org>
Cc: tarantool-patches@dev.tarantool.org
Subject: Re: [Tarantool-patches] [PATCH luajit] Fix TDUP load forwarding after table rehash.
Date: Mon, 28 Aug 2023 17:25:33 +0300	[thread overview]
Message-ID: <5c416cf4-f366-9f35-f05b-13f1c7679749@tarantool.org> (raw)
In-Reply-To: <20230817144641.20088-1-skaplun@tarantool.org>

Sergey,


thanks for the patch. See my comment inline.


On 8/17/23 17:46, Sergey Kaplun wrote:

<snipped>


> +++ b/test/tarantool-tests/lj-980-load-fwd-after-table-rehash.test.lua
> @@ -0,0 +1,166 @@
> +local tap = require('tap')
> +
> +-- Test file to demonstrate LuaJIT misbehaviour during load
> +-- forwarding optimization for HLOAD after table rehashing.
> +-- See also https://github.com/LuaJIT/LuaJIT/issues/980.
> +
> +local test = tap.test('lj-980-load-fwd-after-table-rehash'):skipcond({
> +  ['Test requires JIT enabled'] = not jit.status(),
> +})
> +
> +test:plan(6)
> +
> +jit.opt.start('hotloop=1')
> +
> +local result
> +-- The test for TNEW load forwarding. It doesn't trigger an assert
> +-- since the commit "Fix TNEW load forwarding with instable
> +-- types.". But still add it to avoid regressions in future.
> +for i = 6, 9 do
> +  -- Need big enough table to see rehashing.
> +  -- Also, to simplify logic with AREF, HREF don't use default
> +  -- 1, 4 (start, stop) values here.
> +  local t = {i, i, i, i, i, i, i}
> +  -- Insert via ASTORE.
> +  t[i] = i
> +  t[1] = nil
> +  t[2] = nil
> +  t[3] = nil
> +  t[4] = nil
> +  t[5] = nil
> +  -- Rehash table. Array part is empty.
> +  t['1000'] = 1000
> +  -- Load via HLOAD.
> +  result = t[i]
> +end
> +
> +test:is(result, 9, 'TNEW load forwarding')
> +
> +-- TNEW load forwarding, aliased table.
> +local alias_store = {{}, {}, {}, {}, {}}
> +for i = 6, 9 do
> +  local t = {i, i, i, i, i, i, i}
> +  alias_store[#alias_store + 1] = t
> +  local alias = alias_store[i]
> +  -- Insert via ASTORE.
> +  alias[i] = i
> +  alias[1] = nil
> +  alias[2] = nil
> +  alias[3] = nil
> +  alias[4] = nil
> +  alias[5] = nil
> +  -- Rehash table. Array part is empty.
> +  alias['1000'] = 1000
> +  -- Load via HLOAD.
> +  result = t[i]
> +end
> +
> +test:is(result, 9, 'TNEW load forwarding, aliased table')
> +
> +local expected = 'result'
> +
> +-- TDUP different types.
> +for i = 6, 9 do
> +  local t = {1, 2, 3, 4, 5, 6, 7, 8}
> +  t[i] = expected
> +  t[i + 1] = expected
> +  t[1] = nil
> +  t[2] = nil
> +  t[3] = nil
> +  t[4] = nil
> +  t[5] = nil
> +  t[6] = nil
> +  -- Rehash table. Array part is empty.
> +  t['1000'] = 1000
> +  -- Result on the recording (i == 8) iteration is 'result'.
> +  -- Nevertheless, on the last (i == 9) iteration it is 8.
> +  -- Just check that there is no assert failure here.
> +  -- Load via HLOAD.
> +  result = t[8]
> +end
> +
> +-- Checked for assertion guard, on the last iteration we get
> +-- the value on initializatoin.
> +test:is(result, 8, 'TDUP load forwarding different types')
> +
> +-- TDUP different types, aliased table.
> +alias_store = {{}, {}, {}, {}, {}}
> +for i = 6, 9 do
> +  local t = {1, 2, 3, 4, 5, 6, 7, 8}
> +  -- Store table, to be aliased later.
> +  alias_store[#alias_store + 1] = t
> +  local alias = alias_store[i]
> +  alias[i] = expected
> +  alias[i + 1] = expected
> +  alias[1] = nil
> +  alias[2] = nil
> +  alias[3] = nil
> +  alias[4] = nil
> +  alias[5] = nil
> +  alias[6] = nil
> +  -- Rehash table. Array part is empty.
> +  alias['1000'] = 1000
> +  -- Result on the recording (i == 8) iteration is 'result'.
> +  -- Nevertheless, on the last (i == 9) iteration it is 8.
> +  -- Just check that there is no assert failure here.
> +  -- Load via HLOAD.
> +  result = t[8]
> +end
> +
> +-- Checked for assertion guard, on the last iteration we get
> +-- the value on initializatoin.
> +test:is(result, 8, 'TDUP load forwarding different types, aliased table')
> +
> +-- TDUP same type, different values.
> +for i = 6, 9 do
> +  local t = {1, 2, 3, 4, 5, 6, '7', '8'}
> +  t[i] = expected
> +  t[i + 1] = expected
> +  t[1] = nil
> +  t[2] = nil
> +  t[3] = nil
> +  t[4] = nil
> +  t[5] = nil
> +  t[6] = nil
> +  -- Rehash table. Array part is empty.
> +  t['1000'] = 1000
> +  -- Result on the recording (i == 8) iteration is 'result'.
> +  -- Nevertheless, on the last (i == 9) iteration it is '8'.
> +  -- Just check that there is no assert failure here.
> +  -- Load via HLOAD.
> +  result = t[8]
> +end
> +
> +-- Checked for assertion guard, on the last iteration we get
> +-- the value on initializatoin.
> +test:is(result, '8', 'TDUP load forwarding same type, different values')
> +
> +alias_store = {{}, {}, {}, {}, {}}
> +for i = 6, 9 do
> +  local t = {1, 2, 3, 4, 5, 6, '7', '8'}
> +  -- Store table, to be aliased later.
> +  alias_store[#alias_store + 1] = t
> +  local alias = alias_store[i]
> +  alias[i] = expected
> +  alias[i + 1] = expected
> +  alias[1] = nil
> +  alias[2] = nil
> +  alias[3] = nil
> +  alias[4] = nil
> +  alias[5] = nil
> +  alias[6] = nil
> +  -- Rehash table. Array part is empty.
> +  alias['1000'] = 1000
> +  -- Result on the recording (i == 8) iteration is 'result'.
> +  -- Nevertheless, on the last (i == 9) iteration it is '8'.
> +  -- Just check that there is no assert failure here.
> +  -- Load via HLOAD.
> +  result = t[8]
> +end
> +
> +-- Checked for assertion guard, on the last iteration we get
> +-- the value on initializatoin.
> +test:is(result, '8',
> +        'TDUP load forwarding same type, different values, aliased table')
> +
> +test:done(true)


Is it possible to fold loop bodies to a single function?

Otherwise it is too much duplicate code in the test.


  parent reply	other threads:[~2023-08-28 14:25 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-17 14:46 Sergey Kaplun via Tarantool-patches
2023-08-20 12:13 ` Maxim Kokryashkin via Tarantool-patches
2023-08-21  8:58   ` Sergey Kaplun via Tarantool-patches
2023-08-28 14:25 ` Sergey Bronnikov via Tarantool-patches [this message]
2023-08-28 14:26   ` Sergey Kaplun via Tarantool-patches
2023-08-28 14:33     ` Sergey Bronnikov via Tarantool-patches
2023-08-31 15:19 ` Igor Munkin via Tarantool-patches

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5c416cf4-f366-9f35-f05b-13f1c7679749@tarantool.org \
    --to=tarantool-patches@dev.tarantool.org \
    --cc=m.kokryashkin@tarantool.org \
    --cc=sergeyb@tarantool.org \
    --cc=skaplun@tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH luajit] Fix TDUP load forwarding after table rehash.' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox