freedreno/ir3: fix crash
[mesa.git] / src / freedreno / ir3 / ir3_depth.c
index 77f9af6173f14a9db4921c3143b1e659e462446f..4e377fa4ee5ce65a924c042fb2231fc32341d9a0 100644 (file)
@@ -177,27 +177,21 @@ remove_unused_by_block(struct ir3_block *block)
                        if (instr->opc == OPC_META_FO) {
                                struct ir3_instruction *src = ssa(instr->regs[1]);
                                if (src->regs[0]->wrmask > 1) {
-                                       unsigned newn, lastn;
-
-                                       lastn = util_last_bit(src->regs[0]->wrmask);
                                        src->regs[0]->wrmask &= ~(1 << instr->fo.off);
-                                       newn = util_last_bit(src->regs[0]->wrmask);
 
                                        /* prune no-longer needed right-neighbors.  We could
                                         * probably do the same for left-neighbors (ie. tex
                                         * fetch that only need .yw components), but that
                                         * makes RA a bit more confusing than it already is
                                         */
-                                       if (newn < lastn) {
-                                               struct ir3_instruction *n = ir3_neighbor_first(instr);
-                                               for (unsigned i = 1; i < newn; i++) {
-                                                       n = n->cp.right;
-                                               }
-                                               // XXX I don't think n should be null here!
-                                               if (n) {
-                                                       debug_assert(n->cp.right->flags & IR3_INSTR_UNUSED);
-                                                       n->cp.right = NULL;
-                                               }
+                                       struct ir3_instruction *n = instr;
+                                       while (n && n->cp.right)
+                                               n = n->cp.right;
+                                       while (n->flags & IR3_INSTR_UNUSED) {
+                                               n = n->cp.left;
+                                               if (!n)
+                                                       break;
+                                               n->cp.right = NULL;
                                        }
                                }
                        }