Debian Codegraph @

js/src/jit-test/tests/wasm/bce-x64-ion-codegen.js

raw
1 // |jit-test| --wasm-compiler=optimizing; --disable-wasm-huge-memory; --spectre-mitigations=off; skip-if: !hasDisassembler() || wasmCompileMode() != "ion" || !getBuildConfiguration("x64") || getBuildConfiguration("simulator") || getJitCompilerOptions()["ion.check-range-analysis"]; include:codegen-x64-test.js
2
3 // Spectre mitigation is disabled above to make the generated code simpler to
4 // match; ion.check-range-analysis makes a hash of the code and makes testing
5 // pointless.
6
7 // White-box testing of bounds check elimination on 64-bit systems.
8 //
9 // This is probably fairly brittle, but BCE on 64-bit platforms regressed (bug
10 // 1735207) without us noticing, so it's not like we can do without these tests.
11 //
12 // See also bce-x86-ion-codegen.js.
13 //
14 // If this turns out to be too brittle to be practical then an alternative to
15 // testing the output code is to do what we do for SIMD, record (in a log or
16 // buffer of some kind) that certain optimizations triggered, and then check the
17 // log.
18
19 var memTypes = [''];
20 if (wasmMemory64Enabled()) {
21 memTypes.push('i64')
22 }
23
24 for ( let memType of memTypes ) {
25 let dataType = memType ? memType : 'i32';
26
27 // Make sure the check for the second load is removed: the two load
28 // instructions should appear back-to-back in the output.
29 codegenTestX64_adhoc(
30 `(module
31 (memory ${memType} 1)
32 (func (export "f") (param ${dataType}) (result i32)
33 (local ${dataType})
34 (local.set 1 (${dataType}.add (local.get 0) (${dataType}.const 8)))
35 (i32.load (local.get 1))
36 drop
37 (i32.load (local.get 1))))`,
38 'f', `
39 48 3b .. cmp %r.., %r..
40 0f 83 .. 00 00 00 jnb 0x00000000000000..
41 41 8b .. .. movl \\(%r15,%r..,1\\), %e..
42 41 8b .. .. movl \\(%r15,%r..,1\\), %eax`,
43 {no_prefix:true});
44
45 // Make sure constant indices below the heap minimum do not require a bounds
46 // check.
47 codegenTestX64_adhoc(
48 `(module
49 (memory ${memType} 1)
50 (func (export "f") (result i32)
51 (i32.load (${dataType}.const 16))))`,
52 'f',
53 `41 8b 47 10 movl 0x10\\(%r15\\), %eax`);
54
55 // Ditto, even at the very limit of the known heap, extending into the guard
56 // page. This is an OOB access, of course, but it needs no explicit bounds
57 // check.
58 codegenTestX64_adhoc(
59 `(module
60 (memory ${memType} 1)
61 (func (export "f") (result i32)
62 (i32.load (${dataType}.const 65535))))`,
63 'f',
64 `
65 b8 ff ff 00 00 mov \\$0xFFFF, %eax
66 41 8b 04 07 movl \\(%r15,%rax,1\\), %eax`);
67 }
68