xref: /llvm-project/compiler-rt/test/nsan/vec_sqrt_ext.cpp (revision 52ae891036e3ab1f668eb103c46ca57257901c6b)
151365212SAlexander Shaposhnikov // RUN: %clangxx_nsan -O0 -g -mavx %s -o %t
2*52ae8910SHarini0924 // RUN: env NSAN_OPTIONS=check_nan=true,halt_on_error=0 %run %t 2>&1 | FileCheck %s
351365212SAlexander Shaposhnikov // RUN: %clangxx_nsan -O3 -g -mavx %s -o %t
4*52ae8910SHarini0924 // RUN: env NSAN_OPTIONS=check_nan=true,halt_on_error=0 %run %t 2>&1 | FileCheck %s
551365212SAlexander Shaposhnikov #include <iostream>
651365212SAlexander Shaposhnikov #include <cmath>
751365212SAlexander Shaposhnikov 
851365212SAlexander Shaposhnikov typedef float v8sf __attribute__ ((vector_size(32)));
951365212SAlexander Shaposhnikov 
1051365212SAlexander Shaposhnikov v8sf simd_sqrt(v8sf a) {
1151365212SAlexander Shaposhnikov   return __builtin_elementwise_sqrt(a);
1251365212SAlexander Shaposhnikov   // CHECK: WARNING: NumericalStabilitySanitizer: NaN detected
1351365212SAlexander Shaposhnikov }
1451365212SAlexander Shaposhnikov 
1551365212SAlexander Shaposhnikov int main() {
1651365212SAlexander Shaposhnikov   v8sf a = {-1.0, -2.0, -3.0, 4.0, 5.0, 6.0, 7.0, 8.0};
1751365212SAlexander Shaposhnikov   a = simd_sqrt(a);
1851365212SAlexander Shaposhnikov 
1951365212SAlexander Shaposhnikov   // This prevents DCE.
2051365212SAlexander Shaposhnikov   for (size_t i = 0; i < 8; ++i) {
2151365212SAlexander Shaposhnikov     std::cout << a[i] << std::endl;
2251365212SAlexander Shaposhnikov     // CHECK: WARNING: NumericalStabilitySanitizer: NaN detected
2351365212SAlexander Shaposhnikov   }
2451365212SAlexander Shaposhnikov   return 0;
2551365212SAlexander Shaposhnikov }
26