nir/opt_if: Fix opt_if_simplification when else branch has jump
authorDanylo Piliaiev <danylo.piliaiev@globallogic.com>
Thu, 16 Jul 2020 18:09:08 +0000 (21:09 +0300)
committerMarge Bot <eric+marge@anholt.net>
Wed, 22 Jul 2020 14:20:21 +0000 (14:20 +0000)
commit6f94b3da111f65a46126fdb3652474dc4d9cbda5
tree2b321b9392d8519bd2f850a2fb222740b31f0f48
parent3f783a3c507e16bffb2e460484fbf65eb11ba826
nir/opt_if: Fix opt_if_simplification when else branch has jump

Consider the following case:

 if ssa_1 {
    block block_2:
    /* succs: block_4 */
 } else {
    block block_3:
    ...
    break
    /* succs: block_5 */
 }

 block block_4:
 vec1 32 ssa_100 = phi block_2: ssa_2

After block_3 extraction and reinsertion, phi->pred becomes invalid
and isn't updated by reinsertion since it is unreachable from block_3.

Call nir_opt_remove_phis_block before moving block to eliminate single
source phis after the if.

Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/3282
Fixes: e3e929f8c342b32dc8f5296adf8fb337866fa40a
Signed-off-by: Danylo Piliaiev <danylo.piliaiev@globallogic.com>
Reviewed-by: Matt Turner <mattst88@gmail.com>
Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5945>
src/compiler/nir/nir_opt_if.c