https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84251
Bug ID: 84251 Summary: Performance regression in gcc 8 when comparing floating point numbers Product: gcc Version: 8.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: middle-end Assignee: unassigned at gcc dot gnu.org Reporter: mikulas at artax dot karlin.mff.cuni.cz Target Milestone: --- See this simple function and compile it with -O2 on x86-64: #include <stdlib.h> #include <math.h> int cmp(double a, double b) { if (isnan(a) || isnan(b)) abort(); return a == b; } On gcc-7, we get optimal code: 0000000000000000 <cmp>: 0: 66 0f 2e c1 ucomisd %xmm1,%xmm0 4: 7a 07 jp d <cmp+0xd> 6: 0f 94 c0 sete %al 9: 0f b6 c0 movzbl %al,%eax c: c3 retq d: 48 83 ec 08 sub $0x8,%rsp 11: e8 00 00 00 00 callq 16 <cmp+0x16> On gcc-8, we get inoptimal code. See the nonsensical "setnp" instruction in a block of code where it is known that the "P" flag must be clear. 0000000000000000 <cmp>: 0: 48 83 ec 08 sub $0x8,%rsp 4: 66 0f 2e c1 ucomisd %xmm1,%xmm0 8: 0f 8a 00 00 00 00 jp e <cmp+0xe> e: 0f 9b c0 setnp %al 11: ba 00 00 00 00 mov $0x0,%edx 16: 0f b6 c0 movzbl %al,%eax 19: 0f 45 c2 cmovne %edx,%eax 1c: 48 83 c4 08 add $0x8,%rsp 20: c3 retq Disassembly of section .text.unlikely: 0000000000000000 <cmp.cold.0>: 0: e8 00 00 00 00 callq 5 <cmp.cold.0+0x5>