int test_double() {
  int i;
  float sums[3] = {0.0};
#pragma acc parallel loop
  for (i = 0; i < 4096; i++) {
    double v;
    v = (double)(-i);
#pragma acc atomic
    sums[0] += v;
#pragma acc atomic
    sums[1] = sums[1] + v;
#pragma acc atomic
    sums[2] = v + sums[2];
  }
  for (i = 0; i < 3; i++) {
    if (sums[i] != (-4096 * (4096 - 1) / 2)) {
      return i + 1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<test_double>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    -0x14(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1030 <memset@plt>
movl   $0x0,-0x8(%rbp)
cmpl   $0x1000,-0x8(%rbp)
jge    11a5 <test_double+0x95>
xor    %eax,%eax
sub    -0x8(%rbp),%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm1
movss  -0x14(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x14(%rbp)
movss  -0x10(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
addsd  -0x20(%rbp),%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x10(%rbp)
movsd  -0x20(%rbp),%xmm0
movss  -0xc(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0xc(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    112f <test_double+0x1f>
movl   $0x0,-0x8(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    11fd <test_double+0xed>
movslq -0x8(%rbp),%rax
movss  -0x14(%rbp,%rax,4),%xmm0
movss  0xe38(%rip),%xmm1
ucomiss %xmm1,%xmm0
jne    11dc <test_double+0xcc>
jp     11dc <test_double+0xcc>
jmp    11ea <test_double+0xda>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1204 <test_double+0xf4>
jmp    11ef <test_double+0xdf>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11ac <test_double+0x9c>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_double>:
xorpd  %xmm0,%xmm0
xorps  %xmm1,%xmm1
mov    $0xffffffff,%eax
nopl   0x0(%rax)
lea    0x1(%rax),%ecx
xorps  %xmm2,%xmm2
cvtsi2sd %ecx,%xmm2
cvtss2sd %xmm1,%xmm1
addsd  %xmm2,%xmm1
cvtsd2ss %xmm1,%xmm1
cvtps2pd %xmm0,%xmm0
unpcklpd %xmm2,%xmm2
addpd  %xmm0,%xmm2
cvtpd2ps %xmm2,%xmm0
xorps  %xmm2,%xmm2
cvtsi2sd %eax,%xmm2
cvtss2sd %xmm1,%xmm1
addsd  %xmm2,%xmm1
cvtsd2ss %xmm1,%xmm1
cvtps2pd %xmm0,%xmm0
unpcklpd %xmm2,%xmm2
addpd  %xmm0,%xmm2
cvtpd2ps %xmm2,%xmm0
add    $0xfffffffe,%eax
cmp    $0xffffefff,%eax
jne    1110 <test_double+0x10>
mov    $0x1,%eax
ucomiss 0xe93(%rip),%xmm1
jne    1171 <test_double+0x71>
jnp    1172 <test_double+0x72>
ret
mov    $0x2,%eax
ucomiss 0xe82(%rip),%xmm0
jne    1171 <test_double+0x71>
jp     1171 <test_double+0x71>
shufps $0x55,%xmm0,%xmm0
mov    $0x3,%eax
ucomiss 0xe6e(%rip),%xmm0
jne    1171 <test_double+0x71>
jp     1171 <test_double+0x71>
xor    %eax,%eax
ret

LLVM IR (-O0):
define i32 @test_double() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [3 x float]
%4 = alloca double
%5 = bitcast [3 x float]* %3 to i8*
store i32 0, i32* %2
br label %6
6: ; preds = %33, %0
%7 = load i32, i32* %2
%8 = icmp slt i32 %7, 4096
br i1 %8, label %9, label %36
9: ; preds = %6
%10 = load i32, i32* %2
%11 = sub nsw i32 0, %10
%12 = sitofp i32 %11 to double
store double %12, double* %4
%13 = load double, double* %4
%14 = getelementptr inbounds [3 x float], [3 x float]* %3, i64 0, i64 0
%15 = load float, float* %14
%16 = fpext float %15 to double
%17 = fadd double %16, %13
%18 = fptrunc double %17 to float
store float %18, float* %14
%19 = getelementptr inbounds [3 x float], [3 x float]* %3, i64 0, i64 1
%20 = load float, float* %19
%21 = fpext float %20 to double
%22 = load double, double* %4
%23 = fadd double %21, %22
%24 = fptrunc double %23 to float
%25 = getelementptr inbounds [3 x float], [3 x float]* %3, i64 0, i64 1
store float %24, float* %25
%26 = load double, double* %4
%27 = getelementptr inbounds [3 x float], [3 x float]* %3, i64 0, i64 2
%28 = load float, float* %27
%29 = fpext float %28 to double
%30 = fadd double %26, %29
%31 = fptrunc double %30 to float
%32 = getelementptr inbounds [3 x float], [3 x float]* %3, i64 0, i64 2
store float %31, float* %32
br label %33
33: ; preds = %9
%34 = load i32, i32* %2
%35 = add nsw i32 %34, 1
store i32 %35, i32* %2
br label %6
36: ; preds = %6
store i32 0, i32* %2
br label %37
37: ; preds = %50, %36
%38 = load i32, i32* %2
%39 = icmp slt i32 %38, 3
br i1 %39, label %40, label %53
40: ; preds = %37
%41 = load i32, i32* %2
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds [3 x float], [3 x float]* %3, i64 0, i64 %42
%44 = load float, float* %43
%45 = fcmp une float %44, -8.386560e+06
br i1 %45, label %46, label %49
46: ; preds = %40
%47 = load i32, i32* %2
%48 = add nsw i32 %47, 1
store i32 %48, i32* %1
br label %54
49: ; preds = %40
br label %50
50: ; preds = %49
%51 = load i32, i32* %2
%52 = add nsw i32 %51, 1
store i32 %52, i32* %2
br label %37
53: ; preds = %37
store i32 0, i32* %1
br label %54
54: ; preds = %53, %46
%55 = load i32, i32* %1
ret i32 %55
}

LLVM IR (-O2):
define i32 @test_double() {
br label %3
1: ; preds = %3
%2 = fcmp une float %21, -8.386560e+06
br i1 %2, label %36, label %29
3: ; preds = %3, %0
%4 = phi i32 [ 0, %0 ], [ %27, %3 ]
%5 = phi float [ 0.000000e+00, %0 ], [ %21, %3 ]
%6 = phi <2 x float> [ zeroinitializer, %0 ], [ %26, %3 ]
%7 = sub nsw i32 0, %4
%8 = sitofp i32 %7 to double
%9 = fpext float %5 to double
%10 = fadd double %8, %9
%11 = fptrunc double %10 to float
%12 = fpext <2 x float> %6 to <2 x double>
%13 = insertelement <2 x double> poison, double %8, i64 0
%14 = shufflevector <2 x double> %13, <2 x double> poison, <2 x i32> zeroinitializer
%15 = fadd <2 x double> %14, %12
%16 = fptrunc <2 x double> %15 to <2 x float>
%17 = xor i32 %4, -1
%18 = sitofp i32 %17 to double
%19 = fpext float %11 to double
%20 = fadd double %18, %19
%21 = fptrunc double %20 to float
%22 = fpext <2 x float> %16 to <2 x double>
%23 = insertelement <2 x double> poison, double %18, i64 0
%24 = shufflevector <2 x double> %23, <2 x double> poison, <2 x i32> zeroinitializer
%25 = fadd <2 x double> %24, %22
%26 = fptrunc <2 x double> %25 to <2 x float>
%27 = add nuw nsw i32 %4, 2
%28 = icmp eq i32 %27, 4096
br i1 %28, label %1, label %3
29: ; preds = %1
%30 = extractelement <2 x float> %26, i64 0
%31 = fcmp une float %30, -8.386560e+06
br i1 %31, label %36, label %32
32: ; preds = %29
%33 = extractelement <2 x float> %26, i64 1
%34 = fcmp une float %33, -8.386560e+06
br i1 %34, label %36, label %35
35: ; preds = %32
br label %36
36: ; preds = %1, %29, %32, %35
%37 = phi i32 [ 0, %35 ], [ 1, %1 ], [ 2, %29 ], [ 3, %32 ]
ret i32 %37
}