ac: use an LLVM fence instead of s.waitcnt when possible
authorMarek Olšák <marek.olsak@amd.com>
Sat, 29 Jun 2019 05:03:29 +0000 (01:03 -0400)
committerMarek Olšák <marek.olsak@amd.com>
Thu, 4 Jul 2019 19:39:03 +0000 (15:39 -0400)
Reviewed-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
src/amd/common/ac_llvm_build.c

index 63891855e0786d07d86c8ef6f00086f16f0176a7..b208ba41eeae35a36bdee0378d2d5478b27d6b98 100644 (file)
@@ -2887,6 +2887,15 @@ void ac_build_waitcnt(struct ac_llvm_context *ctx, unsigned wait_flags)
                        vmcnt = 0;
        }
 
+       /* There is no intrinsic for vscnt(0), so use a fence. */
+       if ((wait_flags & AC_WAIT_LGKM &&
+            wait_flags & AC_WAIT_VLOAD &&
+            wait_flags & AC_WAIT_VSTORE) ||
+           vscnt == 0) {
+               LLVMBuildFence(ctx->builder, LLVMAtomicOrderingRelease, false, "");
+               return;
+       }
+
        unsigned simm16 = (lgkmcnt << 8) |
                          (7 << 4) | /* expcnt */
                          (vmcnt & 0xf) |
@@ -2897,15 +2906,6 @@ void ac_build_waitcnt(struct ac_llvm_context *ctx, unsigned wait_flags)
        };
        ac_build_intrinsic(ctx, "llvm.amdgcn.s.waitcnt",
                           ctx->voidt, args, 1, 0);
-
-       /* TODO: add llvm.amdgcn.s.waitcnt.vscnt into LLVM: */
-       if (0 && ctx->chip_class >= GFX10 && vscnt == 0) {
-               LLVMValueRef args[1] = {
-                       LLVMConstInt(ctx->i32, vscnt, false),
-               };
-               ac_build_intrinsic(ctx, "llvm.amdgcn.s.waitcnt.vscnt",
-                                  ctx->voidt, args, 1, 0);
-       }
 }
 
 LLVMValueRef ac_build_fmed3(struct ac_llvm_context *ctx, LLVMValueRef src0,