Signed-off-by: Samuel Pitoiset <samuel.pitoi...@gmail.com>
---
 src/compiler/glsl/ir_optimization.h      |  1 +
 src/compiler/glsl/lower_instructions.cpp | 14 ++++++++++++++
 2 files changed, 15 insertions(+)

diff --git a/src/compiler/glsl/ir_optimization.h 
b/src/compiler/glsl/ir_optimization.h
index 67a7514c7d..b103687973 100644
--- a/src/compiler/glsl/ir_optimization.h
+++ b/src/compiler/glsl/ir_optimization.h
@@ -51,6 +51,7 @@
 #define IMUL_HIGH_TO_MUL          0x80000
 #define DDIV_TO_MUL_RCP           0x100000
 #define DIV_TO_MUL_RCP            (FDIV_TO_MUL_RCP | DDIV_TO_MUL_RCP)
+#define SQRT_TO_ABS_SQRT          0x200000
 
 /* Opertaions for lower_64bit_integer_instructions() */
 #define MUL64                     (1U << 0)
diff --git a/src/compiler/glsl/lower_instructions.cpp 
b/src/compiler/glsl/lower_instructions.cpp
index 729cb13f84..697bb84344 100644
--- a/src/compiler/glsl/lower_instructions.cpp
+++ b/src/compiler/glsl/lower_instructions.cpp
@@ -168,6 +168,7 @@ private:
    void find_lsb_to_float_cast(ir_expression *ir);
    void find_msb_to_float_cast(ir_expression *ir);
    void imul_high_to_mul(ir_expression *ir);
+   void sqrt_to_abs_sqrt(ir_expression *ir);
 
    ir_expression *_carry(operand a, operand b);
 };
@@ -1582,6 +1583,13 @@ 
lower_instructions_visitor::imul_high_to_mul(ir_expression *ir)
    }
 }
 
+void
+lower_instructions_visitor::sqrt_to_abs_sqrt(ir_expression *ir)
+{
+   ir->operands[0] = new(ir) ir_expression(ir_unop_abs, ir->operands[0]);
+   this->progress = true;
+}
+
 ir_visitor_status
 lower_instructions_visitor::visit_leave(ir_expression *ir)
 {
@@ -1719,6 +1727,12 @@ lower_instructions_visitor::visit_leave(ir_expression 
*ir)
          imul_high_to_mul(ir);
       break;
 
+   case ir_unop_rsq:
+   case ir_unop_sqrt:
+      if (lowering(SQRT_TO_ABS_SQRT))
+         sqrt_to_abs_sqrt(ir);
+      break;
+
    default:
       return visit_continue;
    }
-- 
2.12.0

_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to