void __attribute__((noipa))
test_double___builtin_fabs(double *__restrict r, double *__restrict a,
                           double *__restrict pred, int n) {
  for (int i = 0; i < n; ++i)
    r[i] = pred[i] ? __builtin_fabs(a[i]) : 0;
}


x86 assembly (clang, -O0):
<test_double___builtin_fabs>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    119a <test_double___builtin_fabs+0x9a>
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    114b <test_double___builtin_fabs+0x4b>
jp     114b <test_double___builtin_fabs+0x4b>
jmp    116d <test_double___builtin_fabs+0x6d>
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movaps 0xea1(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    117a <test_double___builtin_fabs+0x7a>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    117a <test_double___builtin_fabs+0x7a>
movsd  -0x28(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    111a <test_double___builtin_fabs+0x1a>
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_double___builtin_fabs>:
test   %ecx,%ecx
jle    1137 <test_double___builtin_fabs+0x37>
mov    %ecx,%r8d
cmp    $0x1,%ecx
jne    1138 <test_double___builtin_fabs+0x38>
xor    %eax,%eax
test   $0x1,%r8b
je     1137 <test_double___builtin_fabs+0x37>
movsd  (%rdx,%rax,8),%xmm1
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm1
jne    1125 <test_double___builtin_fabs+0x25>
jnp    1132 <test_double___builtin_fabs+0x32>
movsd  (%rsi,%rax,8),%xmm0
andpd  0xece(%rip),%xmm0
movsd  %xmm0,(%rdi,%rax,8)
ret
mov    %r8d,%ecx
and    $0xfffffffe,%ecx
xor    %eax,%eax
movapd 0xeb8(%rip),%xmm0
jmp    115f <test_double___builtin_fabs+0x5f>
nopw   0x0(%rax,%rax,1)
movsd  %xmm1,0x8(%rdi,%rax,8)
add    $0x2,%rax
cmp    %rax,%rcx
je     110e <test_double___builtin_fabs+0xe>
movsd  (%rdx,%rax,8),%xmm2
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm2
xorpd  %xmm2,%xmm2
jne    1174 <test_double___builtin_fabs+0x74>
jnp    117d <test_double___builtin_fabs+0x7d>
movsd  (%rsi,%rax,8),%xmm2
andpd  %xmm0,%xmm2
movsd  %xmm2,(%rdi,%rax,8)
movsd  0x8(%rdx,%rax,8),%xmm2
ucomisd %xmm1,%xmm2
jne    1190 <test_double___builtin_fabs+0x90>
jnp    1150 <test_double___builtin_fabs+0x50>
movsd  0x8(%rsi,%rax,8),%xmm1
andpd  %xmm0,%xmm1
jmp    1150 <test_double___builtin_fabs+0x50>

LLVM IR (-O0):
define void @test_double___builtin_fabs(double* noalias %0, double* noalias %1, double* noalias %2, i32 %3) {
%5 = alloca double*
%6 = alloca double*
%7 = alloca double*
%8 = alloca i32
%9 = alloca i32
store double* %0, double** %5
store double* %1, double** %6
store double* %2, double** %7
store i32 %3, i32* %8
store i32 0, i32* %9
br label %10
10: ; preds = %35, %4
%11 = load i32, i32* %9
%12 = load i32, i32* %8
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %38
14: ; preds = %10
%15 = load double*, double** %7
%16 = load i32, i32* %9
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds double, double* %15, i64 %17
%19 = load double, double* %18
%20 = fcmp une double %19, 0.000000e+00
br i1 %20, label %21, label %28
21: ; preds = %14
%22 = load double*, double** %6
%23 = load i32, i32* %9
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds double, double* %22, i64 %24
%26 = load double, double* %25
%27 = call double @llvm.fabs.f64(double %26)
br label %29
28: ; preds = %14
br label %29
29: ; preds = %28, %21
%30 = phi double [ %27, %21 ], [ 0.000000e+00, %28 ]
%31 = load double*, double** %5
%32 = load i32, i32* %9
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds double, double* %31, i64 %33
store double %30, double* %34
br label %35
35: ; preds = %29
%36 = load i32, i32* %9
%37 = add nsw i32 %36, 1
store i32 %37, i32* %9
br label %10
38: ; preds = %10
ret void
}

LLVM IR (-O2):
define void @test_double___builtin_fabs(double* noalias nocapture writeonly %0, double* noalias nocapture %1, double* noalias nocapture %2, i32 %3) {
%5 = icmp sgt i32 %3, 0
br i1 %5, label %6, label %26
6: ; preds = %4
%7 = zext i32 %3 to i64
%8 = and i64 %7, 1
%9 = icmp eq i32 %3, 1
br i1 %9, label %12, label %10
10: ; preds = %6
%11 = and i64 %7, 4294967294
br label %27
12: ; preds = %48, %6
%13 = phi i64 [ 0, %6 ], [ %51, %48 ]
%14 = icmp eq i64 %8, 0
br i1 %14, label %26, label %15
15: ; preds = %12
%16 = getelementptr inbounds double, double* %2, i64 %13
%17 = load double, double* %16
%18 = fcmp une double %17, 0.000000e+00
br i1 %18, label %19, label %23
19: ; preds = %15
%20 = getelementptr inbounds double, double* %1, i64 %13
%21 = load double, double* %20
%22 = tail call double @llvm.fabs.f64(double %21)
br label %23
23: ; preds = %19, %15
%24 = phi double [ %22, %19 ], [ 0.000000e+00, %15 ]
%25 = getelementptr inbounds double, double* %0, i64 %13
store double %24, double* %25
br label %26
26: ; preds = %23, %12, %4
ret void
27: ; preds = %48, %10
%28 = phi i64 [ 0, %10 ], [ %51, %48 ]
%29 = phi i64 [ 0, %10 ], [ %52, %48 ]
%30 = getelementptr inbounds double, double* %2, i64 %28
%31 = load double, double* %30
%32 = fcmp une double %31, 0.000000e+00
br i1 %32, label %33, label %37
33: ; preds = %27
%34 = getelementptr inbounds double, double* %1, i64 %28
%35 = load double, double* %34
%36 = tail call double @llvm.fabs.f64(double %35)
br label %37
37: ; preds = %27, %33
%38 = phi double [ %36, %33 ], [ 0.000000e+00, %27 ]
%39 = getelementptr inbounds double, double* %0, i64 %28
store double %38, double* %39
%40 = or i64 %28, 1
%41 = getelementptr inbounds double, double* %2, i64 %40
%42 = load double, double* %41
%43 = fcmp une double %42, 0.000000e+00
br i1 %43, label %44, label %48
44: ; preds = %37
%45 = getelementptr inbounds double, double* %1, i64 %40
%46 = load double, double* %45
%47 = tail call double @llvm.fabs.f64(double %46)
br label %48
48: ; preds = %44, %37
%49 = phi double [ %47, %44 ], [ 0.000000e+00, %37 ]
%50 = getelementptr inbounds double, double* %0, i64 %40
store double %49, double* %50
%51 = add nuw nsw i64 %28, 2
%52 = add i64 %29, 2
%53 = icmp eq i64 %52, %11
br i1 %53, label %12, label %27
}