nir: add deref follower builder for casts.
authorFaith Ekstrand <faith.ekstrand@collabora.com>
Wed, 1 Nov 2023 20:38:35 +0000 (15:38 -0500)
committerEric Engestrom <eric@engestrom.ch>
Sat, 4 Nov 2023 14:12:29 +0000 (14:12 +0000)
This fixes intel_clc builds with llvm 17 on gfx125_bvh_build_DFS_DFS
where it dies in the lower indirect derefs pass.

Co-authored-by: Dave Airlie <airlied@redhat.com>
Fixes: 4a4e1757381c ("nir: Support deref instructions in lower_var_copies")
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/25536>
(cherry picked from commit 6388896985da7495ad0968322491953894d29637)

.pick_status.json
src/compiler/nir/nir_builder.h

index 1ce6d96..e798933 100644 (file)
         "description": "nir: add deref follower builder for casts.",
         "nominated": true,
         "nomination_type": 1,
-        "resolution": 0,
+        "resolution": 1,
         "main_sha": null,
         "because_sha": "4a4e1757381c65653fd6a81cf4e969ddff926ed5",
         "notes": null
index c9f3465..d2b5702 100644 (file)
@@ -1483,9 +1483,12 @@ nir_build_deref_struct(nir_builder *build, nir_deref_instr *parent,
 }
 
 static inline nir_deref_instr *
-nir_build_deref_cast(nir_builder *build, nir_def *parent,
-                     nir_variable_mode modes, const struct glsl_type *type,
-                     unsigned ptr_stride)
+nir_build_deref_cast_with_alignment(nir_builder *build, nir_def *parent,
+                                    nir_variable_mode modes,
+                                    const struct glsl_type *type,
+                                    unsigned ptr_stride,
+                                    unsigned align_mul,
+                                    unsigned align_offset)
 {
    nir_deref_instr *deref =
       nir_deref_instr_create(build->shader, nir_deref_type_cast);
@@ -1493,6 +1496,8 @@ nir_build_deref_cast(nir_builder *build, nir_def *parent,
    deref->modes = modes;
    deref->type = type;
    deref->parent = nir_src_for_ssa(parent);
+   deref->cast.align_mul = align_mul;
+   deref->cast.align_offset = align_offset;
    deref->cast.ptr_stride = ptr_stride;
 
    nir_def_init(&deref->instr, &deref->def, parent->num_components,
@@ -1504,6 +1509,15 @@ nir_build_deref_cast(nir_builder *build, nir_def *parent,
 }
 
 static inline nir_deref_instr *
+nir_build_deref_cast(nir_builder *build, nir_def *parent,
+                     nir_variable_mode modes, const struct glsl_type *type,
+                     unsigned ptr_stride)
+{
+   return nir_build_deref_cast_with_alignment(build, parent, modes, type,
+                                              ptr_stride, 0, 0);
+}
+
+static inline nir_deref_instr *
 nir_alignment_deref_cast(nir_builder *build, nir_deref_instr *parent,
                          uint32_t align_mul, uint32_t align_offset)
 {
@@ -1570,6 +1584,13 @@ nir_build_deref_follower(nir_builder *b, nir_deref_instr *parent,
 
       return nir_build_deref_struct(b, parent, leader->strct.index);
 
+   case nir_deref_type_cast:
+      return nir_build_deref_cast_with_alignment(b, &parent->def,
+                                                 leader->modes,
+                                                 leader->type,
+                                                 leader->cast.ptr_stride,
+                                                 leader->cast.align_mul,
+                                                 leader->cast.align_offset);
    default:
       unreachable("Invalid deref instruction type");
    }