https://bugs.llvm.org/show_bug.cgi?id=48625

            Bug ID: 48625
           Summary: Incorrect codegen for #pragma omp simd loop at -O1
           Product: clang
           Version: trunk
          Hardware: Macintosh
                OS: MacOS X
            Status: NEW
          Severity: normal
          Priority: P
         Component: LLVM Codegen
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected], [email protected],
                    [email protected]

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.

```C
#ifdef __cplusplus
#define restrict __restrict
#endif

#define FIX1 0
#define FIX2 0

void sum(int n, const float* A,
#if FIX1
    float* restrict value)
#else
    float* value_)
#endif
{
#if !FIX1 && !FIX2
    float* restrict value = (float* restrict)value_;
#endif

#if FIX2
    float tmp = *value_;
    float* value = &tmp;
#endif

    #pragma omp simd
    for (int i = 0;i < n;i++) *value += A[i];

#if FIX2
    *value_ = tmp;
#endif
}
```

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to