glsl: optimize (0 cmp x + y) into (-x cmp y).
authorSamuel Iglesias Gonsalvez <siglesias@igalia.com>
Tue, 24 Feb 2015 18:02:57 +0000 (19:02 +0100)
committerEduardo Lima Mitev <elima@igalia.com>
Fri, 13 Mar 2015 15:40:20 +0000 (16:40 +0100)
The optimization done by commit 34ec1a24d did not take it into account.

Fixes:

dEQP-GLES3.functional.shaders.random.all_features.fragment.20

Signed-off-by: Samuel Iglesias Gonsalvez <siglesias@igalia.com>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
Reviewed-by: Matt Turner <mattst88@gmail.com>
Cc: "10.4 10.5" <mesa-stable@lists.freedesktop.org>
src/glsl/opt_algebraic.cpp

index c6040bff825474185eb4fe5fa8efb056cedbc634..69c03ea8be7f237d3d9dae60dd40d7fbc2b392d5 100644 (file)
@@ -626,9 +626,18 @@ ir_algebraic_visitor::handle_expression(ir_expression *ir)
          if (!is_vec_zero(zero))
             continue;
 
-         return new(mem_ctx) ir_expression(ir->operation,
-                                           add->operands[0],
-                                           neg(add->operands[1]));
+         /* Depending of the zero position we want to optimize
+          * (0 cmp x+y) into (-x cmp y) or (x+y cmp 0) into (x cmp -y)
+          */
+         if (add_pos == 1) {
+            return new(mem_ctx) ir_expression(ir->operation,
+                                              neg(add->operands[0]),
+                                              add->operands[1]);
+         } else {
+            return new(mem_ctx) ir_expression(ir->operation,
+                                              add->operands[0],
+                                              neg(add->operands[1]));
+         }
       }
       break;