int test_double() {
  int i;
  float reds[3] = {0.0};
#pragma acc parallel loop
  for (i = 0; i < 4096; i++) {
    double v;
    v = (double)(-i);
#pragma acc atomic
    reds[0] -= v;
#pragma acc atomic
    reds[1] = reds[1] - v;
  }
  for (i = 0; i < 2; i++) {
    if (reds[i] != (4096 * (4096 - 1) / 2)) {
      return i;
    }
  }
  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    118a <test_double+0x7a>
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
subsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x14(%rbp)
movss  -0x10(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
subsd  -0x20(%rbp),%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x10(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    112f <test_double+0x1f>
movl   $0x0,-0x8(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11df <test_double+0xcf>
movslq -0x8(%rbp),%rax
movss  -0x14(%rbp,%rax,4),%xmm0
movss  0xe53(%rip),%xmm1
ucomiss %xmm1,%xmm0
jne    11c1 <test_double+0xb1>
jp     11c1 <test_double+0xb1>
jmp    11cc <test_double+0xbc>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11e6 <test_double+0xd6>
jmp    11d1 <test_double+0xc1>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1191 <test_double+0x81>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_double>:
xorpd  %xmm0,%xmm0
mov    $0xffffffff,%eax
nopl   0x0(%rax)
lea    0x1(%rax),%ecx
xorps  %xmm1,%xmm1
cvtsi2sd %ecx,%xmm1
cvtps2pd %xmm0,%xmm0
unpcklpd %xmm1,%xmm1
subpd  %xmm1,%xmm0
cvtpd2ps %xmm0,%xmm0
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
cvtps2pd %xmm0,%xmm0
unpcklpd %xmm1,%xmm1
subpd  %xmm1,%xmm0
cvtpd2ps %xmm0,%xmm0
add    $0xfffffffe,%eax
cmp    $0xffffefff,%eax
jne    1110 <test_double+0x10>
xor    %eax,%eax
ucomiss 0xeae(%rip),%xmm0
jne    1156 <test_double+0x56>
jnp    1157 <test_double+0x57>
ret
shufps $0x55,%xmm0,%xmm0
mov    $0x1,%eax
ucomiss 0xe99(%rip),%xmm0
jne    1156 <test_double+0x56>
jp     1156 <test_double+0x56>
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 = %26, %0
%7 = load i32, i32* %2
%8 = icmp slt i32 %7, 4096
br i1 %8, label %9, label %29
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 = fsub 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 = fsub 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
br label %26
26: ; preds = %9
%27 = load i32, i32* %2
%28 = add nsw i32 %27, 1
store i32 %28, i32* %2
br label %6
29: ; preds = %6
store i32 0, i32* %2
br label %30
30: ; preds = %42, %29
%31 = load i32, i32* %2
%32 = icmp slt i32 %31, 2
br i1 %32, label %33, label %45
33: ; preds = %30
%34 = load i32, i32* %2
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds [3 x float], [3 x float]* %3, i64 0, i64 %35
%37 = load float, float* %36
%38 = fcmp une float %37, 8.386560e+06
br i1 %38, label %39, label %41
39: ; preds = %33
%40 = load i32, i32* %2
store i32 %40, i32* %1
br label %46
41: ; preds = %33
br label %42
42: ; preds = %41
%43 = load i32, i32* %2
%44 = add nsw i32 %43, 1
store i32 %44, i32* %2
br label %30
45: ; preds = %30
store i32 0, i32* %1
br label %46
46: ; preds = %45, %39
%47 = load i32, i32* %1
ret i32 %47
}

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