nir/algebraic: Only replace an instruction once
authorJason Ekstrand <jason.ekstrand@intel.com>
Thu, 15 Jan 2015 03:08:32 +0000 (19:08 -0800)
committerJason Ekstrand <jason.ekstrand@intel.com>
Thu, 15 Jan 2015 15:20:24 +0000 (07:20 -0800)
Without the break, it was possible that an instruction would match multiple
expressions.  If this happened, you could end up trying to replace it
multiple times and get a segfault.  This makes it so that, after a
successful replacement, it moves on to the next instruction.

Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
src/glsl/nir/nir_algebraic.py

index 72703beea8a2eb8693a9bb8393e1d17a17e8aaf4..f9b246dd86529879ae1863ccb856511ffc26b38c 100644 (file)
@@ -192,8 +192,10 @@ ${pass_name}_block(nir_block *block, void *void_state)
          for (unsigned i = 0; i < ARRAY_SIZE(${pass_name}_${opcode}_xforms); i++) {
             if (nir_replace_instr(alu, ${pass_name}_${opcode}_xforms[i].search,
                                   ${pass_name}_${opcode}_xforms[i].replace,
-                                  state->mem_ctx))
+                                  state->mem_ctx)) {
                state->progress = true;
+               break;
+            }
          }
          break;
       % endfor