[Mesa-dev] [PATCH 3/3] ac: handle cast derefs

Connor Abbott cwabbott0 at gmail.com
Wed Nov 21 11:37:50 UTC 2018


I don't see this working where there are any phi nodes involved. The
variable pointers spec says that you can use pointers with phi nodes.
Currently we just create a plain integer type, so this will fall over.
Are there any CTS tests that phi nodes which don't get removed by
nir_opt_peephole_sel?

Fundamentally, there's a mismatch between the NIR and LLVM/SPIR-V
model for derefs. In LLVM and SPIR-V, pointer-ness is part of the type
of a value, and so pointers can (in theory, in SPIR-V there are
restrictions based on what capabilities are present) be passed around
freely, but on the other hand you can't e.g. add a pointer and an
integer. Instead, you have to do a ptr-to-int cast or do an access
chain (or GEP in LLVM lingo). In NIR, values only have their bitsize
and number of components, so the ptr-to-int cast is implicit, but on
the other hand, every intrinsic using a deref has to be traced back to
a variable or cast deref instruction. So one way of correctly
implementing this would be to emit a LLVM int-to-ptr if necessary for
nir_deref_type_cast here, and emit a ptr-to-int cast in
ac_to_integer(). There's the risk that this doesn't optimize as well
due to LLVM not expecting it, but at least it works. If that becomes a
problem, we could do some kind of fancier analysis to figure out where
to put the casts, or move NIR more towards LLVM's model.
On Mon, Nov 19, 2018 at 9:16 PM Dave Airlie <airlied at gmail.com> wrote:
>
> From: Dave Airlie <airlied at redhat.com>
>
> Just give back the same value for now.
> ---
>  src/amd/common/ac_nir_to_llvm.c | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/src/amd/common/ac_nir_to_llvm.c b/src/amd/common/ac_nir_to_llvm.c
> index cc795324cc5..d7296a4617e 100644
> --- a/src/amd/common/ac_nir_to_llvm.c
> +++ b/src/amd/common/ac_nir_to_llvm.c
> @@ -3715,6 +3715,9 @@ static void visit_deref(struct ac_nir_context *ctx,
>                 result = ac_build_gep0(&ctx->ac, get_src(ctx, instr->parent),
>                                        get_src(ctx, instr->arr.index));
>                 break;
> +       case nir_deref_type_cast:
> +               result = get_src(ctx, instr->parent);
> +               break;
>         default:
>                 unreachable("Unhandled deref_instr deref type");
>         }
> --
> 2.17.2
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev


More information about the mesa-dev mailing list