ac/llvm: fix atomic var operations if source isn't a deref
authorSamuel Pitoiset <samuel.pitoiset@gmail.com>
Mon, 2 Dec 2019 13:58:00 +0000 (14:58 +0100)
committerSamuel Pitoiset <samuel.pitoiset@gmail.com>
Tue, 3 Dec 2019 08:41:33 +0000 (09:41 +0100)
Fixes some CTS regressions.

Fixes: e61a826f396 ("ac/llvm: fix pointer type for global atomics")
Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Reviewed-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
src/amd/llvm/ac_nir_to_llvm.c

index 830866bc5cb898995ed4429f731e3ff7fde15fb3..4c8216dbe73d7601196775ddab11b4446d0b4ce5 100644 (file)
@@ -3022,13 +3022,15 @@ static LLVMValueRef visit_var_atomic(struct ac_nir_context *ctx,
 
        const char *sync_scope = LLVM_VERSION_MAJOR >= 9 ? "workgroup-one-as" : "workgroup";
 
-       nir_deref_instr *deref = nir_instr_as_deref(instr->src[0].ssa->parent_instr);
-       if (deref->mode == nir_var_mem_global) {
-               /* use "singlethread" sync scope to implement relaxed ordering */
-               sync_scope = LLVM_VERSION_MAJOR >= 9 ? "singlethread-one-as" : "singlethread";
-
-               LLVMTypeRef ptr_type = LLVMPointerType(LLVMTypeOf(src), LLVMGetPointerAddressSpace(LLVMTypeOf(ptr)));
-               ptr = LLVMBuildBitCast(ctx->ac.builder, ptr, ptr_type , "");
+       if (instr->src[0].ssa->parent_instr->type == nir_instr_type_deref) {
+               nir_deref_instr *deref = nir_instr_as_deref(instr->src[0].ssa->parent_instr);
+               if (deref->mode == nir_var_mem_global) {
+                       /* use "singlethread" sync scope to implement relaxed ordering */
+                       sync_scope = LLVM_VERSION_MAJOR >= 9 ? "singlethread-one-as" : "singlethread";
+
+                       LLVMTypeRef ptr_type = LLVMPointerType(LLVMTypeOf(src), LLVMGetPointerAddressSpace(LLVMTypeOf(ptr)));
+                       ptr = LLVMBuildBitCast(ctx->ac.builder, ptr, ptr_type , "");
+               }
        }
 
        if (instr->intrinsic == nir_intrinsic_shared_atomic_comp_swap ||