forked from LuaJIT/LuaJIT
-
Notifications
You must be signed in to change notification settings - Fork 13
/
mark-conv-non-weak.test.lua
62 lines (54 loc) · 1.66 KB
/
mark-conv-non-weak.test.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
local tap = require('tap')
local test = tap.test('mark-conv-non-weak'):skipcond({
['Test requires JIT enabled'] = not jit.status(),
})
test:plan(1)
local data = {0.1, 0, 0.1, 0, 0 / 0}
local sum = 0
jit.opt.start('hotloop=1', 'hotexit=1')
-- XXX: The test fails before the patch only
-- for `DUALNUM` mode. All of the IRs below are
-- produced by the corresponding LuaJIT build.
-- When the last trace is recorded, the traced bytecode
-- is the following before the patch:
-- ---- TRACE 4 start 2/3 test.lua:6
-- 0018 ADDVV 1 1 6
-- 0019 ITERC 5 3 3
-- 0000 . FUNCC ; ipairs_aux
-- 0020 JITERL 5 1
-- 0021 GGET 2 7 ; "assert"
-- 0022 ISEQV 1 1
-- 0023 JMP 4 => 0026
-- 0024 KPRI 4 1
-- 0025 JMP 5 => 0027
-- 0027 CALL 2 1 2
-- 0000 . FUNCC ; assert
--
-- And the following after the patch:
-- ---- TRACE 4 start 2/2 test.lua:5
-- 0016 ISNEV 6 6
-- 0017 JMP 7 => 0019
-- 0019 ITERC 5 3 3
-- 0000 . FUNCC ; ipairs_aux
-- 0020 JITERL 5 1
-- 0021 GGET 2 7 ; "assert"
-- 0022 ISEQV 1 1
-- 0023 JMP 4 => 0026
-- 0026 KPRI 4 2
-- 0027 CALL 2 1 2
-- 0000 . FUNCC ; assert
-- 0028 RET0 0 1
--
-- The crucial difference here is the abscent
-- `ISNEV` in the first case, which produces the
-- desired guarded `CONV`, when translated to IR.
--
-- Since there is no guard, NaN is added to the sum,
-- despite the test case logic.
for _, val in ipairs(data) do
if val == val then
sum = sum + val
end
end
test:ok(sum == sum, 'NaN check was not omitted')
os.exit(test:check() and 0 or 1)