freedreno/ir3/ra: assign vreg names to all array elements
authorRob Clark <robdclark@chromium.org>
Thu, 16 Jul 2020 19:41:11 +0000 (12:41 -0700)
committerRob Clark <robdclark@chromium.org>
Sat, 18 Jul 2020 16:21:09 +0000 (09:21 -0700)
We shouldn't divide-by-two for half-reg arrays.  We set the proper node
interference class, based on `arr->half`.

Fixes a RA fail with 16b arrays:

  src/freedreno/ir3/ir3_ra.c:633: name_to_array: Assertion `!"invalid array name"' failed.

Caused by use/def iterators returning `arr->length` vreg namess, but
only assigning the array half that many names.

Also, since we are assigning unique vreg names to each array element,
there is no need to try and convert from half-reg to it's conflicting
full reg when pre-coloring the array elements.  Getting us closer to
having half-arrays work sanely with split-register-file (a5xx and
earlier).

Signed-off-by: Rob Clark <robdclark@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5957>

src/freedreno/ir3/ir3_ra.c

index 060784ce9863e25448edd9c6851f0add1112cfc2..156299fc18e4999dc8eb139d160cf5e4381f0279 100644 (file)
@@ -552,8 +552,8 @@ ra_init(struct ir3_ra_ctx *ctx)
        base = ctx->class_base[total_class_count];
        foreach_array (arr, &ctx->ir->array_list) {
                arr->base = base;
-               ctx->class_alloc_count[total_class_count] += reg_size_for_array(arr);
-               base += reg_size_for_array(arr);
+               ctx->class_alloc_count[total_class_count] += arr->length;
+               base += arr->length;
        }
        ctx->alloc_count += ctx->class_alloc_count[total_class_count];
 
@@ -626,8 +626,7 @@ name_to_array(struct ir3_ra_ctx *ctx, unsigned name)
 {
        ra_assert(ctx, name_is_array(ctx, name));
        foreach_array (arr, &ctx->ir->array_list) {
-               unsigned sz = reg_size_for_array(arr);
-               if (name < (arr->base + sz))
+               if (name < (arr->base + arr->length))
                        return arr;
        }
        ra_unreachable(ctx, "invalid array name");
@@ -1344,11 +1343,8 @@ ra_precolor(struct ir3_ra_ctx *ctx, struct ir3_instruction **precolor, unsigned
                }
        }
 
-       /* pre-assign array elements:
-        *
-        * TODO this is going to need some work for half-precision.. possibly
-        * this is easier on a6xx, where we can just divide array size by two?
-        * But on a5xx and earlier it will need to track two bases.
+       /*
+        * Pre-assign array elements:
         */
        foreach_array (arr, &ctx->ir->array_list) {
 
@@ -1358,28 +1354,12 @@ ra_precolor(struct ir3_ra_ctx *ctx, struct ir3_instruction **precolor, unsigned
                if (!ctx->scalar_pass)
                        assign_arr_base(ctx, arr, precolor, nprecolor);
 
-               unsigned base = arr->reg;
-
                for (unsigned i = 0; i < arr->length; i++) {
-                       unsigned name, reg;
-
-                       if (arr->half) {
-                               /* Doesn't need to do this on older generations than a6xx,
-                                * since there's no conflict between full regs and half regs
-                                * on them.
-                                *
-                                * TODO Presumably "base" could start from 0 respectively
-                                * for half regs of arrays on older generations.
-                                */
-                               unsigned base_half = base * 2 + i;
-                               reg = ctx->set->gpr_to_ra_reg[0+HALF_OFFSET][base_half];
-                               base = base_half / 2 + 1;
-                       } else {
-                               reg = ctx->set->gpr_to_ra_reg[0][base++];
-                       }
+                       unsigned cls = arr->half ? HALF_OFFSET : 0;
 
-                       name = arr->base + i;
-                       ra_set_node_reg(ctx->g, name, reg);
+                       ra_set_node_reg(ctx->g,
+                                       arr->base + i,   /* vreg name */
+                                       ctx->set->gpr_to_ra_reg[cls][arr->reg + i]);
                }
        }