ac/llvm: run the LLVM sinking pass because LLVM will stop running it
authorMarek Olšák <marek.olsak@amd.com>
Tue, 13 Dec 2022 16:03:21 +0000 (11:03 -0500)
committerMarek Olšák <marek.olsak@amd.com>
Fri, 27 Jan 2023 00:33:17 +0000 (19:33 -0500)
shader-db was run with the sinking pass disabled in LLVM.

58380 shaders in 35438 tests
Totals:
SGPRS: 2730768 -> 2730768 (0.00 %)
VGPRS: 1592932 -> 1592928 (-0.00 %)
Spilled SGPRs: 2687 -> 2687 (0.00 %)
Spilled VGPRs: 551 -> 551 (0.00 %)
Private memory VGPRs: 253 -> 253 (0.00 %)
Scratch size: 700 -> 700 (0.00 %) dwords per thread
Code Size: 61238872 -> 61238868 (-0.00 %) bytes
Max Waves: 849209 -> 849209 (0.00 %)
Outputs: 127090 -> 127090 (0.00 %)
Patch Outputs: 579 -> 579 (0.00 %)

Totals from affected shaders:
SGPRS: 440 -> 440 (0.00 %)
VGPRS: 396 -> 392 (-1.01 %)
Spilled SGPRs: 0 -> 0 (0.00 %)
Spilled VGPRs: 0 -> 0 (0.00 %)
Private memory VGPRs: 0 -> 0 (0.00 %)
Scratch size: 0 -> 0 (0.00 %) dwords per thread
Code Size: 49880 -> 49876 (-0.01 %) bytes
Max Waves: 105 -> 105 (0.00 %)
Outputs: 14 -> 14 (0.00 %)
Patch Outputs: 0 -> 0 (0.00 %)

Reviewed-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/20297>

src/amd/llvm/ac_llvm_build.h
src/amd/llvm/ac_llvm_helper.cpp
src/amd/llvm/ac_llvm_util.c

index 76f5502..9b8c595 100644 (file)
@@ -580,6 +580,8 @@ LLVMValueRef ac_build_atomic_rmw(struct ac_llvm_context *ctx, LLVMAtomicRMWBinOp
 LLVMValueRef ac_build_atomic_cmp_xchg(struct ac_llvm_context *ctx, LLVMValueRef ptr,
                                       LLVMValueRef cmp, LLVMValueRef val, const char *sync_scope);
 
+void ac_add_sinking_pass(LLVMPassManagerRef PM);
+
 void ac_export_mrt_z(struct ac_llvm_context *ctx, LLVMValueRef depth, LLVMValueRef stencil,
                      LLVMValueRef samplemask, LLVMValueRef mrt0_alpha, bool is_last,
                      struct ac_export_args *args);
index 71ed11a..66fdef8 100644 (file)
@@ -31,6 +31,7 @@
 #include <llvm/MC/MCSubtargetInfo.h>
 #include <llvm/Support/CommandLine.h>
 #include <llvm/Transforms/IPO.h>
+#include <llvm/Transforms/Scalar.h>
 
 #include <cstring>
 
@@ -45,6 +46,8 @@
 #include "ac_llvm_build.h"
 #include "util/macros.h"
 
+using namespace llvm;
+
 bool ac_is_llvm_processor_supported(LLVMTargetMachineRef tm, const char *processor)
 {
    llvm::TargetMachine *TM = reinterpret_cast<llvm::TargetMachine *>(tm);
@@ -326,3 +329,8 @@ LLVMValueRef ac_build_atomic_cmp_xchg(struct ac_llvm_context *ctx, LLVMValueRef
                                               llvm::AtomicOrdering::SequentiallyConsistent,
                                               llvm::AtomicOrdering::SequentiallyConsistent, SSID));
 }
+
+void ac_add_sinking_pass(LLVMPassManagerRef PM)
+{
+  unwrap(PM)->add(createLoopSinkPass());
+}
index ff936af..832e908 100644 (file)
@@ -239,6 +239,8 @@ static LLVMPassManagerRef ac_create_passmgr(LLVMTargetLibraryInfoRef target_libr
    /* This pass should eliminate all the load and store instructions. */
    LLVMAddPromoteMemoryToRegisterPass(passmgr);
    LLVMAddScalarReplAggregatesPass(passmgr);
+   if (LLVM_VERSION_MAJOR >= 16)
+      ac_add_sinking_pass(passmgr);
    LLVMAddLICMPass(passmgr);
    LLVMAddAggressiveDCEPass(passmgr);
    LLVMAddCFGSimplificationPass(passmgr);