[Openmp-commits] [llvm] [openmp] [compiler-rt] [TSan] Add instrumentation of AVX2 and AVX512 instructions (PR #74636)

via Openmp-commits openmp-commits at lists.llvm.org
Thu Dec 14 02:37:57 PST 2023


================
@@ -0,0 +1,57 @@
+// REQUIRES: mavx512f
+// RUN: %clang_tsan -march=native -DSIMDLEN=4 -DTYPE=float %s -o %t && %run %t 2>&1 | FileCheck %s
+// RUN: %clang_tsan -march=native -DSIMDLEN=4 -DTYPE=double %s -o %t && %run %t 2>&1 | FileCheck %s
+// RUN: %clang_tsan -march=native -DSIMDLEN=8 -DTYPE=float %s -o %t && %run %t 2>&1 | FileCheck %s
+// RUN: %clang_tsan -march=native -DSIMDLEN=8 -DTYPE=double %s -o %t && %run %t 2>&1 | FileCheck %s
+#include "test.h"
+#include <immintrin.h>
+#include <stdint.h>
+
+#ifndef SIMDLEN
+#  define SIMDLEN 8
+#endif /*SIMDLEN*/
+#ifndef TYPE
+#  define TYPE double
+#endif /*TYPE*/
+
+#if SIMDLEN == 4
+#  define tsan_scatter_func __tsan_scatter_vector4
+#  define intri_type __m256i
+#elif SIMDLEN == 8
+#  define tsan_scatter_func __tsan_scatter_vector8
+#  define intri_type __m512i
+#endif
+
+extern void tsan_scatter_func(intri_type, int, uint8_t);
+TYPE A[8];
+
+__attribute__((disable_sanitizer_instrumentation)) void *Thread(uint8_t mask) {
+#if SIMDLEN == 4
+  __m256i vaddr = _mm256_set_epi64x(
+#elif SIMDLEN == 8
+  __m512i vaddr = _mm512_set_epi64(
+      (int64_t)(A + 7), (int64_t)(A + 6), (int64_t)(A + 5), (int64_t)(A + 4),
+#endif
+      (int64_t)(A + 3), (int64_t)(A + 2), (int64_t)(A + 1), (int64_t)(A + 0));
+  tsan_scatter_func(vaddr, sizeof(TYPE), mask);
----------------
jprotze wrote:

At the moment, we only added llvm vector intrinsics to the ThreadSanitizer pass. These intrinsics are generated by the vectorizer (e.g., triggered by OpenMP simd, or clang simd directives). According to our understanding, we cannot explicitly place these intrinsics into C source code.

Furthermore, we failed to convince the vectorizer to actually emit masked llvm vector intrinsics (i.e., having not all mask bits True), as the cost heuristic would typically prefer generating scalar code instead.

@felilxtomski will add instrumentation to the TSan pass for the related x86 vector intrinsics. Then we might trigger this instrumentation from C code.

https://github.com/llvm/llvm-project/pull/74636


More information about the Openmp-commits mailing list