+static void
+assign_arr_base(struct ir3_ra_ctx *ctx, struct ir3_array *arr,
+ struct ir3_instruction **precolor, unsigned nprecolor)
+{
+ /* In the mergedregs case, we convert full precision arrays
+ * to their effective half-precision base, and find conflicts
+ * amongst all other arrays/inputs.
+ *
+ * In the splitregs case (halfreg file and fullreg file do
+ * not conflict), we ignore arrays and other pre-colors that
+ * are not the same precision.
+ */
+ bool mergedregs = ctx->v->mergedregs;
+ unsigned base = 0;
+
+ /* figure out what else we conflict with which has already
+ * been assigned:
+ */
+retry:
+ foreach_array (arr2, &ctx->ir->array_list) {
+ if (arr2 == arr)
+ break;
+ ra_assert(ctx, arr2->start_ip <= arr2->end_ip);
+
+ unsigned base2 = arr2->reg;
+ unsigned len2 = arr2->length;
+ unsigned len = arr->length;
+
+ if (mergedregs) {
+ /* convert into half-reg space: */
+ if (!arr2->half) {
+ base2 *= 2;
+ len2 *= 2;
+ }
+ if (!arr->half) {
+ len *= 2;
+ }
+ } else if (arr2->half != arr->half) {
+ /* for split-register-file mode, we only conflict with
+ * other arrays of same precision:
+ */
+ continue;
+ }
+
+ /* if it intersects with liverange AND register range.. */
+ if (intersects(arr->start_ip, arr->end_ip,
+ arr2->start_ip, arr2->end_ip) &&
+ intersects(base, base + len,
+ base2, base2 + len2)) {
+ base = MAX2(base, base2 + len2);
+ goto retry;
+ }
+ }
+
+ /* also need to not conflict with any pre-assigned inputs: */
+ for (unsigned i = 0; i < nprecolor; i++) {
+ struct ir3_instruction *instr = precolor[i];
+
+ if (!instr || (instr->flags & IR3_INSTR_UNUSED))
+ continue;
+
+ struct ir3_ra_instr_data *id = &ctx->instrd[instr->ip];
+
+ /* only consider the first component: */
+ if (id->off > 0)
+ continue;
+
+ unsigned name = ra_name(ctx, id);
+ unsigned regid = instr->regs[0]->num;
+ unsigned reglen = class_sizes[id->cls];
+ unsigned len = arr->length;
+
+ if (mergedregs) {
+ /* convert into half-reg space: */
+ if (!is_half(instr)) {
+ regid *= 2;
+ reglen *= 2;
+ }
+ if (!arr->half) {
+ len *= 2;
+ }
+ } else if (is_half(instr) != arr->half) {
+ /* for split-register-file mode, we only conflict with
+ * other arrays of same precision:
+ */
+ continue;
+ }
+
+ /* Check if array intersects with liverange AND register
+ * range of the input:
+ */
+ if (intersects(arr->start_ip, arr->end_ip,
+ ctx->def[name], ctx->use[name]) &&
+ intersects(base, base + len,
+ regid, regid + reglen)) {
+ base = MAX2(base, regid + reglen);
+ goto retry;
+ }
+ }
+
+ /* convert back from half-reg space to fullreg space: */
+ if (mergedregs && !arr->half) {
+ base = DIV_ROUND_UP(base, 2);
+ }
+
+ arr->reg = base;
+}
+