[Mesa-dev] [PATCH 02/59] glsl/standalone: Optimize add-of-neg to subtract
Ian Romanick
idr at freedesktop.org
Wed Oct 26 00:59:08 UTC 2016
From: Ian Romanick <ian.d.romanick at intel.com>
This just makes the output of the standalone compiler a little more
compact.
Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
---
src/compiler/glsl/standalone.cpp | 34 ++++++++++++++++++++++++++++++++++
1 file changed, 34 insertions(+)
diff --git a/src/compiler/glsl/standalone.cpp b/src/compiler/glsl/standalone.cpp
index 055c433..b41d25c 100644
--- a/src/compiler/glsl/standalone.cpp
+++ b/src/compiler/glsl/standalone.cpp
@@ -38,6 +38,37 @@
#include "standalone.h"
#include "util/string_to_uint_map.h"
+class add_neg_to_sub_visitor : public ir_hierarchical_visitor {
+public:
+ add_neg_to_sub_visitor()
+ {
+ /* empty */
+ }
+
+ ir_visitor_status visit_leave(ir_expression *ir)
+ {
+ if (ir->operation != ir_binop_add)
+ return visit_continue;
+
+ for (unsigned i = 0; i < 2; i++) {
+ ir_expression *const op = ir->operands[i]->as_expression();
+
+ if (op != NULL && op->operation == ir_unop_neg) {
+ ir->operation = ir_binop_sub;
+
+ /* This ensures that -a + b becomes b - a. */
+ if (i == 0)
+ ir->operands[0] = ir->operands[1];
+
+ ir->operands[i] = op->operands[0];
+ break;
+ }
+ }
+
+ return visit_continue;
+ }
+};
+
static const struct standalone_options *options;
static void
@@ -441,6 +472,9 @@ standalone_compile_shader(const struct standalone_options *_options,
if (!shader)
continue;
+ add_neg_to_sub_visitor v;
+ visit_list_elements(&v, shader->ir);
+
shader->Program = rzalloc(shader, gl_program);
init_gl_program(shader->Program, shader->Stage);
}
--
2.5.5
More information about the mesa-dev
mailing list