On 22 September 2011 15:21, Kenneth Graunke <span dir="ltr"><<a href="mailto:kenneth@whitecape.org" target="_blank">kenneth@whitecape.org</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Found by inspection.<br>
<br>
Signed-off-by: Kenneth Graunke <<a href="mailto:kenneth@whitecape.org" target="_blank">kenneth@whitecape.org</a>><br>
---<br>
src/glsl/opt_tree_grafting.cpp | 37 ++++++++++++++++++++++++++-----------<br>
1 files changed, 26 insertions(+), 11 deletions(-)<br>
<br>
diff --git a/src/glsl/opt_tree_grafting.cpp b/src/glsl/opt_tree_grafting.cpp<br>
index 22a1749..d9ab2e6 100644<br>
--- a/src/glsl/opt_tree_grafting.cpp<br>
+++ b/src/glsl/opt_tree_grafting.cpp<br>
@@ -148,18 +148,17 @@ ir_tree_grafting_visitor::visit_enter(ir_loop *ir)<br>
return visit_stop;<br>
}<br>
<br>
+/**<br>
+ * Check if we can continue grafting after writing to a variable. If the<br>
+ * expression we're trying to graft references the variable, we must stop.<br>
+ *<br>
+ * \param ir An instruction that writes to a variable.<br>
+ * \param var The variable being updated.<br>
+ */<br>
ir_visitor_status<br>
-ir_tree_grafting_visitor::visit_leave(ir_assignment *ir)<br>
+ir_tree_grafting_visitor::check_graft(ir_instruction *ir, ir_variable *var)<br>
{<br>
- if (do_graft(&ir->rhs) ||<br>
- do_graft(&ir->condition))<br>
- return visit_stop;<br>
-<br>
- /* If this assignment updates a variable used in the assignment<br>
- * we're trying to graft, then we're done.<br>
- */<br>
- if (dereferences_variable(this->graft_assign->rhs,<br>
- ir->lhs->variable_referenced())) {<br>
+ if (dereferences_variable(this->graft_assign->rhs, var)) {<br>
if (debug) {<br>
printf("graft killed by: ");<br>
ir->print();<br>
@@ -172,6 +171,19 @@ ir_tree_grafting_visitor::visit_leave(ir_assignment *ir)<br>
}<br>
<br>
ir_visitor_status<br>
+ir_tree_grafting_visitor::visit_leave(ir_assignment *ir)<br>
+{<br>
+ if (do_graft(&ir->rhs) ||<br>
+ do_graft(&ir->condition))<br>
+ return visit_stop;<br>
+<br>
+ /* If this assignment updates a variable used in the assignment<br>
+ * we're trying to graft, then we're done.<br>
+ */<br>
+ return check_graft(ir, ir->lhs->variable_referenced());<br>
+}<br>
+<br>
+ir_visitor_status<br>
ir_tree_grafting_visitor::visit_enter(ir_function *ir)<br>
{<br>
(void) ir;<br>
@@ -195,8 +207,11 @@ ir_tree_grafting_visitor::visit_enter(ir_call *ir)<br>
ir_rvalue *ir = (ir_rvalue *)iter.get();<br>
ir_rvalue *new_ir = ir;<br>
<br>
- if (sig_param->mode != ir_var_in && sig_param->mode != ir_var_const_in)<br>
+ if (sig_param->mode != ir_var_in && sig_param->mode != ir_var_const_in) {<br>
+ if (check_graft(ir, sig_param) == visit_stop)<br>
+ return visit_stop;<br>
continue;<br>
+ }<br>
<br>
if (do_graft(&new_ir)) {<br>
ir->replace_with(new_ir);<br>
<font color="#888888">--<br>
1.7.6.1<br>
<br>
_______________________________________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org" target="_blank">mesa-dev@lists.freedesktop.org</a><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/mesa-dev" target="_blank">http://lists.freedesktop.org/mailman/listinfo/mesa-dev</a><br>
</font></blockquote></div><br>It looks like you need to add this line to the class declaration to get it to compile:<br><br>ir_visitor_status check_graft(ir_instruction *ir, ir_variable *var);<br><br>I'm assuming that you actually tried this code and it worked, and this was just a rebasing error? If so, then this code is<br>
<br>Reviewed-by: Paul Berry <<a href="mailto:stereotype441@gmail.com" target="_blank">stereotype441@gmail.com</a>><br><br>BTW, any interest in trying to craft a Piglit test that validates this fix? I'm guessing it shouldn't be too hard (famous last words, I know).<br>