[Bug tree-optimization/57492] Optimize 2.0**i to ldexp(1.0,i)

2024-09-11 Thread ktkachov at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57492

ktkachov at gcc dot gnu.org changed:

   What|Removed |Added

   Last reconfirmed|2013-05-31 00:00:00 |2024-9-11
 CC||ktkachov at gcc dot gnu.org

--- Comment #6 from ktkachov at gcc dot gnu.org ---
This looks like a useful transformation to me. On aarch64 SVE we have the
FSCALE instruction that can be used to implement ldexp efficiently so the more
math calls fold to it the better.

[Bug tree-optimization/57492] Optimize 2.0**i to ldexp(1.0,i)

2018-08-27 Thread joseph at codesourcery dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57492

--- Comment #5 from joseph at codesourcery dot com  ---
The example from comment#2 should require -funsafe-math-optimizations 
(it's not correct if the pow call overflowed / underflowed but the ldexp 
call doesn't).

[Bug tree-optimization/57492] Optimize 2.0**i to ldexp(1.0,i)

2018-08-27 Thread rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57492

Richard Biener  changed:

   What|Removed |Added

   Keywords||easyhack

--- Comment #4 from Richard Biener  ---
Should be relatively easy to fix with new match.pd rules.

[Bug tree-optimization/57492] Optimize 2.0**i to ldexp(1.0,i)

2018-08-27 Thread antoshkka at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57492

--- Comment #3 from Antony Polukhin  ---
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
cvtsi2sdxmm0, 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.

[Bug tree-optimization/57492] Optimize 2.0**i to ldexp(1.0,i)

2013-06-01 Thread tkoenig at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57492

--- Comment #2 from Thomas Koenig  ---
Another thing to optimize would be to change

a*builtin_pow(2.0,i) to ldexp(a, i).

Lots of fun things to do ;-)


[Bug tree-optimization/57492] Optimize 2.0**i to ldexp(1.0,i)

2013-05-31 Thread glisse at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57492

Marc Glisse  changed:

   What|Removed |Added

   Keywords||missed-optimization
 Status|UNCONFIRMED |NEW
   Last reconfirmed||2013-05-31
 Ever confirmed|0   |1

--- Comment #1 from Marc Glisse  ---
Confirmed. If you feel motivated, you can also handle 4.0**i, and then maybe
look at ldexp optimizations (with -ffast-math?) like 2*ldexp(1,i) or
ldexp(1,i+1) -> ldexp(2,i).