This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/82405] Function not inlined for switch and suboptimal assembly is generated
- From: "antoshkka at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 03 Oct 2017 15:48:22 +0000
- Subject: [Bug c++/82405] Function not inlined for switch and suboptimal assembly is generated
- Auto-submitted: auto-generated
- References: <bug-82405-4@http.gcc.gnu.org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82405
--- Comment #6 from Antony Polukhin <antoshkka at gmail dot com> ---
> And I don't think you can reassociate here validly unless -ffast-math.
But you can. In the isolated test case, instead of getting r*r at first, just
move the constant into the xmm1 first and after that multiply it twice with r.
Clang does that
.LCPI0_0:
.quad 4616189618054758400 # double 4
.quad 4614256447914709615 # double 3.1415000000000002
test_switch_native_slow(int, double): # @test_switch_native_slow(int,
double)
xor eax, eax
cmp edi, 123
sete al
movsd xmm1, qword ptr [8*rax + .LCPI0_0] # xmm1 = mem[0],zero
mulsd xmm1, xmm0
mulsd xmm0, xmm1
ret
Moreover, the current approach "multiply r twice and then multiply it on the
constant" changes the observable behavior, such optimization could be enabled
only with -ffast-math