CSE tries to collapse equal instructions, and collapsing two phis with incompatible dests is illegal.
Reviewed-by: Konstantin Seurer <konstantin.seurer@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Reviewed-by: Jason Ekstrand <jason.ekstrand@collabora.com>
Fixes:
6bdce55c ("nir: Add a basic CSE pass")
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19960>
if (phi1->instr.block != phi2->instr.block)
return false;
+ /* In case of phis with no sources, the dest needs to be checked
+ * to ensure that phis with incompatible dests won't get merged
+ * during CSE. */
+ if (phi1->dest.ssa.num_components != phi2->dest.ssa.num_components)
+ return false;
+ if (phi1->dest.ssa.bit_size != phi2->dest.ssa.bit_size)
+ return false;
+
nir_foreach_phi_src(src1, phi1) {
nir_foreach_phi_src(src2, phi2) {
if (src1->pred == src2->pred) {