gallivm: simplify shuffling in emit_store_reg()
authorBrian Paul <brianp@vmware.com>
Tue, 5 Jul 2022 22:34:39 +0000 (16:34 -0600)
committerMarge Bot <emma+marge@anholt.net>
Wed, 27 Jul 2022 22:24:56 +0000 (22:24 +0000)
The writemask can be implemented with just one llvm vector shuffle.

Signed-off-by: Brian Paul <brianp@vmware.com>
Reviewed-by: Dave Airlie <airlied@redhat.com>
Reviewed-by: Roland Scheidegger <sroland@vmware.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17561>

src/gallium/auxiliary/gallivm/lp_bld_nir_aos.c

index 425ee66..4e05b11 100644 (file)
@@ -197,20 +197,18 @@ emit_store_reg(struct lp_build_nir_context *bld_base,
 
    LLVMValueRef cur = LLVMBuildLoad(gallivm->builder, reg_storage, "");
    LLVMTypeRef i32t = LLVMInt32TypeInContext(gallivm->context);
-   for (unsigned i = 0; i < 4; i++) {
-      if (writemask & (1 << i)) {
-         LLVMValueRef shuffles[LP_MAX_VECTOR_LENGTH] = { 0 };
-         for (unsigned j = 0; j < 16; j++){
-            if (j % 4 == i)
-               shuffles[j] = LLVMConstInt(i32t, 16 + j, 0);
-            else
-               shuffles[j] = LLVMConstInt(i32t, j, 0);
-         }
-
-         cur = LLVMBuildShuffleVector(gallivm->builder, cur, dst[0],
-                                      LLVMConstVector(shuffles, 16), "");
+   LLVMValueRef shuffles[LP_MAX_VECTOR_LENGTH];
+   for (unsigned j = 0; j < 16; j++) {
+      unsigned comp = j % 4;
+      if (writemask & (1 << comp)) {
+         shuffles[j] = LLVMConstInt(i32t, 16 + j, 0); // new val
+      } else {
+         shuffles[j] = LLVMConstInt(i32t, j, 0);      // cur val
       }
    }
+   cur = LLVMBuildShuffleVector(gallivm->builder, cur, dst[0],
+                                LLVMConstVector(shuffles, 16), "");
+
    LLVMBuildStore(gallivm->builder, cur, reg_storage);
 }