https://bugs.kde.org/show_bug.cgi?id=485148

--- Comment #3 from Petr <[email protected]> ---
Yeah, I'm not sorry for providing a C++ code.

Here is a very simple repro:

```
    #include <x86intrin.h>
    #include <stdio.h>

    static __attribute__((noinline)) void test_fma_ss(float dst[4], const float
a[4], const float b[4], const float c[4]) {
      __m128 av = _mm_loadu_ps(a);
      __m128 bv = _mm_loadu_ps(b);
      __m128 cv = _mm_loadu_ps(c);

      __m128 dv = _mm_fmadd_ss(av, bv, cv);
      _mm_storeu_ps(dst, dv);
    }

    int main() {
      float a[4] = { 1, 2, 3, 4 };
      float b[4] = { 3, 11, 35, 1 };
      float c[4] = { -1, -2, -19, 0 };

      float dst[4];
      test_fma_ss(dst, a, b, c);

      printf("[%f %f %f %f]\n", dst[0], dst[1], dst[2], dst[3]);
      return 0;
    }
```

Which can be compiled as

    gcc valgrind_bug.cpp -O2 -mfma -mavx2 -o valgrind_bug

When executed without valgrind:
    ./valgrind_bug

It prints:

    [2.000000 2.000000 3.000000 4.000000]

When executed with valgrind:
    valgrind ./valgrind_bug

In prints:

==109113== Memcheck, a memory error detector
==109113== Copyright (C) 2002-2022, and GNU GPL'd, by Julian Seward et al.
==109113== Using Valgrind-3.23.0.GIT and LibVEX; rerun with -h for copyright
info
==109113== Command: ./valgrind_bug
==109113== 
[2.000000 0.000000 0.000000 0.000000]
==109113== 
==109113== HEAP SUMMARY:
==109113==     in use at exit: 0 bytes in 0 blocks
==109113==   total heap usage: 1 allocs, 1 frees, 1,024 bytes allocated
==109113== 
==109113== All heap blocks were freed -- no leaks are possible
==109113== 
==109113== For lists of detected and suppressed errors, rerun with: -s
==109113== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

The result is different - only the first value is correct, the remaining 3
values were zeroed.

-- 
You are receiving this mail because:
You are watching all bug changes.

Reply via email to