Open b1e213d1-25a4-466d-a8fa-acab6241b133 opened 3 years ago
The local variable 'value' is restrict-qualified, and hence should be assumed not to alias, right?
What if instead of a separate variable, the result should be stored in A[n]? Then one couldn't use restrict in the function signature, and a restrict-qualified local variable would have to be used. I just checked this and the same bug exists in that case.
Yes, a temporary value fixes the bug, but AFAIK the original code should be valid C99.
I believe this is not a bug as both value_ and A can be an alias to the same memory location. You need to either use 'restrict' or a temporary variable to make sure that doesn't happen.
Extended Description
The following program leads to incorrect codegen on x86-64 when compiled with '-fopenmp-simd -O1': only every 4th (SSE) or 8th (AVX) element is summed for large n. Changing the optimization level or enabling either FIX1 or FIX2 in the code avoids the problem. The problem occurs in both C and C++ mode and seemingly for any x86-64 uarch. Example of incorrect ASM: https://godbolt.org/z/17n8bP.