Stream: git-wasmtime

Topic: wasmtime / issue #6661 Cranelift: DCE unused stack slots


view this post on Zulip Wasmtime GitHub notifications bot (Jun 28 2023 at 16:48):

fitzgen opened issue #6661:

If there are explicit stack slots that are never used (say because of some earlier optimization making it dead) then we will never DCE the stack slot itself, and will always allocate stack space for that slot. This can then lead to code that might otherwise not have been emitted, like stack limit checks and stack probes.

Example:

function %f(i64 vmctx, i32) -> i32 {
    gv0 = vmctx
    stack_limit = gv0

    ;; Comment out this unused stack slot and we won't allocate any stack space
    ;; and therefore won't emit any stack-limit checks. Leave it in and we
    ;; unnecessarily do those things, even though nothing uses this stack slot.
    ss0 = explicit_slot 8

block0(v0: i64, v1: i32):
    return v1
}

view this post on Zulip Wasmtime GitHub notifications bot (Jun 28 2023 at 16:48):

fitzgen labeled issue #6661:

If there are explicit stack slots that are never used (say because of some earlier optimization making it dead) then we will never DCE the stack slot itself, and will always allocate stack space for that slot. This can then lead to code that might otherwise not have been emitted, like stack limit checks and stack probes.

Example:

function %f(i64 vmctx, i32) -> i32 {
    gv0 = vmctx
    stack_limit = gv0

    ;; Comment out this unused stack slot and we won't allocate any stack space
    ;; and therefore won't emit any stack-limit checks. Leave it in and we
    ;; unnecessarily do those things, even though nothing uses this stack slot.
    ss0 = explicit_slot 8

block0(v0: i64, v1: i32):
    return v1
}

view this post on Zulip Wasmtime GitHub notifications bot (Jun 28 2023 at 16:48):

fitzgen labeled issue #6661:

If there are explicit stack slots that are never used (say because of some earlier optimization making it dead) then we will never DCE the stack slot itself, and will always allocate stack space for that slot. This can then lead to code that might otherwise not have been emitted, like stack limit checks and stack probes.

Example:

function %f(i64 vmctx, i32) -> i32 {
    gv0 = vmctx
    stack_limit = gv0

    ;; Comment out this unused stack slot and we won't allocate any stack space
    ;; and therefore won't emit any stack-limit checks. Leave it in and we
    ;; unnecessarily do those things, even though nothing uses this stack slot.
    ss0 = explicit_slot 8

block0(v0: i64, v1: i32):
    return v1
}

view this post on Zulip Wasmtime GitHub notifications bot (Jun 28 2023 at 16:49):

fitzgen commented on issue #6661:

Note that if we ever fix this, we will have to make various filetests that rely on us not DCEing stack slots actually touch their stack slots so that they continue to test the stack-limit interactions and such things that they are trying to test.

view this post on Zulip Wasmtime GitHub notifications bot (Jun 28 2023 at 16:58):

bjorn3 commented on issue #6661:

CompiledCode lists all the offsets of all stack slots, thus allowing external code to read and write stack slots. Maybe add a flag to stack slot definitions to indicate that their address is not leaked unless stack_addr explicitly leaks it, and as such are not accessed outside of code inside the function.


Last updated: Dec 23 2024 at 13:07 UTC