From b4019892c97dcfa365e1420ec2a8b06b89a142b3 Mon Sep 17 00:00:00 2001 From: Ioannis Assiouras Date: Wed, 18 Dec 2024 23:16:52 +0000 Subject: [PATCH] SWDEV-505504 - Disable vectorization in GetHipDispatchTable Change-Id: Id33144623555a5d25e029ca644f6274610dcd0ad [ROCm/clr commit: 158b6a29e0468d36a092ad8d204ce04b70dd4eda] --- projects/clr/hipamd/src/hip_api_trace.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/projects/clr/hipamd/src/hip_api_trace.cpp b/projects/clr/hipamd/src/hip_api_trace.cpp index eefe147e46..c9d8303a1b 100644 --- a/projects/clr/hipamd/src/hip_api_trace.cpp +++ b/projects/clr/hipamd/src/hip_api_trace.cpp @@ -1366,11 +1366,22 @@ template Tp& GetDispatchTableImpl() { } } // namespace -const HipDispatchTable* GetHipDispatchTable() { +// At the -O3 optimization level, these functions are vectorized (gcc 11.4.1), +// resulting in extra code to preload the dispatch table onto the stack using vector registers. +// This preloading occurs before verifying if the table has been initialized. +// Since the table is typically already initialized, this adds unnecessary overhead to the critical +// path. +#if defined(__GNUC__) || defined(__clang__) +#define NO_VECTORIZE __attribute__((optimize("no-tree-vectorize"))) +#else +#define NO_VECTORIZE +#endif +NO_VECTORIZE const HipDispatchTable* GetHipDispatchTable() { static auto* _v = &GetDispatchTableImpl(); return _v; } -const HipCompilerDispatchTable* GetHipCompilerDispatchTable() { +NO_VECTORIZE const HipCompilerDispatchTable* +GetHipCompilerDispatchTable() { static auto* _v = &GetDispatchTableImpl(); return _v; }