digitalmars.D.bugs - [Issue 17854] New: Suboptimal code generated with constants and SSE
- d-bugmail puremagic.com (60/60) Sep 23 2017 https://issues.dlang.org/show_bug.cgi?id=17854
https://issues.dlang.org/show_bug.cgi?id=17854 Issue ID: 17854 Summary: Suboptimal code generated with constants and SSE Product: D Version: D2 Hardware: x86_64 OS: All Status: NEW Keywords: performance Severity: enhancement Priority: P1 Component: dmd Assignee: nobody puremagic.com Reporter: b2.temp gmx.com in both case with -O -release A. FP constant ============== int test(float i) { return cast(int)(2.0 * i * i); } disassembles to: 000000000045B640h push rbp 000000000045B641h mov rbp, rsp 000000000045B644h sub rsp, 10h 000000000045B648h movss xmm3, xmm0 000000000045B64Ch cvtss2sd xmm1, xmm0 000000000045B650h mov rax, 4000000000000000h 000000000045B65Ah mov qword ptr [rbp-10h], rax 000000000045B65Eh movsd xmm2, qword ptr [rbp-10h] 000000000045B663h mulsd xmm1, xmm2 000000000045B667h cvtss2sd xmm4, xmm0 000000000045B66Bh mulsd xmm1, xmm4 000000000045B66Fh cvttsd2si eax, xmm1 000000000045B673h mov rsp, rbp 000000000045B676h pop rbp 000000000045B677h ret B. Integer constant =================== int test(float i) { return cast(int)(2 * i * i); } disassembles to: 000000000045B640h push rbp 000000000045B641h mov rbp, rsp 000000000045B644h sub rsp, 10h 000000000045B648h movss xmm2, xmm0 000000000045B64Ch mov eax, 40000000h 000000000045B651h mov dword ptr [rbp-10h], eax 000000000045B654h movss xmm1, dword ptr [rbp-10h] 000000000045B659h mulss xmm0, xmm1 000000000045B65Dh mulss xmm0, xmm2 000000000045B661h cvttss2si eax, xmm0 000000000045B665h mov rsp, rbp 000000000045B668h pop rbp 000000000045B669h ret case A could clearly be compiled as B since the fractional part of the constant is empty. --
Sep 23 2017