[Mesa-dev] [PATCH 21/23] glsl: Recognize double negated multiplies and divides as equal
Ian Romanick
idr at freedesktop.org
Fri Mar 20 13:58:21 PDT 2015
From: Ian Romanick <ian.d.romanick at intel.com>
For example (-x * 43) and (x * -43) should be considered common.
No shader-db changes. I'll probably drop this patch, but I wanted to
send it out to show that I tried this too.
Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
---
src/glsl/ir_equals.cpp | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/src/glsl/ir_equals.cpp b/src/glsl/ir_equals.cpp
index 5f5af5b..664cbfa 100644
--- a/src/glsl/ir_equals.cpp
+++ b/src/glsl/ir_equals.cpp
@@ -218,6 +218,16 @@ ir_expression::equals(const ir_instruction *ir, enum ir_node_type ignore) const
if (operation != other->operation)
return false;
+ if (operation == ir_binop_mul || operation == ir_binop_div) {
+ /* For multiplication and division we want an even-parity of negations on
+ * operands. This means that 'x * y' equals '-x * -y'.
+ */
+ return ((operands[0]->equals(other->operands[0], ignore) &&
+ operands[1]->equals(other->operands[1], ignore)) ||
+ (operands[0]->negative_equals(other->operands[0], ignore) &&
+ operands[1]->negative_equals(other->operands[1], ignore)));
+ }
+
for (unsigned i = 0; i < get_num_operands(); i++) {
if (!operands[i]->equals(other->operands[i], ignore))
return false;
--
2.1.0
More information about the mesa-dev
mailing list