[Mesa-dev] [PATCH] glsl: skip mul by zero opt for floating point expression

vadym.shovkoplias vadim.shovkoplias at gmail.com
Mon Jul 2 15:22:10 UTC 2018


From: Vadym Shovkoplias <vadym.shovkoplias at globallogic.com>

One of the operands can be NaN and multiplication by zero
should also result to NaN value. E.g:

float Temp = 0.0;
void main()
{
	Temp = log2(Temp);
	Temp = Temp * 0.0;
        isnan(Temp);
        ...
}

here Temp should be NaN and isnan() should return true.

Signed-off-by: Vadym Shovkoplias <vadym.shovkoplias at globallogic.com>
---
 src/compiler/glsl/opt_algebraic.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/compiler/glsl/opt_algebraic.cpp b/src/compiler/glsl/opt_algebraic.cpp
index ff4be26957..2d01575bb3 100644
--- a/src/compiler/glsl/opt_algebraic.cpp
+++ b/src/compiler/glsl/opt_algebraic.cpp
@@ -590,7 +590,8 @@ ir_algebraic_visitor::handle_expression(ir_expression *ir)
       if (is_vec_one(op_const[1]))
 	 return ir->operands[0];
 
-      if (is_vec_zero(op_const[0]) || is_vec_zero(op_const[1]))
+      if ((is_vec_zero(op_const[0]) || is_vec_zero(op_const[1])) &&
+	!ir->type->is_float() && !ir->type->is_double())
 	 return ir_constant::zero(ir, ir->type);
 
       if (is_vec_negative_one(op_const[0]))
-- 
2.18.0



More information about the mesa-dev mailing list