https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81376
Bug ID: 81376 Summary: unnecessary cast before comparison Product: gcc Version: 8.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: middle-end Assignee: unassigned at gcc dot gnu.org Reporter: drepper.fsp+rhbz at gmail dot com Target Milestone: --- Take the following code: typedef double c_t; typedef int a_t; int f(a_t a1, a_t a2) { return (c_t) a1 < (c_t) a2; } With IEEE 754 double we have a 52 bits mantissa which is wide enough to represent all of the 'int' values exactly. No possibility for imprecision and especially not for Inf or NaN. Still gcc (trunk as of today but likely older versions as well) generate the code for the conversion. This is for x86-64 with -O2: f: vxorpd %xmm0, %xmm0, %xmm0 vxorpd %xmm1, %xmm1, %xmm1 xorl %eax, %eax vcvtsi2sd %edi, %xmm0, %xmm0 vcvtsi2sd %esi, %xmm1, %xmm1 vucomisd %xmm0, %xmm1 seta %al ret A simple xorl %eax, %eax cmpl %esi, %edi setl %al ret is sufficient, just as if c_t above would be defined as 'int'.