[Mesa-dev] [PATCH] nir/algebraic: Only replace an instruction once

Jason Ekstrand jason at jlekstrand.net
Wed Jan 14 19:15:03 PST 2015


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.
---
 src/glsl/nir/nir_algebraic.py | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/glsl/nir/nir_algebraic.py b/src/glsl/nir/nir_algebraic.py
index 72703be..f9b246d 100644
--- a/src/glsl/nir/nir_algebraic.py
+++ b/src/glsl/nir/nir_algebraic.py
@@ -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
-- 
2.2.1



More information about the mesa-dev mailing list