From: Nicolai Hähnle <nicolai.haeh...@amd.com>

Avoid a v_cndmask: the absolute value is free due to input modifiers.
---
 src/amd/common/ac_llvm_build.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/src/amd/common/ac_llvm_build.c b/src/amd/common/ac_llvm_build.c
index 8c050f31a76..71468df2dbc 100644
--- a/src/amd/common/ac_llvm_build.c
+++ b/src/amd/common/ac_llvm_build.c
@@ -431,26 +431,27 @@ build_cube_intrinsic(struct ac_llvm_context *ctx,
 
 /**
  * Build a manual selection sequence for cube face sc/tc coordinates and
  * major axis vector (multiplied by 2 for consistency) for the given
  * vec3 \p coords, for the face implied by \p selcoords.
  *
  * For the major axis, we always adjust the sign to be in the direction of
  * selcoords.ma; i.e., a positive out_ma means that coords is pointed towards
  * the selcoords major axis.
  */
-static void build_cube_select(LLVMBuilderRef builder,
+static void build_cube_select(struct ac_llvm_context *ctx,
                              const struct cube_selection_coords *selcoords,
                              const LLVMValueRef *coords,
                              LLVMValueRef *out_st,
                              LLVMValueRef *out_ma)
 {
+       LLVMBuilderRef builder = ctx->builder;
        LLVMTypeRef f32 = LLVMTypeOf(coords[0]);
        LLVMValueRef is_ma_positive;
        LLVMValueRef sgn_ma;
        LLVMValueRef is_ma_z, is_not_ma_z;
        LLVMValueRef is_ma_y;
        LLVMValueRef is_ma_x;
        LLVMValueRef sgn;
        LLVMValueRef tmp;
 
        is_ma_positive = LLVMBuildFCmp(builder, LLVMRealUGE,
@@ -473,23 +474,23 @@ static void build_cube_select(LLVMBuilderRef builder,
 
        /* Select tc */
        tmp = LLVMBuildSelect(builder, is_ma_y, coords[2], coords[1], "");
        sgn = LLVMBuildSelect(builder, is_ma_y, sgn_ma,
                LLVMConstReal(f32, -1.0), "");
        out_st[1] = LLVMBuildFMul(builder, tmp, sgn, "");
 
        /* Select ma */
        tmp = LLVMBuildSelect(builder, is_ma_z, coords[2],
                LLVMBuildSelect(builder, is_ma_y, coords[1], coords[0], ""), 
"");
-       sgn = LLVMBuildSelect(builder, is_ma_positive,
-               LLVMConstReal(f32, 2.0), LLVMConstReal(f32, -2.0), "");
-       *out_ma = LLVMBuildFMul(builder, tmp, sgn, "");
+       tmp = ac_build_intrinsic(ctx, "llvm.fabs.f32",
+                                ctx->f32, &tmp, 1, AC_FUNC_ATTR_READNONE);
+       *out_ma = LLVMBuildFMul(builder, tmp, LLVMConstReal(f32, 2.0), "");
 }
 
 void
 ac_prepare_cube_coords(struct ac_llvm_context *ctx,
                       bool is_deriv, bool is_array, bool is_lod,
                       LLVMValueRef *coords_arg,
                       LLVMValueRef *derivs_arg)
 {
 
        LLVMBuilderRef builder = ctx->builder;
@@ -563,21 +564,21 @@ ac_prepare_cube_coords(struct ac_llvm_context *ctx,
                         *            = 1/z * dx/dh - x/z * 1/z * dz/dh.
                         *
                         * This motivatives the implementation below.
                         *
                         * Whether this actually gives the expected results for
                         * apps that might feed in derivatives obtained via
                         * finite differences is anyone's guess. The OpenGL spec
                         * seems awfully quiet about how textureGrad for cube
                         * maps should be handled.
                         */
-                       build_cube_select(builder, &selcoords, &derivs_arg[axis 
* 3],
+                       build_cube_select(ctx, &selcoords, &derivs_arg[axis * 
3],
                                          deriv_st, &deriv_ma);
 
                        deriv_ma = LLVMBuildFMul(builder, deriv_ma, invma, "");
 
                        for (int i = 0; i < 2; ++i)
                                derivs[axis * 2 + i] =
                                        LLVMBuildFSub(builder,
                                                LLVMBuildFMul(builder, 
deriv_st[i], invma, ""),
                                                LLVMBuildFMul(builder, 
deriv_ma, coords[i], ""), "");
                }
-- 
2.11.0

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

Reply via email to