spirv: Run repair_ssa if there are discard instructions
authorJason Ekstrand <jason@jlekstrand.net>
Mon, 1 Jun 2020 23:01:05 +0000 (18:01 -0500)
committerMarge Bot <eric+marge@anholt.net>
Tue, 8 Sep 2020 19:44:01 +0000 (19:44 +0000)
commit7cedc4128a1f9d8ecae00ff41ccf1b63e4f3ebd0
tree2eb31408fbd3de40484310c14af3dfc37f015c5a
parent45bcb1084139b58378551e2d954bd6032db20330
spirv: Run repair_ssa if there are discard instructions

SPIR-V's OpKill is a control-flow instruction but NIR's discard is not.
Therefore, it can be valid SPIR-V to have

    if (...) {
        foo = /* something */
    } else {
        discard;
    }
    use(foo);

without any phi between the definition of foo and its use.  This is not
true in NIR, however, because NIR's discard isn't considered
control-flow.  Arguably, this is a NIR bug but making discard control-
flow is a very deep change that can have serious ans subtle
side-effects.   The easier thing to do is just fix up the SSA in case we
have an OpKill which might have gotten us into the above case.

Fixes dEQP-VK.graphicsfuzz.vectors-and-discard-in-function with the new
NIR dominance validation pass enabled.

Cc: mesa-stable@lists.freedesktop.org
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5288>
src/compiler/spirv/vtn_cfg.c
src/compiler/spirv/vtn_private.h