https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57492

--- Comment #3 from Antony Polukhin <antoshkka at gmail dot com> ---
More examples:

double test_uns(unsigned u) {
    return __builtin_pow(2, u);
}

double test_int(int i) {
    return __builtin_pow(2, i);
}


Above two functions clang optimizes to exp2 and ldexp calls:

test_uns(unsigned int):                           # @test_uns(unsigned int)
        mov     eax, edi
        cvtsi2sd        xmm0, rax
        jmp     exp2                    # TAILCALL
.LCPI1_0:
        .quad   4607182418800017408     # double 1
test_int(int):                           # @test_int(int)
        movsd   xmm0, qword ptr [rip + .LCPI1_0] # xmm0 = mem[0],zero
        jmp     ldexp                   # TAILCALL


GCC still uses pow for both cases:

test_uns(unsigned int):
  mov edi, edi
  pxor xmm1, xmm1
  movsd xmm0, QWORD PTR .LC0[rip]
  cvtsi2sdq xmm1, rdi
  jmp pow
test_int(int):
  pxor xmm1, xmm1
  movsd xmm0, QWORD PTR .LC0[rip]
  cvtsi2sd xmm1, edi
  jmp pow
.LC0:
  .long 0
  .long 1073741824 


Tested on GCC trunk 9.0.

Reply via email to