https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64225
Bug ID: 64225
Summary: -funsafe-math-optimizations generates call to pow
where multiply instruction would do
Product: gcc
Version: 4.9.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: middle-end
Assignee: unassigned at gcc dot gnu.org
Reporter: bernie.ogden at linaro dot org
Created attachment 34217
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=34217&action=edit
Reproducer
Running e.g.
./gcc-linaro-aarch64-linux-gnu-4.9-2014.09_linux/bin/aarch64-linux-gnu-gcc -S
-o - r.i -O1 -funsafe-math-optimizations generates code like this:
stp x29, x30, [sp, -32]!
add x29, sp, 0
str d8, [sp, 16]
fmov d8, d0
fmov d1, 2.0e+0
bl pow
fmul d8, d8, d8
ldr d0, .LC0
fmul d0, d8, d0
ldr d8, [sp, 16]
ldp x29, x30, [sp], 32
ret
Removing -funsafe-math-optimizations, or replacing it with -ffast-math,
replaces the call to pow with the intuitively more sensible fmul and saves the
stacking, e.g.:
ldr d1, .LC0
fmul d1, d0, d1
fmul d0, d1, d0
ret
A little experimentation shows similar behaviour for AArch32, AArch64 and x86.
By binary chopping through Linaro releases I find the behaviour begins with the
first 4.8 release (gcc version 4.8.1 20130401 (prerelease)).
Attached r.i and the output generated by:
./gcc-linaro-aarch64-linux-gnu-4.9-2014.09_linux/bin/aarch64-linux-gnu-gcc -v
--save-temps -S -o - r.c -O1 -funsafe-math-optimizations > output 2>&1
Guessed middle-end for Component, and entered latest version in which I've seen
the bug for Version.