Tarantool development patches archive
 help / color / mirror / Atom feed
From: Sergey Kaplun via Tarantool-patches <tarantool-patches@dev.tarantool.org>
To: Maxim Kokryashkin <m.kokryashkin@tarantool.org>,
	Sergey Bronnikov <sergeyb@tarantool.org>
Cc: tarantool-patches@dev.tarantool.org
Subject: [Tarantool-patches] [PATCH luajit] Fix jit.dump() output for IR_CONV.
Date: Wed, 25 Oct 2023 16:14:28 +0300	[thread overview]
Message-ID: <20231025131428.4124-1-skaplun@tarantool.org> (raw)

From: Mike Pall <mike>

(cherry-picked from commit 44bd7437a27e0d19bcf878c20ad27a673f17f40b)

When dumping IRs via `jit.dump()`, the incorrect value of `IR_CONV` mode
shift (`IRCONV_CSH`) is used. This patch fixes the value.

Sergey Kaplun:
* added the description and the test for the problem

Part of tarantool/tarantool#9145
---

Branch: https://github.com/tarantool/luajit/tree/skaplun/fix-ir-conv
Tarantool PR: https://github.com/tarantool/tarantool/pull/9307
Issue: https://github.com/tarantool/tarantool/issues/9145

 src/jit/dump.lua                              |  2 +-
 .../fix-jit-dump-ir-conv.test.lua             | 68 +++++++++++++++++++
 2 files changed, 69 insertions(+), 1 deletion(-)
 create mode 100644 test/tarantool-tests/fix-jit-dump-ir-conv.test.lua

diff --git a/src/jit/dump.lua b/src/jit/dump.lua
index 27b5c2ae..84fe0044 100644
--- a/src/jit/dump.lua
+++ b/src/jit/dump.lua
@@ -277,7 +277,7 @@ local litname = {
     local s = irtype[band(mode, 31)]
     s = irtype[band(shr(mode, 5), 31)].."."..s
     if band(mode, 0x800) ~= 0 then s = s.." sext" end
-    local c = shr(mode, 14)
+    local c = shr(mode, 12)
     if c == 2 then s = s.." index" elseif c == 3 then s = s.." check" end
     t[mode] = s
     return s
diff --git a/test/tarantool-tests/fix-jit-dump-ir-conv.test.lua b/test/tarantool-tests/fix-jit-dump-ir-conv.test.lua
new file mode 100644
index 00000000..ed03210a
--- /dev/null
+++ b/test/tarantool-tests/fix-jit-dump-ir-conv.test.lua
@@ -0,0 +1,68 @@
+local tap = require('tap')
+local test = tap.test('fix-jit-dump-ir-conv'):skipcond({
+  ['Test requires JIT enabled'] = not jit.status(),
+  ['Disabled on *BSD due to #4819'] = jit.os == 'BSD',
+})
+
+test:plan(2)
+
+-- Test file to demonstrate LuaJIT incorrect `jit.dump()` output
+-- for `IR_CONV`.
+
+local jparse = require('utils').jit.parse
+
+-- XXX: Avoid any traces compilation due to hotcount collisions
+-- for predictable results.
+jit.off()
+jit.flush()
+
+jit.opt.start('hotloop=1')
+
+jit.on()
+jparse.start('i')
+
+-- luacheck: ignore
+local tab = {}
+local idx = 1
+for _ = 1, 4 do
+  -- `int IR_CONV int.num index`.
+  tab[idx] = idx
+end
+
+local traces = jparse.finish()
+
+-- Skip tests for DUALNUM mode since it has no conversions (for
+-- the same cases).
+local IS_DUALNUM = not traces[1]:has_ir('num SLOAD')
+
+test:ok(IS_DUALNUM or traces[1]:has_ir('CONV.*int.num index'),
+        'correct dump for index')
+
+local function trace(step)
+  -- `int IR_CONV int.num check` for `step` conversion.
+  for _ = 1, 4, step do
+  end
+end
+
+-- XXX: Reset hotcounters and traces.
+jit.flush()
+jit.opt.start('hotloop=1')
+
+jparse.start('i')
+-- Compile the inner trace first.
+trace(1)
+-- Compile the big trace with the first trace inlined.
+-- Needs narrowing optimization enabled.
+-- XXX: Reset hotcounters and call the function 3 times to
+-- compile. Needed to avoid hotcount collisions.
+jit.opt.start('hotloop=1')
+trace(1)
+trace(1)
+trace(1)
+
+traces = jparse.finish()
+
+test:ok(IS_DUALNUM or traces[2]:has_ir('CONV.*int.num check'),
+        'correct dump for check')
+
+test:done(true)
-- 
2.42.0


             reply	other threads:[~2023-10-25 13:19 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-25 13:14 Sergey Kaplun via Tarantool-patches [this message]
2023-10-26 12:24 ` Maxim Kokryashkin via Tarantool-patches
2023-11-08 19:29 ` Sergey Bronnikov via Tarantool-patches
2023-11-23  6:32 ` 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=20231025131428.4124-1-skaplun@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 jit.dump() output for IR_CONV.' \
    /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