diff --git a/src/compiler/nir/nir_instr_set.c b/src/compiler/nir/nir_instr_set.c index 47c26db2c6c..a43efe025df 100644 --- a/src/compiler/nir/nir_instr_set.c +++ b/src/compiler/nir/nir_instr_set.c @@ -778,8 +778,6 @@ nir_instr_set_add_or_rewrite(struct set *instr_set, nir_instr *instr, nir_def_rewrite_uses(def, new_def); - nir_instr_remove(instr); - return match; } else { /* otherwise, replace hashed instruction */ diff --git a/src/compiler/nir/nir_opt_cse.c b/src/compiler/nir/nir_opt_cse.c index 76760a876d1..3f72b35eb71 100644 --- a/src/compiler/nir/nir_opt_cse.c +++ b/src/compiler/nir/nir_opt_cse.c @@ -47,6 +47,7 @@ nir_opt_cse_impl(nir_function_impl *impl) nir_foreach_instr_safe(instr, block) { if (nir_instr_set_add_or_rewrite(instr_set, instr, dominates)) { progress = true; + nir_instr_remove(instr); } } } diff --git a/src/compiler/nir/nir_opt_gcm.c b/src/compiler/nir/nir_opt_gcm.c index 4cc2b09c56d..1e76dca8984 100644 --- a/src/compiler/nir/nir_opt_gcm.c +++ b/src/compiler/nir/nir_opt_gcm.c @@ -838,8 +838,10 @@ opt_gcm_impl(nir_shader *shader, nir_function_impl *impl, bool value_number) continue; if (nir_instr_set_add_or_rewrite(gvn_set, instr, - value_number ? NULL : weak_gvn)) + value_number ? NULL : weak_gvn)) { state.progress = true; + nir_instr_remove(instr); + } } nir_instr_set_destroy(gvn_set); diff --git a/src/compiler/nir/nir_opt_reuse_constants.c b/src/compiler/nir/nir_opt_reuse_constants.c index 79f885be406..8e78a6cc0c1 100644 --- a/src/compiler/nir/nir_opt_reuse_constants.c +++ b/src/compiler/nir/nir_opt_reuse_constants.c @@ -33,6 +33,7 @@ nir_opt_reuse_constants(nir_shader *shader) if (nir_instr_set_add_or_rewrite(consts, instr, nir_instrs_equal)) { func_progress = true; + nir_instr_remove(instr); } } }