Mesa (glsl2): glsl2: Don' t dead-code eliminate a call where the return value is unused.
Eric Anholt
anholt at kemper.freedesktop.org
Thu Aug 5 19:59:54 UTC 2010
Module: Mesa
Branch: glsl2
Commit: 9f82806c7b5109553cf806a5652e6b6198665094
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=9f82806c7b5109553cf806a5652e6b6198665094
Author: Eric Anholt <eric at anholt.net>
Date: Thu Aug 5 12:10:31 2010 -0700
glsl2: Don't dead-code eliminate a call where the return value is unused.
This showed up since the disabling of inlining at compile time, which
I apparently didn't regenerate piglit summary for.
Fixes:
glsl-deadcode-call.
---
src/glsl/ir.h | 3 +++
src/glsl/ir_basic_block.cpp | 13 +++++++++----
src/glsl/ir_dead_code.cpp | 3 ++-
src/glsl/ir_dead_code_local.cpp | 7 ++++++-
4 files changed, 20 insertions(+), 6 deletions(-)
diff --git a/src/glsl/ir.h b/src/glsl/ir.h
index f586025..ef8339c 100644
--- a/src/glsl/ir.h
+++ b/src/glsl/ir.h
@@ -1389,4 +1389,7 @@ extern void
import_prototypes(const exec_list *source, exec_list *dest,
class glsl_symbol_table *symbols, void *mem_ctx);
+extern bool
+ir_has_call(ir_instruction *ir);
+
#endif /* IR_H */
diff --git a/src/glsl/ir_basic_block.cpp b/src/glsl/ir_basic_block.cpp
index f9953ea..a833825 100644
--- a/src/glsl/ir_basic_block.cpp
+++ b/src/glsl/ir_basic_block.cpp
@@ -49,6 +49,14 @@ public:
bool has_call;
};
+bool
+ir_has_call(ir_instruction *ir)
+{
+ ir_has_call_visitor v;
+ ir->accept(&v);
+ return v.has_call;
+}
+
/**
* Calls a user function for every basic block in the instruction stream.
*
@@ -115,8 +123,6 @@ void call_for_basic_blocks(exec_list *instructions,
call_for_basic_blocks(&ir_sig->body, callback, data);
}
} else if (ir->as_assignment()) {
- ir_has_call_visitor v;
-
/* If there's a call in the expression tree being assigned,
* then that ends the BB too.
*
@@ -130,8 +136,7 @@ void call_for_basic_blocks(exec_list *instructions,
* expression flattener may be useful before using the basic
* block finder to get more maximal basic blocks out.
*/
- ir->accept(&v);
- if (v.has_call) {
+ if (ir_has_call(ir)) {
callback(leader, ir, data);
leader = NULL;
}
diff --git a/src/glsl/ir_dead_code.cpp b/src/glsl/ir_dead_code.cpp
index a8d264f..8798887 100644
--- a/src/glsl/ir_dead_code.cpp
+++ b/src/glsl/ir_dead_code.cpp
@@ -78,7 +78,8 @@ do_dead_code(exec_list *instructions)
* Don't do so if it's a shader output, though.
*/
if (entry->var->mode != ir_var_out &&
- entry->var->mode != ir_var_inout) {
+ entry->var->mode != ir_var_inout &&
+ !ir_has_call(entry->assign)) {
entry->assign->remove();
progress = true;
diff --git a/src/glsl/ir_dead_code_local.cpp b/src/glsl/ir_dead_code_local.cpp
index b22cc55..4bbedf0 100644
--- a/src/glsl/ir_dead_code_local.cpp
+++ b/src/glsl/ir_dead_code_local.cpp
@@ -156,7 +156,12 @@ process_assignment(void *ctx, ir_assignment *ir, exec_list *assignments)
}
}
- /* Add this instruction to the assignment list. */
+ /* Add this instruction to the assignment list available to be removed.
+ * But not if the assignment has other side effects.
+ */
+ if (ir_has_call(ir))
+ return progress;
+
assignment_entry *entry = new(ctx) assignment_entry(var, ir);
assignments->push_tail(entry);
More information about the mesa-commit
mailing list