Mesa (main): glsl: Drop INT_DIV_TO_MUL_RCP lowering.

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Tue Jun 7 03:04:36 UTC 2022


Module: Mesa
Branch: main
Commit: ab3a1d41c5adceb864e5f62405cdb4ad13f7f5e1
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=ab3a1d41c5adceb864e5f62405cdb4ad13f7f5e1

Author: Emma Anholt <emma at anholt.net>
Date:   Tue May 31 13:52:57 2022 -0700

glsl: Drop INT_DIV_TO_MUL_RCP lowering.

nir_lower_int_to_float() does this at the end of compilation, no need to
do it up front.

Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig at collabora.com>
Reviewed-by: Timothy Arceri <tarceri at itsqueeze.com>
Reviewed-by: Erik Faye-Lund <erik.faye-lund at collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16823>

---

 src/compiler/glsl/ir_optimization.h      |  1 -
 src/compiler/glsl/lower_instructions.cpp | 63 --------------------------------
 src/mesa/state_tracker/st_glsl_to_ir.cpp |  1 -
 3 files changed, 65 deletions(-)

diff --git a/src/compiler/glsl/ir_optimization.h b/src/compiler/glsl/ir_optimization.h
index 0f24f08d7be..0c627d12fac 100644
--- a/src/compiler/glsl/ir_optimization.h
+++ b/src/compiler/glsl/ir_optimization.h
@@ -35,7 +35,6 @@ struct gl_shader_program;
 
 /* Operations for lower_instructions() */
 #define SUB_TO_ADD_NEG     0x01
-#define INT_DIV_TO_MUL_RCP 0x40
 #define LDEXP_TO_ARITH     0x80
 #define CARRY_TO_ARITH     0x100
 #define BORROW_TO_ARITH    0x200
diff --git a/src/compiler/glsl/lower_instructions.cpp b/src/compiler/glsl/lower_instructions.cpp
index 9d42ccdd15e..2e37054bbbf 100644
--- a/src/compiler/glsl/lower_instructions.cpp
+++ b/src/compiler/glsl/lower_instructions.cpp
@@ -31,7 +31,6 @@
  *
  * Currently supported transformations:
  * - SUB_TO_ADD_NEG
- * - INT_DIV_TO_MUL_RCP
  * - LDEXP_TO_ARITH
  * - CARRY_TO_ARITH
  * - BORROW_TO_ARITH
@@ -47,11 +46,6 @@
  * want to recognize add(op0, neg(op1)) or the other way around to
  * produce a subtract anyway.
  *
- * INT_DIV_TO_MUL_RCP:
- * ---------------------------------------------------------
- * Breaks an ir_binop_div expression down to f2i(i2f(op0) * (rcp(i2f(op1))).
- * Used for !NativeIntegers HW.
- *
  * LDEXP_TO_ARITH:
  * -------------
  * Converts ir_binop_ldexp to arithmetic and bit operations for float sources.
@@ -100,7 +94,6 @@ private:
    unsigned lower; /** Bitfield of which operations to lower */
 
    void sub_to_add_neg(ir_expression *);
-   void int_div_to_mul_rcp(ir_expression *);
    void ldexp_to_arith(ir_expression *);
    void dldexp_to_arith(ir_expression *);
    void dfrexp_sig_to_arith(ir_expression *);
@@ -157,57 +150,6 @@ lower_instructions_visitor::sub_to_add_neg(ir_expression *ir)
    this->progress = true;
 }
 
-void
-lower_instructions_visitor::int_div_to_mul_rcp(ir_expression *ir)
-{
-   assert(ir->operands[1]->type->is_integer_32());
-
-   /* Be careful with integer division -- we need to do it as a
-    * float and re-truncate, since rcp(n > 1) of an integer would
-    * just be 0.
-    */
-   ir_rvalue *op0, *op1;
-   const struct glsl_type *vec_type;
-
-   vec_type = glsl_type::get_instance(GLSL_TYPE_FLOAT,
-				      ir->operands[1]->type->vector_elements,
-				      ir->operands[1]->type->matrix_columns);
-
-   if (ir->operands[1]->type->base_type == GLSL_TYPE_INT)
-      op1 = new(ir) ir_expression(ir_unop_i2f, vec_type, ir->operands[1], NULL);
-   else
-      op1 = new(ir) ir_expression(ir_unop_u2f, vec_type, ir->operands[1], NULL);
-
-   op1 = new(ir) ir_expression(ir_unop_rcp, op1->type, op1, NULL);
-
-   vec_type = glsl_type::get_instance(GLSL_TYPE_FLOAT,
-				      ir->operands[0]->type->vector_elements,
-				      ir->operands[0]->type->matrix_columns);
-
-   if (ir->operands[0]->type->base_type == GLSL_TYPE_INT)
-      op0 = new(ir) ir_expression(ir_unop_i2f, vec_type, ir->operands[0], NULL);
-   else
-      op0 = new(ir) ir_expression(ir_unop_u2f, vec_type, ir->operands[0], NULL);
-
-   vec_type = glsl_type::get_instance(GLSL_TYPE_FLOAT,
-				      ir->type->vector_elements,
-				      ir->type->matrix_columns);
-
-   op0 = new(ir) ir_expression(ir_binop_mul, vec_type, op0, op1);
-
-   if (ir->operands[1]->type->base_type == GLSL_TYPE_INT) {
-      ir->operation = ir_unop_f2i;
-      ir->operands[0] = op0;
-   } else {
-      ir->operation = ir_unop_i2u;
-      ir->operands[0] = new(ir) ir_expression(ir_unop_f2i, op0);
-   }
-   ir->init_num_operands();
-   ir->operands[1] = NULL;
-
-   this->progress = true;
-}
-
 void
 lower_instructions_visitor::ldexp_to_arith(ir_expression *ir)
 {
@@ -1515,11 +1457,6 @@ lower_instructions_visitor::visit_leave(ir_expression *ir)
 	 sub_to_add_neg(ir);
       break;
 
-   case ir_binop_div:
-      if (ir->operands[1]->type->is_integer_32() && lowering(INT_DIV_TO_MUL_RCP))
-	 int_div_to_mul_rcp(ir);
-      break;
-
    case ir_binop_ldexp:
       if (lowering(LDEXP_TO_ARITH) && ir->type->is_float())
          ldexp_to_arith(ir);
diff --git a/src/mesa/state_tracker/st_glsl_to_ir.cpp b/src/mesa/state_tracker/st_glsl_to_ir.cpp
index f8a94cfb656..79496f1e913 100644
--- a/src/mesa/state_tracker/st_glsl_to_ir.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_ir.cpp
@@ -108,7 +108,6 @@ link_shader(struct gl_context *ctx, struct gl_shader_program *prog)
                          CARRY_TO_ARITH |
                          BORROW_TO_ARITH |
                          (have_dround ? 0 : DOPS_TO_DFRAC) |
-                         (!ctx->Const.NativeIntegers ? INT_DIV_TO_MUL_RCP : 0) |
                          (ctx->Const.ForceGLSLAbsSqrt ? SQRT_TO_ABS_SQRT : 0) |
                          /* Assume that if ARB_gpu_shader5 is not supported
                           * then all of the extended integer functions need



More information about the mesa-commit mailing list