[llvm] [mlir] [mlir][tosa] Use optnone for compliance initialization under HWAsan (PR #226310)

Walter Lee via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 24 16:51:49 PDT 2026


https://github.com/googlewalt updated https://github.com/llvm/llvm-project/pull/226310

>From beda95a991825ac97da279c71317168f11699551 Mon Sep 17 00:00:00 2001
From: Walter Lee <waltl at google.com>
Date: Thu, 24 Sep 2026 18:05:11 -0400
Subject: [PATCH 1/2] [mlir][tosa] Use optnone for compliance initialization
 under HWAsan (NFC)

Similar to #223586, compiling the file is very slow when we enable
HWAsan internally.  Mark the constructor with optnone under
LLVM_HWADDRESS_SANITIZER_BUILD to skip expensive optimization and
register allocation passes, bringing compilation time from 10+m to
~30s.
---
 llvm/include/llvm/Support/Compiler.h                  |  2 +-
 .../Dialect/Tosa/Transforms/TosaProfileCompliance.cpp | 11 ++++++-----
 2 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/llvm/include/llvm/Support/Compiler.h b/llvm/include/llvm/Support/Compiler.h
index 33ea019a87be57..0bdf422dadad25 100644
--- a/llvm/include/llvm/Support/Compiler.h
+++ b/llvm/include/llvm/Support/Compiler.h
@@ -611,7 +611,7 @@ void __asan_unpoison_memory_region(void const volatile *addr, size_t size);
 
 /// \macro LLVM_HWADDRESS_SANITIZER_BUILD
 /// Whether LLVM itself is built with HWAddressSanitizer instrumentation.
-#if __has_feature(hwaddress_sanitizer)
+#if __has_feature(hwaddress_sanitizer) || defined(__SANITIZE__HWADDRESS__)
 #define LLVM_HWADDRESS_SANITIZER_BUILD 1
 #else
 #define LLVM_HWADDRESS_SANITIZER_BUILD 0
diff --git a/mlir/lib/Dialect/Tosa/Transforms/TosaProfileCompliance.cpp b/mlir/lib/Dialect/Tosa/Transforms/TosaProfileCompliance.cpp
index 3c81be49cbd9a4..abd1aed65d9104 100644
--- a/mlir/lib/Dialect/Tosa/Transforms/TosaProfileCompliance.cpp
+++ b/mlir/lib/Dialect/Tosa/Transforms/TosaProfileCompliance.cpp
@@ -14,11 +14,12 @@
 using namespace mlir;
 using namespace mlir::tosa;
 
-// Building this ~5,000-line generated initializer map under MemorySanitizer
-// leads to extreme compile times (>3.5 minutes) during InstCombine and greedy
-// register allocation due to shadow/origin instrumentation overhead. Disable
-// optimization under MSan to keep build times manageable.
-#if LLVM_MEMORY_SANITIZER_BUILD
+// Building this ~5,000-line generated initializer map under HWAddressSanitizer
+// or MemorySanitizer leads to extreme compile times (>3.5 minutes) during
+// InstCombine and greedy register allocation due to instrumentation
+// overhead. Disable optimization under MSan/HWAsan to keep build times
+// manageable.
+#if LLVM_MEMORY_SANITIZER_BUILD || LLVM_HWADDRESS_SANITIZER_BUILD
 __attribute__((optnone))
 #else
 LLVM_ATTRIBUTE_MINSIZE

>From 43a3e4d0ba0a28b61ebccac5e0a9b8daa0ebb7cd Mon Sep 17 00:00:00 2001
From: Walter Lee <waltl at google.com>
Date: Thu, 24 Sep 2026 19:51:20 -0400
Subject: [PATCH 2/2] Revert sanitizer change

---
 llvm/include/llvm/Support/Compiler.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/include/llvm/Support/Compiler.h b/llvm/include/llvm/Support/Compiler.h
index 0bdf422dadad25..33ea019a87be57 100644
--- a/llvm/include/llvm/Support/Compiler.h
+++ b/llvm/include/llvm/Support/Compiler.h
@@ -611,7 +611,7 @@ void __asan_unpoison_memory_region(void const volatile *addr, size_t size);
 
 /// \macro LLVM_HWADDRESS_SANITIZER_BUILD
 /// Whether LLVM itself is built with HWAddressSanitizer instrumentation.
-#if __has_feature(hwaddress_sanitizer) || defined(__SANITIZE__HWADDRESS__)
+#if __has_feature(hwaddress_sanitizer)
 #define LLVM_HWADDRESS_SANITIZER_BUILD 1
 #else
 #define LLVM_HWADDRESS_SANITIZER_BUILD 0



More information about the llvm-commits mailing list