From: Samuel Iglesias Gonsalvez Date: Tue, 24 Feb 2015 18:02:57 +0000 (+0100) Subject: glsl: optimize (0 cmp x + y) into (-x cmp y). X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=b43bbfa90ace596c8b2e0b3954a5f69924726c59;p=mesa.git glsl: optimize (0 cmp x + y) into (-x cmp y). 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 Reviewed-by: Ian Romanick Reviewed-by: Matt Turner Cc: "10.4 10.5" --- diff --git a/src/glsl/opt_algebraic.cpp b/src/glsl/opt_algebraic.cpp index c6040bff825..69c03ea8be7 100644 --- a/src/glsl/opt_algebraic.cpp +++ b/src/glsl/opt_algebraic.cpp @@ -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;